Merge pull request #37 from fmgjcoppens:add/lapack

add/lapack
This commit is contained in:
François Coppens 2021-05-21 12:00:55 +02:00 committed by GitHub
commit 5c9b9f359c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 79 additions and 11 deletions

View File

@ -21,7 +21,12 @@ else
$(error No valid compiler environment set in $$ENV. \ $(error No valid compiler environment set in $$ENV. \
First run: $$ source smvars.sh {intel | llvm | gnu}) First run: $$ source smvars.sh {intel | llvm | gnu})
endif endif
CXXFLAGS = $(OPT) $(ARCH) $(DEBUG) -fPIC $(THRESHOLD) CXXFLAGS = $(OPT) $(ARCH) $(DEBUG) $(THRESHOLD) -fPIC
ifeq ($(MKL),-DMKL)
CXXFLAGS += $(MKL)
LFLAGS = -mkl=sequential
H5LFLAGS = -L${MKLROOT}/lib/intel64 -Wl,--no-as-needed -lmkl_intel_lp64 -lmkl_sequential -lmkl_core -lpthread -lm -ldl
endif
FFLAGS = $(CXXFLAGS) FFLAGS = $(CXXFLAGS)
H5CXX = h5c++ H5CXX = h5c++
H5CXXFLAGS = $(CXXFLAGS) H5CXXFLAGS = $(CXXFLAGS)
@ -93,16 +98,16 @@ $(OBJ_DIR)/%.o: $(TST_DIR)/%.f90 | $(OBJ_DIR)
#### LINKING #### LINKING
$(BIN_DIR)/cMaponiA3_test_3x3_3: $(OBJ_DIR)/cMaponiA3_test_3x3_3.o $(DEPS_CXX) | $(BIN_DIR) $(BIN_DIR)/cMaponiA3_test_3x3_3: $(OBJ_DIR)/cMaponiA3_test_3x3_3.o $(DEPS_CXX) | $(BIN_DIR)
$(CXX) -o $@ $^ $(CXX) $(LFLAGS) -o $@ $^
$(BIN_DIR)/test_h5: $(OBJ_DIR)/test_h5.o $(DEPS_CXX) | $(BIN_DIR) $(BIN_DIR)/test_h5: $(OBJ_DIR)/test_h5.o $(DEPS_CXX) | $(BIN_DIR)
$(H5CXX) -o $@ $^ $(H5CXX) $(H5LFLAGS) -o $@ $^
$(BIN_DIR)/fMaponiA3_test_3x3_3: $(DEPS_F) $(OBJ_DIR)/fMaponiA3_test_3x3_3.o | $(BIN_DIR) $(BIN_DIR)/fMaponiA3_test_3x3_3: $(DEPS_F) $(OBJ_DIR)/fMaponiA3_test_3x3_3.o | $(BIN_DIR)
$(FC) $(FLIBS) -o $@ $^ $(FC) $(LFLAGS) $(FLIBS) -o $@ $^
$(BIN_DIR)/fMaponiA3_test_4x4_2: $(DEPS_F) $(OBJ_DIR)/fMaponiA3_test_4x4_2.o | $(BIN_DIR) $(BIN_DIR)/fMaponiA3_test_4x4_2: $(DEPS_F) $(OBJ_DIR)/fMaponiA3_test_4x4_2.o | $(BIN_DIR)
$(FC) $(FLIBS) -o $@ $^ $(FC) $(LFLAGS) $(FLIBS) -o $@ $^
$(BIN_DIR)/QMCChem_dataset_test: $(DEPS_F) $(OBJ_DIR)/QMCChem_dataset_test.o | $(BIN_DIR) $(BIN_DIR)/QMCChem_dataset_test: $(DEPS_F) $(OBJ_DIR)/QMCChem_dataset_test.o | $(BIN_DIR)
$(FC) $(FLIBS) -o $@ $^ $(FC) $(LFLAGS) $(FLIBS) -o $@ $^

View File

@ -4,7 +4,9 @@
#include <cstring> #include <cstring>
#include <iostream> #include <iostream>
#include <string> #include <string>
#ifdef MKL
#include <mkl_lapacke.h>
#endif
// #define DEBUG // #define DEBUG
#ifndef THRESHOLD #ifndef THRESHOLD
@ -18,6 +20,10 @@ void selectLargestDenominator(unsigned int l, unsigned int N_updates,
unsigned int *Updates_index, unsigned int *p, unsigned int *Updates_index, unsigned int *p,
double ***ylk); double ***ylk);
#ifdef MKL
lapack_int inverse(double *A, unsigned n);
#endif
template <typename T> void showScalar(T scalar, std::string name) { template <typename T> void showScalar(T scalar, std::string name) {
std::cout << name << " = " << scalar << std::endl << std::endl; std::cout << name << " = " << scalar << std::endl << std::endl;
} }

View File

