mirror of
https://github.com/TREX-CoE/Sherman-Morrison.git
synced 2024-12-26 06:15: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
|
## MKL linker flags
|
||||||
ifeq ($(MKL),-DMKL)
|
ifeq ($(MKL),-DMKL)
|
||||||
CXXFLAGS += $(MKL)
|
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)
|
ifeq ($(ENV),INTEL)
|
||||||
LFLAGS = -mkl=sequential # implicit
|
LFLAGS = -mkl=sequential # implicit
|
||||||
else
|
else
|
||||||
@ -50,6 +50,11 @@ DEPS_F = $(DEPS_CXX) \
|
|||||||
$(OBJ_DIR)/finterface_mod.o \
|
$(OBJ_DIR)/finterface_mod.o \
|
||||||
$(OBJ_DIR)/helpers_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
|
## Directory structure
|
||||||
SRC_DIR := src
|
SRC_DIR := src
|
||||||
TST_DIR := tests
|
TST_DIR := tests
|
||||||
@ -91,7 +96,7 @@ $(OBJ_DIR)/%.o: $(SRC_DIR)/%.cpp $(INC_DIR)/* | $(OBJ_DIR)
|
|||||||
|
|
||||||
## HDF5/C++ objects
|
## HDF5/C++ objects
|
||||||
$(OBJ_DIR)/%_h5.o: $(TST_DIR)/%_h5.cpp $(INC_DIR)/* | $(OBJ_DIR)
|
$(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
|
## Fortran modules
|
||||||
$(OBJ_DIR)/%_mod.o: $(SRC_DIR)/%_mod.f90 | $(OBJ_DIR)
|
$(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)
|
$(BIN_DIR)/fnu_test_h5: $(OBJ_DIR)/fnu_test_h5.o $(DEPS_CXX) | $(BIN_DIR)
|
||||||
$(H5CXX) $(H5LFLAGS) -o $@ $^
|
$(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)
|
$(BIN_DIR)/fMaponiA3_test_3x3_3: $(DEPS_F) $(OBJ_DIR)/fMaponiA3_test_3x3_3.o | $(BIN_DIR)
|
||||||
$(FC) $(LFLAGS) $(FLIBS) -o $@ $^
|
$(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 "hdf5/serial/hdf5.h"
|
||||||
|
|
||||||
#include "qmckl.h"
|
#include "qmckl.h"
|
||||||
|
#include "cstring"
|
||||||
|
#include "iostream"
|
||||||
|
|
||||||
|
#include "Helpers.hpp"
|
||||||
|
|
||||||
#define PERF
|
#define PERF
|
||||||
|
|
||||||
@ -15,7 +19,7 @@ using namespace H5;
|
|||||||
|
|
||||||
const H5std_string FILE_NAME("dataset.hdf5");
|
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);
|
DataSet ds = file.openDataSet(key);
|
||||||
ds.read(data, PredType::STD_U32LE);
|
ds.read(data, PredType::STD_U32LE);
|
||||||
ds.close();
|
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);
|
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 + "/slater_matrix_dim", &dim);
|
||||||
read_int(file, group + "/nupdates", &nupdates);
|
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];
|
double *slater_inverse = new double[dim * dim];
|
||||||
read_double(file, group + "/slater_inverse", slater_inverse);
|
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);
|
read_int(file, group + "/col_update_index", col_update_index);
|
||||||
|
|
||||||
double *updates = new double[nupdates * dim];
|
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];
|
double *u = new double[nupdates * dim];
|
||||||
|
|
||||||
/* Test */
|
/* Test */
|
||||||
#ifdef DEBUG2
|
|
||||||
showMatrix(slater_inverse, dim, "OLD Inverse");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Transform replacement updates in 'updates[]' into additive updates in 'u[]'
|
// Transform replacement updates in 'updates[]' into additive updates in 'u[]'
|
||||||
for (j = 0; j < nupdates; j++) {
|
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];
|
slater_matrix[i * dim + (col - 1)] = updates[i + j * dim];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
delete[] updates;
|
||||||
#ifdef DEBUG2
|
|
||||||
showMatrix(slater_matrix, dim, "OLD Slater");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef DEBUG2
|
|
||||||
showMatrix(u, dim, "Updates");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef PERF
|
#ifdef PERF
|
||||||
std::cout << "# of reps. = " << repetition_number << std::endl;
|
|
||||||
double *slater_inverse_nonpersistent = new double[dim * dim];
|
double *slater_inverse_nonpersistent = new double[dim * dim];
|
||||||
|
if (version == "sm1") {
|
||||||
for (unsigned int i = 0; i < repetition_number; i++) {
|
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));
|
dim * dim * sizeof(double));
|
||||||
if (version == "maponia3") {
|
qmckl_exit_code sherman_morrison_exit;
|
||||||
MaponiA3(slater_inverse_nonpersistent, dim, nupdates, u,
|
qmckl_context context;
|
||||||
col_update_index);
|
sherman_morrison_exit = qmckl_sherman_morrison_c(context,
|
||||||
} else if (version == "maponia3s") {
|
dim,
|
||||||
MaponiA3S(slater_inverse_nonpersistent, dim, nupdates, u,
|
nupdates,
|
||||||
col_update_index);
|
u,
|
||||||
} else if (version == "sm1") {
|
col_update_index,
|
||||||
SM1(slater_inverse_nonpersistent, dim, nupdates, u, col_update_index);
|
slater_inverse_nonpersistent);
|
||||||
} else if (version == "sm2") {
|
}
|
||||||
SM2(slater_inverse_nonpersistent, dim, nupdates, u, col_update_index);
|
}
|
||||||
} else if (version == "sm3") {
|
else {
|
||||||
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 {
|
|
||||||
std::cerr << "Unknown version " << version << std::endl;
|
std::cerr << "Unknown version " << version << std::endl;
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
std::memcpy(slater_inverse, slater_inverse_nonpersistent,
|
std::memcpy(slater_inverse, slater_inverse_nonpersistent,
|
||||||
dim * dim * sizeof(double));
|
dim * dim * sizeof(double));
|
||||||
delete[] slater_inverse_nonpersistent;
|
delete[] slater_inverse_nonpersistent;
|
||||||
#else
|
#else // No performance measurements repetition
|
||||||
if (version == "maponia3") {
|
if (version == "sm1") {
|
||||||
MaponiA3(slater_inverse, dim, nupdates, u, col_update_index);
|
qmckl_exit_code sherman_morrison_exit;
|
||||||
} else if (version == "maponia3s") {
|
qmckl_context context;
|
||||||
MaponiA3S(slater_inverse, dim, nupdates, u, col_update_index);
|
sherman_morrison_exit = qmckl_sherman_morrison_c(context,
|
||||||
} else if (version == "sm1") {
|
dim,
|
||||||
SM1(slater_inverse, dim, nupdates, u, col_update_index);
|
nupdates,
|
||||||
} else if (version == "sm2") {
|
u,
|
||||||
SM2(slater_inverse, dim, nupdates, u, col_update_index);
|
col_update_index,
|
||||||
} else if (version == "sm3") {
|
slater_inverse);
|
||||||
SM3(slater_inverse, dim, nupdates, u, col_update_index);
|
}
|
||||||
} else if (version == "sm4") {
|
else {
|
||||||
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 {
|
|
||||||
std::cerr << "Unknown version " << version << std::endl;
|
std::cerr << "Unknown version " << version << std::endl;
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
#endif // PERF
|
#endif // PERF
|
||||||
|
delete[] u, col_update_index;
|
||||||
#ifdef DEBUG2
|
|
||||||
showMatrix(slater_matrix, dim, "NEW Slater");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef DEBUG2
|
|
||||||
showMatrix(slater_inverse, dim, "NEW Inverse");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
double *res = new double[dim * dim]{0};
|
double *res = new double[dim * dim]{0};
|
||||||
matMul(slater_matrix, slater_inverse, res, dim);
|
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 << " "
|
std::cout << "Residual = " << version << " " << cycle << " " << res_max << " "
|
||||||
<< res2 << std::endl;
|
<< res2 << std::endl;
|
||||||
|
|
||||||
#ifdef DEBUG2
|
delete[] res, slater_matrix, slater_inverse;
|
||||||
showMatrix(res, dim, "Result");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
delete[] res, updates, u, col_update_index, slater_matrix, slater_inverse;
|
|
||||||
|
|
||||||
return ok;
|
return ok;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user