From 2a39aabaf06ce5ecf498cc55f3172696e3520e89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Coppens?= Date: Thu, 15 Jul 2021 17:56:33 +0200 Subject: [PATCH 1/4] Cleanup 1 --- Makefile | 4 ++-- include/SMWB.hpp | 14 ++------------ smvars.sh | 8 ++++++-- src/SMWB.cpp | 8 ++++---- src/Woodbury.cpp | 22 +++++++++++++--------- tests/fnu_test_h5.cpp | 8 ++++---- tests/test_h5.cpp | 14 ++------------ 7 files changed, 33 insertions(+), 45 deletions(-) diff --git a/Makefile b/Makefile index 5d3901c..b6c5da9 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ ## Compilers, compiler flags & external libs ifeq ($(ENV),INTEL) - CXX = icpc + CXX = icpx FC = ifort ARCH = -march=native OPT = -O3 @@ -15,7 +15,7 @@ else ifeq ($(ENV),GNU) CXX = g++ FC = gfortran ARCH = -mavx - OPT = -O0 + OPT = -O3 DEBUG = -g else $(error No valid compiler environment set in $$ENV. \ diff --git a/include/SMWB.hpp b/include/SMWB.hpp index 6d1d0f9..b117aef 100644 --- a/include/SMWB.hpp +++ b/include/SMWB.hpp @@ -4,18 +4,8 @@ void SMWB1(double *Slater_inv, const unsigned int Dim, const unsigned int N_updates, double *Updates, unsigned int *Updates_index); -// // Sherman-Morrison-Woodbury kernel 2 -// // WB2, WB3, SM3 mixing scheme -// void SMWB2(double *Slater_inv, unsigned int Dim, unsigned int N_updates, -// double *Updates, unsigned int *Updates_index); - -// // Sherman-Morrison-Woodbury kernel 3 -// // WB2, WB3, SM4 mixing scheme -// void SMWB3(double *Slater_inv, unsigned int Dim, unsigned int N_updates, -// double *Updates, unsigned int *Updates_index); - -// Sherman-Morrison-Woodbury kernel 4 +// Sherman-Morrison-Woodbury kernel 2 // WB2, SM2 mixing scheme -void SMWB4(double *Slater_inv, const unsigned int Dim, +void SMWB2(double *Slater_inv, const unsigned int Dim, const unsigned int N_updates, double *Updates, unsigned int *Updates_index); diff --git a/smvars.sh b/smvars.sh index 2e9e868..4f24e7b 100644 --- a/smvars.sh +++ b/smvars.sh @@ -27,20 +27,23 @@ export SMROOT case $ENV in intel) echo "* SM build environment set to 'intel'" - export HDF5_CXX=icpc - export HDF5_CXXLINKER=icpc + export HDF5_CXX=icpx + export HDF5_CXXLINKER=icpx + export HDF5_CLINKER=icpx export ENV=INTEL ;; llvm) echo "* SM build environment set to 'llvm'" export HDF5_CXX=clang++ export HDF5_CXXLINKER=clang++ + export HDF5_CLINKER=clang++ export ENV=LLVM ;; vfc) echo "* SM build environment set to 'vfc'" export HDF5_CXX=clang++ export HDF5_CXXLINKER=clang++ + export HDF5_CLINKER=clang++ export ENV=LLVM export VFC_BACKENDS="libinterflop_ieee.so --count-op" ;; @@ -48,6 +51,7 @@ case $ENV in echo "* SM build environment set to 'gnu'" export HDF5_CXX=g++ export HDF5_CXXLINKER=g++ + export HDF5_CLINKER=g++ export ENV=GNU ;; *) diff --git a/src/SMWB.cpp b/src/SMWB.cpp index 18c7d54..4006cf8 100644 --- a/src/SMWB.cpp +++ b/src/SMWB.cpp @@ -80,9 +80,9 @@ void SMWB1(double *Slater_inv, const unsigned int Dim, } } -// Sherman-Morrison-Woodbury kernel 4 +// Sherman-Morrison-Woodbury kernel 2 // WB2, SM2 mixing scheme -void SMWB4(double *Slater_inv, const unsigned int Dim, +void SMWB2(double *Slater_inv, const unsigned int Dim, const unsigned int N_updates, double *Updates, unsigned int *Updates_index) { #ifdef DEBUG2 @@ -144,8 +144,8 @@ void SMWB1_f(double **linSlater_inv, unsigned int *Dim, unsigned int *N_updates, double **linUpdates, unsigned int **Updates_index) { SMWB1(*linSlater_inv, *Dim, *N_updates, *linUpdates, *Updates_index); } -void SMWB4_f(double **linSlater_inv, unsigned int *Dim, unsigned int *N_updates, +void SMWB2_f(double **linSlater_inv, unsigned int *Dim, unsigned int *N_updates, double **linUpdates, unsigned int **Updates_index) { - SMWB4(*linSlater_inv, *Dim, *N_updates, *linUpdates, *Updates_index); + SMWB2(*linSlater_inv, *Dim, *N_updates, *linUpdates, *Updates_index); } } diff --git a/src/Woodbury.cpp b/src/Woodbury.cpp index ed7eb74..9c97b96 100644 --- a/src/Woodbury.cpp +++ b/src/Woodbury.cpp @@ -134,8 +134,8 @@ bool WB3(double *Slater_inv, const unsigned int Dim, double *Updates, // Check if determinant of B is not too close to zero double det; - det = B0 * (B4 * B8 - B5 * B7) - - B1 * (B3 * B8 - B5 * B6) + B2 * (B3 * B7 - B4 * B6); + det = B0 * (B4 * B8 - B5 * B7) - B1 * (B3 * B8 - B5 * B6) + + B2 * (B3 * B7 - B4 * B6); #ifdef DEBUG2 std::cerr << "Determinant of B = " << det << std::endl; #endif @@ -150,15 +150,15 @@ bool WB3(double *Slater_inv, const unsigned int Dim, double *Updates, // Compute B^{-1} with explicit formula for 3x3 inversion double Binv[9], idet = 1.0 / det; - Binv[0] = (B4 * B8 - B7 * B5) * idet; + Binv[0] = (B4 * B8 - B7 * B5) * idet; Binv[1] = -(B1 * B8 - B7 * B2) * idet; - Binv[2] = (B1 * B5 - B4 * B2) * idet; + Binv[2] = (B1 * B5 - B4 * B2) * idet; Binv[3] = -(B3 * B8 - B6 * B5) * idet; - Binv[4] = (B0 * B8 - B6 * B2) * idet; + Binv[4] = (B0 * B8 - B6 * B2) * idet; Binv[5] = -(B0 * B5 - B3 * B2) * idet; - Binv[6] = (B3 * B7 - B6 * B4) * idet; + Binv[6] = (B3 * B7 - B6 * B4) * idet; Binv[7] = -(B0 * B7 - B6 * B1) * idet; - Binv[8] = (B0 * B4 - B3 * B1) * idet; + Binv[8] = (B0 * B4 - B3 * B1) * idet; #ifdef DEBUG2 std::cerr << "Conditioning number of B = " << condition1(B, Binv, 3) @@ -198,10 +198,14 @@ bool WB3(double *Slater_inv, const unsigned int Dim, double *Updates, extern "C" { bool WB2_f(double **linSlater_inv, unsigned int *Dim, double **linUpdates, unsigned int **Updates_index) { - WB2(*linSlater_inv, *Dim, *linUpdates, *Updates_index); + bool ok; + ok = WB2(*linSlater_inv, *Dim, *linUpdates, *Updates_index); + return ok; } bool WB3_f(double **linSlater_inv, unsigned int *Dim, double **linUpdates, unsigned int **Updates_index) { - WB3(*linSlater_inv, *Dim, *linUpdates, *Updates_index); + bool ok; + ok = WB3(*linSlater_inv, *Dim, *linUpdates, *Updates_index); + return ok; } } diff --git a/tests/fnu_test_h5.cpp b/tests/fnu_test_h5.cpp index 3f9763a..f7e0146 100644 --- a/tests/fnu_test_h5.cpp +++ b/tests/fnu_test_h5.cpp @@ -126,11 +126,11 @@ int test_cycle(H5File file, int cycle, std::string version, double tolerance) { dim * dim * sizeof(double)); SMWB1(slater_inverse_nonpersistent, dim, nupdates, u, col_update_index); } - } else if (version == "smwb4") { + } else if (version == "smwb2") { for (unsigned int i = 0; i < repetition_number; i++) { std::memcpy(slater_inverse_nonpersistent, slater_inverse, dim * dim * sizeof(double)); - SMWB4(slater_inverse_nonpersistent, dim, nupdates, u, col_update_index); + SMWB2(slater_inverse_nonpersistent, dim, nupdates, u, col_update_index); } #ifdef MKL } else if (version == "lapack") { @@ -170,8 +170,8 @@ int test_cycle(H5File file, int cycle, std::string version, double tolerance) { // SMWB2(slater_inverse, dim, nupdates, u, col_update_index); // } else if (version == "smwb3") { // SMWB3(slater_inverse, dim, nupdates, u, col_update_index); - } else if (version == "smwb4") { - SMWB4(slater_inverse, dim, nupdates, u, col_update_index); + } else if (version == "smwb2") { + SMWB2(slater_inverse, dim, nupdates, u, col_update_index); #ifdef MKL } else if (version == "lapack") { memcpy(slater_inverse, slater_matrix, dim * dim * sizeof(double)); diff --git a/tests/test_h5.cpp b/tests/test_h5.cpp index 5763125..70c9787 100644 --- a/tests/test_h5.cpp +++ b/tests/test_h5.cpp @@ -104,14 +104,8 @@ int test_cycle(H5File file, int cycle, std::string version, double tolerance) { 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); - // } else if (version == "smwb3") { - // SMWB3(slater_inverse_nonpersistent, dim, nupdates, u, - // col_update_index); - } else if (version == "smwb4") { - SMWB4(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, @@ -145,10 +139,6 @@ int test_cycle(H5File file, int cycle, std::string version, double tolerance) { WB3(slater_inverse, dim, u, col_update_index); } else if (version == "smwb1") { SMWB1(slater_inverse, dim, nupdates, u, col_update_index); - // } else if (version == "smwb2") { - // SMWB2(slater_inverse, dim, nupdates, u, col_update_index); - // } else if (version == "smwb3") { - // SMWB3(slater_inverse, dim, nupdates, u, col_update_index); } else if (version == "smwb4") { SMWB4(slater_inverse, dim, nupdates, u, col_update_index); #ifdef MKL From 3c87cb311e893f51a90bbf7d881377e33c87db67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Coppens?= Date: Thu, 15 Jul 2021 18:14:47 +0200 Subject: [PATCH 2/4] Simplified SM2(...) {...} --- src/SM_Standard.cpp | 56 ++++----------------------------------------- 1 file changed, 4 insertions(+), 52 deletions(-) diff --git a/src/SM_Standard.cpp b/src/SM_Standard.cpp index 84b5c82..e2a19d7 100644 --- a/src/SM_Standard.cpp +++ b/src/SM_Standard.cpp @@ -65,55 +65,7 @@ void SM2(double *Slater_inv, unsigned int Dim, unsigned int N_updates, unsigned int later_index[N_updates]; unsigned int later = 0; - double C[Dim]; - double D[Dim]; - - unsigned int l = 0; - // For each update - while (l < N_updates) { - // C = A^{-1} x U_l - for (unsigned int i = 0; i < Dim; i++) { - C[i] = 0; - for (unsigned int j = 0; j < Dim; j++) { - C[i] += Slater_inv[i * Dim + j] * Updates[l * Dim + j]; - } - } - - // Denominator - double den = 1 + C[Updates_index[l] - 1]; - if (std::fabs(den) < threshold()) { -#ifdef DEBUG1 - std::cerr << "Breakdown condition triggered at " << Updates_index[l] - << std::endl; - std::cerr << "Denominator = " << den << std::endl; -#endif - - // U_l = U_l / 2 (do the split) - for (unsigned int i = 0; i < Dim; i++) { - later_updates[later * Dim + i] = Updates[l * Dim + i] / 2.0; - C[i] /= 2.0; - } - later_index[later] = Updates_index[l]; - later++; - - den = 1 + C[Updates_index[l] - 1]; - } - double iden = 1 / den; - - // D = v^T x A^{-1} - for (unsigned int j = 0; j < Dim; j++) { - D[j] = Slater_inv[(Updates_index[l] - 1) * Dim + j]; - } - - // A^{-1} = A^{-1} - C x D / den - for (unsigned int i = 0; i < Dim; i++) { - for (unsigned int j = 0; j < Dim; j++) { - double update = C[i] * D[j] * iden; - Slater_inv[i * Dim + j] -= update; - } - } - l += 1; - } + SM2star(Slater_inv, Dim, N_updates, Updates, Updates_index, later_updates, later_index, &later); if (later > 0) { SM2(Slater_inv, Dim, later, later_updates, later_index); @@ -136,7 +88,7 @@ void SM2star(double *Slater_inv, unsigned int Dim, unsigned int N_updates, unsigned int l = 0; // For each update while (l < N_updates) { - // C = A^{-1} x U_l + // C = S^{-1} x U_l for (unsigned int i = 0; i < Dim; i++) { C[i] = 0; for (unsigned int j = 0; j < Dim; j++) { @@ -165,12 +117,12 @@ void SM2star(double *Slater_inv, unsigned int Dim, unsigned int N_updates, } double iden = 1 / den; - // D = v^T x A^{-1} + // D = v^T x S^{-1} for (unsigned int j = 0; j < Dim; j++) { D[j] = Slater_inv[(Updates_index[l] - 1) * Dim + j]; } - // A^{-1} = A^{-1} - C x D / den + // S^{-1} = S^{-1} - C x D / den for (unsigned int i = 0; i < Dim; i++) { for (unsigned int j = 0; j < Dim; j++) { double update = C[i] * D[j] * iden; From f10502da9d84b4c61098036039d2790274596532 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Coppens?= Date: Thu, 15 Jul 2021 18:15:46 +0200 Subject: [PATCH 3/4] Cleaning 2 --- src/SM_Standard.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/SM_Standard.cpp b/src/SM_Standard.cpp index e2a19d7..8545e9a 100644 --- a/src/SM_Standard.cpp +++ b/src/SM_Standard.cpp @@ -65,7 +65,8 @@ void SM2(double *Slater_inv, unsigned int Dim, unsigned int N_updates, unsigned int later_index[N_updates]; unsigned int later = 0; - SM2star(Slater_inv, Dim, N_updates, Updates, Updates_index, later_updates, later_index, &later); + SM2star(Slater_inv, Dim, N_updates, Updates, Updates_index, later_updates, + later_index, &later); if (later > 0) { SM2(Slater_inv, Dim, later, later_updates, later_index); From 2ec8fb278cb694adf43527304138b0b1e03553c2 Mon Sep 17 00:00:00 2001 From: Francois Coppens Date: Sat, 17 Jul 2021 11:40:59 +0200 Subject: [PATCH 4/4] Minor modifications to test programs. --- tests/fnu_test_h5.cpp | 10 +++------- tests/test_h5.cpp | 9 ++++++++- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/tests/fnu_test_h5.cpp b/tests/fnu_test_h5.cpp index f7e0146..50272c0 100644 --- a/tests/fnu_test_h5.cpp +++ b/tests/fnu_test_h5.cpp @@ -10,7 +10,7 @@ #include #define PERF -// #define STATUS +#define STATUS // #define RESIDUAL #ifdef PERF @@ -166,10 +166,6 @@ int test_cycle(H5File file, int cycle, std::string version, double tolerance) { WB3(slater_inverse, dim, u, col_update_index); } else if (version == "smwb1") { SMWB1(slater_inverse, dim, nupdates, u, col_update_index); - // } else if (version == "smwb2") { - // SMWB2(slater_inverse, dim, nupdates, u, col_update_index); - // } else if (version == "smwb3") { - // SMWB3(slater_inverse, dim, nupdates, u, col_update_index); } else if (version == "smwb2") { SMWB2(slater_inverse, dim, nupdates, u, col_update_index); #ifdef MKL @@ -213,14 +209,14 @@ int main(int argc, char **argv) { if (argc != 5) { std::cerr << "Execute from within 'datasets/'" << std::endl; std::cerr - << "usage: test_h5 " + << "usage: fnu_test_h5 " << std::endl; return 1; } #else if (argc != 4) { std::cerr << "Execute from within 'datasets/'" << std::endl; - std::cerr << "usage: test_h5 " + std::cerr << "usage: fnu_test_h5 " << std::endl; return 1; } diff --git a/tests/test_h5.cpp b/tests/test_h5.cpp index 70c9787..d0a151f 100644 --- a/tests/test_h5.cpp +++ b/tests/test_h5.cpp @@ -181,15 +181,22 @@ int test_cycle(H5File file, int cycle, std::string version, double tolerance) { int main(int argc, char **argv) { #ifdef PERF if (argc != 6) { + std::cerr << "Execute from within 'datasets/'" << std::endl; + std::cerr + << "usage: test_h5 " + << std::endl; + return 1; + } #else if (argc != 5) { -#endif std::cerr << "Execute from within 'datasets/'" << std::endl; std::cerr << "usage: test_h5 " << std::endl; return 1; } +#endif + std::string version(argv[1]); int start_cycle = std::stoi(argv[2]); int stop_cycle = std::stoi(argv[3]);