@ -1,7 +1,7 @@
#!/usr/bin/env bash #!/usr/bin/env bash
unset THRESHOLD unset THRESHOLD
unset MKL
ENV=$1 ENV=$1
THRESHOLD=$2
## Set Sherman-Morrison root dir ## Set Sherman-Morrison root dir
PWD=$(pwd) PWD=$(pwd)
@ -22,22 +22,26 @@ export SMROOT
## Set environment for hdf5-tools and Makefile ## Set environment for hdf5-tools and Makefile
case $ENV in case $ENV in
intel) intel)
echo "* SM build environment set to 'intel'"
export HDF5_CXX=icpc export HDF5_CXX=icpc
export HDF5_CXXLINKER=icpc export HDF5_CXXLINKER=icpc
export ENV=INTEL export ENV=INTEL
;; ;;
llvm) llvm)
echo "* SM build environment set to 'llvm'"
export HDF5_CXX=clang++ export HDF5_CXX=clang++
export HDF5_CXXLINKER=clang++ export HDF5_CXXLINKER=clang++
export ENV=LLVM export ENV=LLVM
;; ;;
vfc) vfc)
echo "* SM build environment set to 'vfc'"
export HDF5_CXX=clang++ export HDF5_CXX=clang++
export HDF5_CXXLINKER=clang++ export HDF5_CXXLINKER=clang++
export ENV=LLVM export ENV=LLVM
export VFC_BACKENDS="libinterflop_ieee.so --count-op" export VFC_BACKENDS="libinterflop_ieee.so --count-op"
;; ;;
gnu) gnu)
echo "* SM build environment set to 'gnu'"
export HDF5_CXX=g++ export HDF5_CXX=g++
export HDF5_CXXLINKER=g++ export HDF5_CXXLINKER=g++
export ENV=GNU export ENV=GNU
@ -45,7 +49,10 @@ case $ENV in
*) *)
echo "Unknown environment descriptor given." echo "Unknown environment descriptor given."
echo "Usage: source smvars.sh {intel | llvm | vfc | gnu}" echo "Usage: source smvars.sh {intel | llvm | vfc | gnu}"
echo "Usage: source smvars.sh {intel | llvm | vfc | gnu} [mkl]"
echo "Usage: source smvars.sh {intel | llvm | vfc | gnu} [threshold]" echo "Usage: source smvars.sh {intel | llvm | vfc | gnu} [threshold]"
echo "Usage: source smvars.sh {intel | llvm | vfc | gnu} [mkl] [threshold]"
echo "Usage: source smvars.sh {intel | llvm | vfc | gnu} [threshold] [mkl]"
return 1 return 1
;; ;;
esac esac
@ -57,8 +64,33 @@ then
export SMVARS=true export SMVARS=true
fi fi
## If a threshold is provided, export compiler flag ## Argument parsing
if [[ $# -gt 1 ]] if [[ $# -eq 1 ]]
then then
export THRESHOLD="-DTHRESHOLD=$THRESHOLD" echo "* Default threshold of '1e-3' will be used in next build."
fi
if [[ $# -eq 2 ]]
then
if [[ $2 == mkl ]]
then
echo "* oneMKL-dependent parts of the code are enable in next build."
echo "* Default threshold of '1e-3' will be used in next build."
export MKL="-DMKL"
else
echo "* Threshold of '$2' will be used in next build."
export THRESHOLD="-DTHRESHOLD=$2"
fi
fi
if [[ $# -eq 3 ]]
then
echo "* oneMKL-dependent parts of the code are enable in next build."
export MKL="-DMKL"
if [[ $2 == mkl ]]
then
echo "* Threshold of '$3' will be used in next build."
export THRESHOLD="-DTHRESHOLD=$3"
else
echo "* Threshold of '$2' will be used in next build."
export THRESHOLD="-DTHRESHOLD=$2"
fi
fi fi

View File

@ -39,3 +39,23 @@ void selectLargestDenominator(unsigned int l, unsigned int N_updates,
} }
Switch(p, l, lbar); Switch(p, l, lbar);
} }
#ifdef MKL
// Inplace inverse n x n matrix A.
// returns:
// ret = 0 on success
// ret < 0 illegal argument value
// ret > 0 singular matrix
lapack_int inverse(double *A, unsigned n) {
int ipiv[n + 1];
lapack_int ret;
ret = LAPACKE_dgetrf(LAPACK_COL_MAJOR, n, n, A, n, ipiv);
if (ret != 0)
return ret;
ret = LAPACKE_dgetri(LAPACK_COL_MAJOR, n, A, n, ipiv);
return ret;
}
#endif

View File

@ -81,6 +81,11 @@ int test_cycle(H5File file, int cycle, std::string version, double tolerance) {
SM3(slater_inverse, dim, nupdates, u, col_update_index); SM3(slater_inverse, dim, nupdates, u, col_update_index);
} else if (version == "sm4") { } else if (version == "sm4") {
SM4(slater_inverse, dim, nupdates, u, col_update_index); SM4(slater_inverse, dim, nupdates, u, col_update_index);
#ifdef MKL
} else if (version == "lapack") {
memcpy(slater_inverse, slater_matrix, dim * dim * sizeof(double));
inverse(slater_inverse, dim);
#endif
} else { } else {
std::cerr << "Unknown version " << version << std::endl; std::cerr << "Unknown version " << version << std::endl;
exit(1); exit(1);