mirror of
https://github.com/TREX-CoE/Sherman-Morrison.git
synced 2024-11-03 20:54:08 +01:00
- Added a new test program tests/qmckl_test_h5.cpp that uses SM1 (qmckl_sherman_morrison_c) from the QMCkl library.
- Added build entry in Makefile for tests/qmckl_test_h5.cpp. #25
This commit is contained in:
parent
0849e23100
commit
8961f78ea2
12
Makefile
12
Makefile
@ -29,7 +29,7 @@ CXXFLAGS = $(OPT) $(ARCH) $(DEBUG) $(THRESHOLD) -fPIC
|
||||
## MKL linker flags
|
||||
ifeq ($(MKL),-DMKL)
|
||||
CXXFLAGS += $(MKL)
|
||||
H5LFLAGS = -L${MKLROOT}/lib/intel64 -Wl,--no-as-needed -lmkl_intel_lp64 -lmkl_sequential -lmkl_core -lpthread -lm -ldl
|
||||
H5LFLAGS = -L$(MKLROOT)/lib/intel64 -Wl,--no-as-needed -lmkl_intel_lp64 -lmkl_sequential -lmkl_core -lpthread -lm -ldl
|
||||
ifeq ($(ENV),INTEL)
|
||||
LFLAGS = -mkl=sequential # implicit
|
||||
else
|
||||
@ -50,6 +50,11 @@ DEPS_F = $(DEPS_CXX) \
|
||||
$(OBJ_DIR)/finterface_mod.o \
|
||||
$(OBJ_DIR)/helpers_mod.o
|
||||
|
||||
## QMCkl includes and linking
|
||||
QMCKL_INCLUDE = -I $(SMROOT)/qmckl/build/include/
|
||||
QMCKLLFLAGS = -L$(SMROOT)/qmckl/build/lib -lqmckl
|
||||
|
||||
|
||||
## Directory structure
|
||||
SRC_DIR := src
|
||||
TST_DIR := tests
|
||||
@ -91,7 +96,7 @@ $(OBJ_DIR)/%.o: $(SRC_DIR)/%.cpp $(INC_DIR)/* | $(OBJ_DIR)
|
||||
|
||||
## HDF5/C++ objects
|
||||
$(OBJ_DIR)/%_h5.o: $(TST_DIR)/%_h5.cpp $(INC_DIR)/* | $(OBJ_DIR)
|
||||
$(H5CXX) $(H5CXXFLAGS) $(INCLUDE) -c -o $@ $<
|
||||
$(H5CXX) $(H5CXXFLAGS) $(INCLUDE) $(QMCKL_INCLUDE) -c -o $@ $<
|
||||
|
||||
## Fortran modules
|
||||
$(OBJ_DIR)/%_mod.o: $(SRC_DIR)/%_mod.f90 | $(OBJ_DIR)
|
||||
@ -116,6 +121,9 @@ $(BIN_DIR)/test_h5: $(OBJ_DIR)/test_h5.o $(DEPS_CXX) | $(BIN_DIR)
|
||||
$(BIN_DIR)/fnu_test_h5: $(OBJ_DIR)/fnu_test_h5.o $(DEPS_CXX) | $(BIN_DIR)
|
||||
$(H5CXX) $(H5LFLAGS) -o $@ $^
|
||||
|
||||
$(BIN_DIR)/qmckl_test_h5: $(OBJ_DIR)/qmckl_test_h5.o | $(BIN_DIR)
|
||||
$(H5CXX) $(H5LFLAGS) $(QMCKLLFLAGS) -o $@ $^
|
||||
|
||||
$(BIN_DIR)/fMaponiA3_test_3x3_3: $(DEPS_F) $(OBJ_DIR)/fMaponiA3_test_3x3_3.o | $(BIN_DIR)
|
||||
$(FC) $(LFLAGS) $(FLIBS) -o $@ $^
|
||||
|
||||
|
2
qmckl
2
qmckl
@ -1 +1 @@
|
||||
Subproject commit 4e31dc4ac4f96cb43352860122778c31c65a903f
|
||||
Subproject commit 7b2a8caeabadb7724b9d7c8b0498e7ea71b7b992
|
@ -2,6 +2,10 @@
|
||||
#include "hdf5/serial/hdf5.h"
|
||||
|
||||
#include "qmckl.h"
|
||||
#include "cstring"
|
||||
#include "iostream"
|
||||
|
||||
#include "Helpers.hpp"
|
||||
|
||||
#define PERF
|
||||
|
||||
@ -15,7 +19,7 @@ using namespace H5;
|
||||
|
||||
const H5std_string FILE_NAME("dataset.hdf5");
|
||||
|
||||
void read_int(H5File file, std::string key, unsigned int *data) {
|
||||
void read_int(H5File file, std::string key, uint64_t *data) {
|
||||
DataSet ds = file.openDataSet(key);
|
||||
ds.read(data, PredType::STD_U32LE);
|
||||
ds.close();
|
||||
@ -33,7 +37,9 @@ int test_cycle(H5File file, int cycle, std::string version, double tolerance) {
|
||||
|
||||
std::string group = "cycle_" + std::to_string(cycle);
|
||||
|
||||
unsigned int dim, nupdates, col, i, j;
|
||||
unsigned int col, i, j;
|
||||
uint64_t dim, nupdates;
|
||||
|
||||
read_int(file, group + "/slater_matrix_dim", &dim);
|
||||
read_int(file, group + "/nupdates", &nupdates);
|
||||
|
||||
@ -43,7 +49,7 @@ int test_cycle(H5File file, int cycle, std::string version, double tolerance) {
|
||||
double *slater_inverse = new double[dim * dim];
|
||||
read_double(file, group + "/slater_inverse", slater_inverse);
|
||||
|
||||
unsigned int *col_update_index = new unsigned int[nupdates];
|
||||
uint64_t *col_update_index = new uint64_t[nupdates];
|
||||
read_int(file, group + "/col_update_index", col_update_index);
|
||||
|
||||
double *updates = new double[nupdates * dim];
|
||||
@ -52,9 +58,6 @@ int test_cycle(H5File file, int cycle, std::string version, double tolerance) {
|
||||
double *u = new double[nupdates * dim];
|
||||
|
||||
/* Test */
|
||||
#ifdef DEBUG2
|
||||
showMatrix(slater_inverse, dim, "OLD Inverse");
|
||||
#endif
|
||||
|
||||
// Transform replacement updates in 'updates[]' into additive updates in 'u[]'
|
||||
for (j = 0; j < nupdates; j++) {
|
||||
@ -65,96 +68,48 @@ int test_cycle(H5File file, int cycle, std::string version, double tolerance) {
|
||||
slater_matrix[i * dim + (col - 1)] = updates[i + j * dim];
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef DEBUG2
|
||||
showMatrix(slater_matrix, dim, "OLD Slater");
|
||||
#endif
|
||||
|
||||
#ifdef DEBUG2
|
||||
showMatrix(u, dim, "Updates");
|
||||
#endif
|
||||
delete[] updates;
|
||||
|
||||
#ifdef PERF
|
||||
std::cout << "# of reps. = " << repetition_number << std::endl;
|
||||
double *slater_inverse_nonpersistent = new double[dim * dim];
|
||||
if (version == "sm1") {
|
||||
for (unsigned int i = 0; i < repetition_number; i++) {
|
||||
std::memcpy(slater_inverse_nonpersistent, slater_inverse,
|
||||
memcpy(slater_inverse_nonpersistent, slater_inverse,
|
||||
dim * dim * sizeof(double));
|
||||
if (version == "maponia3") {
|
||||
MaponiA3(slater_inverse_nonpersistent, dim, nupdates, u,
|
||||
col_update_index);
|
||||
} else if (version == "maponia3s") {
|
||||
MaponiA3S(slater_inverse_nonpersistent, dim, nupdates, u,
|
||||
col_update_index);
|
||||
} else if (version == "sm1") {
|
||||
SM1(slater_inverse_nonpersistent, dim, nupdates, u, col_update_index);
|
||||
} else if (version == "sm2") {
|
||||
SM2(slater_inverse_nonpersistent, dim, nupdates, u, col_update_index);
|
||||
} else if (version == "sm3") {
|
||||
SM3(slater_inverse_nonpersistent, dim, nupdates, u, col_update_index);
|
||||
} else if (version == "sm4") {
|
||||
SM4(slater_inverse_nonpersistent, dim, nupdates, u, col_update_index);
|
||||
} else if (version == "wb2") {
|
||||
WB2(slater_inverse_nonpersistent, dim, u, col_update_index);
|
||||
} else if (version == "wb3") {
|
||||
WB3(slater_inverse_nonpersistent, dim, u, col_update_index);
|
||||
} else if (version == "smwb1") {
|
||||
SMWB1(slater_inverse_nonpersistent, dim, nupdates, u, col_update_index);
|
||||
} else if (version == "smwb2") {
|
||||
SMWB2(slater_inverse_nonpersistent, dim, nupdates, u, col_update_index);
|
||||
#ifdef MKL
|
||||
} else if (version == "lapack") {
|
||||
memcpy(slater_inverse_nonpersistent, slater_matrix,
|
||||
dim * dim * sizeof(double));
|
||||
inverse(slater_inverse_nonpersistent, dim);
|
||||
#endif // MKL
|
||||
} else {
|
||||
qmckl_exit_code sherman_morrison_exit;
|
||||
qmckl_context context;
|
||||
sherman_morrison_exit = qmckl_sherman_morrison_c(context,
|
||||
dim,
|
||||
nupdates,
|
||||
u,
|
||||
col_update_index,
|
||||
slater_inverse_nonpersistent);
|
||||
}
|
||||
}
|
||||
else {
|
||||
std::cerr << "Unknown version " << version << std::endl;
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
std::memcpy(slater_inverse, slater_inverse_nonpersistent,
|
||||
dim * dim * sizeof(double));
|
||||
delete[] slater_inverse_nonpersistent;
|
||||
#else
|
||||
if (version == "maponia3") {
|
||||
MaponiA3(slater_inverse, dim, nupdates, u, col_update_index);
|
||||
} else if (version == "maponia3s") {
|
||||
MaponiA3S(slater_inverse, dim, nupdates, u, col_update_index);
|
||||
} else if (version == "sm1") {
|
||||
SM1(slater_inverse, dim, nupdates, u, col_update_index);
|
||||
} else if (version == "sm2") {
|
||||
SM2(slater_inverse, dim, nupdates, u, col_update_index);
|
||||
} else if (version == "sm3") {
|
||||
SM3(slater_inverse, dim, nupdates, u, col_update_index);
|
||||
} else if (version == "sm4") {
|
||||
SM4(slater_inverse, dim, nupdates, u, col_update_index);
|
||||
} else if (version == "wb2") {
|
||||
WB2(slater_inverse, dim, u, col_update_index);
|
||||
} else if (version == "wb3") {
|
||||
WB3(slater_inverse, dim, u, col_update_index);
|
||||
} else if (version == "smwb1") {
|
||||
SMWB1(slater_inverse, dim, nupdates, u, col_update_index);
|
||||
} else if (version == "smwb4") {
|
||||
SMWB4(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 // MKL
|
||||
} else {
|
||||
#else // No performance measurements repetition
|
||||
if (version == "sm1") {
|
||||
qmckl_exit_code sherman_morrison_exit;
|
||||
qmckl_context context;
|
||||
sherman_morrison_exit = qmckl_sherman_morrison_c(context,
|
||||
dim,
|
||||
nupdates,
|
||||
u,
|
||||
col_update_index,
|
||||
slater_inverse);
|
||||
}
|
||||
else {
|
||||
std::cerr << "Unknown version " << version << std::endl;
|
||||
exit(1);
|
||||
}
|
||||
#endif // PERF
|
||||
|
||||
#ifdef DEBUG2
|
||||
showMatrix(slater_matrix, dim, "NEW Slater");
|
||||
#endif
|
||||
|
||||
#ifdef DEBUG2
|
||||
showMatrix(slater_inverse, dim, "NEW Inverse");
|
||||
#endif
|
||||
delete[] u, col_update_index;
|
||||
|
||||
double *res = new double[dim * dim]{0};
|
||||
matMul(slater_matrix, slater_inverse, res, dim);
|
||||
@ -165,11 +120,7 @@ int test_cycle(H5File file, int cycle, std::string version, double tolerance) {
|
||||
std::cout << "Residual = " << version << " " << cycle << " " << res_max << " "
|
||||
<< res2 << std::endl;
|
||||
|
||||
#ifdef DEBUG2
|
||||
showMatrix(res, dim, "Result");
|
||||
#endif
|
||||
|
||||
delete[] res, updates, u, col_update_index, slater_matrix, slater_inverse;
|
||||
delete[] res, slater_matrix, slater_inverse;
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user