Added LAPACK option to test_h5.cpp to compare residuals and number of operations.

This commit is contained in:
François Coppens 2021-05-20 19:21:59 +02:00
parent ab661ad785
commit 6c9c68c93d
4 changed files with 32 additions and 6 deletions

View File

@ -21,11 +21,13 @@ 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
FFLAGS = $(CXXFLAGS) FFLAGS = $(CXXFLAGS)
H5CXX = h5c++ H5CXX = h5c++
H5CXXFLAGS = $(CXXFLAGS) H5CXXFLAGS = $(CXXFLAGS)
FLIBS = -lstdc++ FLIBS = -lstdc++
LFLAGS = -mkl=sequential
H5LFLAGS = -L${MKLROOT}/lib/intel64 -Wl,--no-as-needed -lmkl_intel_lp64 -lmkl_sequential -lmkl_core -lpthread -lm -ldl
## Includes and dependencies ## Includes and dependencies
INCLUDE = -I $(INC_DIR)/ INCLUDE = -I $(INC_DIR)/
@ -93,16 +95,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,6 +4,7 @@
#include <cstring> #include <cstring>
#include <iostream> #include <iostream>
#include <string> #include <string>
#include <mkl_lapacke.h>
// #define DEBUG // #define DEBUG
@ -18,6 +19,8 @@ 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);
lapack_int inverse(double *A, unsigned n);
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

@ -39,3 +39,21 @@ void selectLargestDenominator(unsigned int l, unsigned int N_updates,
} }
Switch(p, l, lbar); Switch(p, l, lbar);
} }
// 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;
}

View File

@ -81,6 +81,9 @@ 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);
} else if (version == "lapack") {
memcpy(slater_inverse, slater_matrix, dim * dim * sizeof(double));
inverse(slater_inverse, dim);
} else { } else {
std::cerr << "Unknown version " << version << std::endl; std::cerr << "Unknown version " << version << std::endl;
exit(1); exit(1);