From 00fcaf230984406bac1d3df94c7882c24594459c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Coppens?= Date: Thu, 25 Feb 2021 12:59:38 +0100 Subject: [PATCH 1/3] Replaced dataset. --- tests/convert-to-h5.py | 2 +- tests/test.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/convert-to-h5.py b/tests/convert-to-h5.py index 72a1173..e3dcaf9 100644 --- a/tests/convert-to-h5.py +++ b/tests/convert-to-h5.py @@ -7,7 +7,7 @@ def rl(rf): with h5py.File('datasets.hdf5', 'w') as f: - with open('datasets.short.dat', 'r') as rf: + with open('datasets.dat', 'r') as rf: while(1): line = rl(rf) if not line or not line.startswith('#START_PACKET'): diff --git a/tests/test.cpp b/tests/test.cpp index 01ae2b5..de0b63d 100644 --- a/tests/test.cpp +++ b/tests/test.cpp @@ -7,9 +7,9 @@ #include "../Helpers.hpp" using namespace H5; -#define DEBUG 1 +//#define DEBUG 0 -const H5std_string FILE_NAME( "datasets.small.hdf5" ); +const H5std_string FILE_NAME( "datasets.hdf5" ); void read_int(H5File file, std::string key, unsigned int * data) { DataSet ds = file.openDataSet(key); From 5d4a7af01a3f41aab60738b3b03486c5cbd10083 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Coppens?= Date: Fri, 26 Feb 2021 17:28:52 +0100 Subject: [PATCH 2/3] File tree restructured. Written build script build.sh. TODO: convert buld script into Makefile. --- .gitignore | 1 - Makefile | 45 +++--- build.sh | 36 +++++ cMaponiA3_test_3x3_3.cpp | 53 ------ fMaponiA3_test_3x3_3.f90 | 59 ------- fMaponiA3_test_4x4_2.f90 | 151 ------------------ Helpers.hpp => include/Helpers.hpp | 0 SM_MaponiA3.hpp => include/SM_MaponiA3.hpp | 0 mwe/compile.sh | 1 - mwe/main.cpp | 23 --- mwe/main.f90 | 12 -- mwe/worker.cpp | 7 - mwe/worker.h | 6 - .../QMCChem_dataset_test.m | 0 {Octave-tests => octave-tests}/SM-Coppens-1.m | 0 {Octave-tests => octave-tests}/SMMaponiA3.m | 0 {Octave-tests => octave-tests}/SMMaponiA4.m | 0 Helpers_mod.f90 => src/Helpers_mod.f90 | 0 SM_MaponiA3.cpp => src/SM_MaponiA3.cpp | 0 .../SM_MaponiA3_mod.f90 | 0 det.irp.f => src/det.irp.f | 0 .../QMCChem_dataset_test.f90 | 0 tests/test.cpp | 4 +- {tests => tools}/convert-to-h5.py | 0 24 files changed, 63 insertions(+), 335 deletions(-) create mode 100755 build.sh delete mode 100644 cMaponiA3_test_3x3_3.cpp delete mode 100644 fMaponiA3_test_3x3_3.f90 delete mode 100644 fMaponiA3_test_4x4_2.f90 rename Helpers.hpp => include/Helpers.hpp (100%) rename SM_MaponiA3.hpp => include/SM_MaponiA3.hpp (100%) delete mode 100755 mwe/compile.sh delete mode 100644 mwe/main.cpp delete mode 100644 mwe/main.f90 delete mode 100644 mwe/worker.cpp delete mode 100644 mwe/worker.h rename QMCChem_dataset_test.m => octave-tests/QMCChem_dataset_test.m (100%) rename {Octave-tests => octave-tests}/SM-Coppens-1.m (100%) rename {Octave-tests => octave-tests}/SMMaponiA3.m (100%) rename {Octave-tests => octave-tests}/SMMaponiA4.m (100%) rename Helpers_mod.f90 => src/Helpers_mod.f90 (100%) rename SM_MaponiA3.cpp => src/SM_MaponiA3.cpp (100%) rename SM_MaponiA3_mod.f90 => src/SM_MaponiA3_mod.f90 (100%) rename det.irp.f => src/det.irp.f (100%) rename QMCChem_dataset_test.f90 => tests/QMCChem_dataset_test.f90 (100%) rename {tests => tools}/convert-to-h5.py (100%) diff --git a/.gitignore b/.gitignore index c4bd975..970fc12 100644 --- a/.gitignore +++ b/.gitignore @@ -8,4 +8,3 @@ Slater* Updates* tests/test datasets/datasets.* - diff --git a/Makefile b/Makefile index 127e584..271570a 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,10 @@ -# ARCH = -xCORE-AVX2 +SRC_DIR := src +INC_DIR := include +OBJ_DIR := build +BIN_DIR := bin ## Used compilers +ARCH = -xCORE-AVX2 H5CXX = h5c++ CXX = icpc FC = ifort @@ -9,10 +13,11 @@ FC = ifort H5CXXFLAGS = -O0 -g CXXFLAGS = -O0 -g -traceback FFLAGS = -O0 -g -traceback +INCLUDE = -I$(INC_DIR) FLIBS = -lstdc++ -OBJS = SM_MaponiA3.o ## Deps & objs for C++ cMaponiA3_test_3x3_3 +OBJS = $(OBJ_DIR)/SM_MaponiA3.o cMaponiA3_test_3x3_3OBJ = cMaponiA3_test_3x3_3.o fMaponiA3_test_3x3_3OBJ = SM_MaponiA3_mod.o fMaponiA3_test_3x3_3.o fMaponiA3_test_4x4_2OBJ = Helpers_mod.o SM_MaponiA3_mod.o fMaponiA3_test_4x4_2.o @@ -24,45 +29,45 @@ all: cMaponiA3_test_3x3_3 fMaponiA3_test_3x3_3 fMaponiA3_test_4x4_2 QMCChem_data ## Compile recipes for C++ -%.o: %.cpp - $(CXX) $(ARCH) $(CXXFLAGS) -c -o $@ $< +$(OBJ_DIR)/%.o: $(SRC_DIR)/%.cpp | $(OBJ_DIR) + $(CXX) $(ARCH) $(CXXFLAGS) $(INCLUDE) -c -o $@ $< ## Compile recepies for Fortran -%.o: %.f90 +$(OBJ_DIR)/%.o: $(SRC_DIR)/%.f90 | $(OBJ_DIR) $(FC) $(ARCH) $(FFLAGS) -c -o $@ $< ## Explicit recipe to trigger rebuild and relinking when headerfile is changed -SM_MaponiA3.o: SM_MaponiA3.cpp Helpers.hpp - $(CXX) $(ARCH) $(CXXFLAGS) -fPIC -c -o $@ $< +$(OBJ_DIR)/SM_MaponiA3.o: $(SRC_DIR)/SM_MaponiA3.cpp $(INC_DIR)/Helpers.hpp| $(OBJ_DIR) + $(CXX) $(ARCH) $(CXXFLAGS) $(INCLUDE) -fPIC -c -o $@ $< ## Build tagets .PHONY: all clean distclean clean: - @rm -vf *.o *.mod + @rm -vrf $(OBJ_DIR) distclean: clean - @rm -vf cMaponiA3_test_3x3_3 \ - fMaponiA3_test_3x3_3 fMaponiA3_test_4x4_2 \ - QMCChem_dataset_test \ - Slater* Updates.dat \ - tests/test + @rm -vrf $(BIN_DIR) \ + Slater* Updates.dat ## Linking the C++ example program -cMaponiA3_test_3x3_3: $(cMaponiA3_test_3x3_3OBJ) $(OBJS) - $(CXX) $(ARCH) $(CXXFLAGS) -o $@ $^ +$(BIN_DIR)/cMaponiA3_test_3x3_3: $(OBJ_DIR)/$(cMaponiA3_test_3x3_3OBJ) $(OBJS) | $(BIN_DIR) + $(CXX) $(ARCH) $(CXXFLAGS) $(INCLUDE) -o $@ $^ ## Linking Fortran example program calling the C++ function -fMaponiA3_test_3x3_3: $(fMaponiA3_test_3x3_3OBJ) $(OBJS) +$(BIN_DIR)/fMaponiA3_test_3x3_3: $(OBJ_DIR)/$(fMaponiA3_test_3x3_3OBJ) $(OBJS) | $(BIN_DIR) $(FC) $(ARCH) $(FFLAGS) $(FLIBS) -o $@ $^ -fMaponiA3_test_4x4_2: $(fMaponiA3_test_4x4_2OBJ) $(OBJS) +$(BIN_DIR)/fMaponiA3_test_4x4_2: $(OBJ_DIR)/$(fMaponiA3_test_4x4_2OBJ) $(OBJS) | $(BIN_DIR) $(FC) $(ARCH) $(FFLAGS) $(FLIBS) -o $@ $^ -QMCChem_dataset_test: $(QMCChem_dataset_testOBJ) $(OBJS) +$(BIN_DIR)/QMCChem_dataset_test: $(OBJ_DIR)/$(QMCChem_dataset_testOBJ) $(OBJS) | $(BIN_DIR) $(FC) $(ARCH) $(FFLAGS) $(FLIBS) -o $@ $^ -tests/test: tests/test.cpp SM_MaponiA3.o - $(H5CXX) $(ARCH) $(H5CXXFLAGS) -o $@ $^ +$(BIN_DIR)/test: $(SRC_DIR)/test.cpp $(OBJS) | $(BIN_DIR) + $(H5CXX) $(H5CXXFLAGS) $(INCLUDE) -o $@ $^ + +$(BIN_DIR) $(OBJ_DIR): + mkdir -p $@ diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..f4c7e12 --- /dev/null +++ b/build.sh @@ -0,0 +1,36 @@ + + +mkdir build/ bin/ + +## compile tests/test.cpp +icpc -O0 -fPIC -c src/SM_MaponiA3.cpp -o build/SM_MaponiA3.o -I include/ + +## compile tests/fMaponiA3_test_3x3_3.f90 +ifort -c src/SM_MaponiA3_mod.f90 -o build/SM_MaponiA3_mod.o -module build +ifort -c tests/fMaponiA3_test_3x3_3.f90 -o build/fMaponiA3_test_3x3_3.o -I build/ +## link bin/QMCChem_dataset_test +ifort -o bin/fMaponiA3_test_3x3_3 build/fMaponiA3_test_3x3_3.o build/SM_MaponiA3_mod.o build/SM_MaponiA3.o -lstdc++ + +## compile tests/fMaponiA3_test_4x4_2.f90 +ifort -c src/SM_MaponiA3_mod.f90 -o build/SM_MaponiA3_mod.o -module build +ifort -c src/Helpers_mod.f90 -o build/Helpers_mod.o -module build +ifort -c tests/fMaponiA3_test_4x4_2.f90 -o build/fMaponiA3_test_4x4_2.o -I build/ +## link bin/QMCChem_dataset_test +ifort -o bin/fMaponiA3_test_4x4_2 build/fMaponiA3_test_4x4_2.o build/SM_MaponiA3_mod.o build/Helpers_mod.o build/SM_MaponiA3.o -lstdc++ + +## compile tests/QMCChem_dataset_test.f90 +ifort -c src/SM_MaponiA3_mod.f90 -o build/SM_MaponiA3_mod.o -module build +ifort -c src/Helpers_mod.f90 -o build/Helpers_mod.o -module build +ifort -c tests/QMCChem_dataset_test.f90 -o build/QMCChem_dataset_test.o -I build/ +## link bin/QMCChem_dataset_test +ifort -o bin/QMCChem_dataset_test build/QMCChem_dataset_test.o build/SM_MaponiA3_mod.o build/Helpers_mod.o build/SM_MaponiA3.o -lstdc++ + +## compile tests/test.cpp +h5c++ -c tests/test.cpp -o build/test.o -I include/ +## link bin/test +h5c++ -o bin/test build/test.o build/SM_MaponiA3.o + +## compile tests/cMaponiA3_test_3x3_3.cpp +icpc -c tests/cMaponiA3_test_3x3_3.cpp -o build/cMaponiA3_test_3x3_3.o -I include/ +## link bin/cMaponiA3_test_3x3_3 +icpc -o bin/cMaponiA3_test_3x3_3 build/cMaponiA3_test_3x3_3.o build/SM_MaponiA3.o diff --git a/cMaponiA3_test_3x3_3.cpp b/cMaponiA3_test_3x3_3.cpp deleted file mode 100644 index 525d15d..0000000 --- a/cMaponiA3_test_3x3_3.cpp +++ /dev/null @@ -1,53 +0,0 @@ -// main.cpp -#include "SM_MaponiA3.hpp" -#include "Helpers.hpp" - -int main() { - - unsigned int M = 3; // Dimension of the Slater-matrix - unsigned int i, j; // Indices for iterators - - // Declare, allocate all vectors and matrices and fill them with zeros - unsigned int *Ar_index = new unsigned int[M]; - double *A = new double[M*M]; // The matrix to be inverted - double *A0 = new double[M*M]; // A diagonal matrix with the digonal elements of A - double *Ar = new double[M*M]; // The update matrix - double *A0_inv = new double[M*M]; // The inverse - - // Fill with zeros - for (i = 0; i < M; i++) { - for (j = 0; j < M; j++) { - A0[i*M+j] = 0; - Ar[i*M+j] = 0; - A0_inv[i*M+j] = 0; - } - } - - // Initialize A with M=3 and fill acc. to Eq. (17) from paper - A[0] = 1; A[3] = 1; A[6] = -1; - A[1] = 1; A[4] = 1; A[7] = 0; - A[2] = -1; A[5] = 0; A[8] = -1; - - showMatrix(A, M, "A"); - - // Initialize the diagonal matrix A0, - // the inverse of A0_inv of diagonal matrix A0_inv - // and the update matrix Ar - for (i = 0; i < M; i++) { - A0[i*M + i] = A[i*M + i]; - A0_inv[i*M + i] = 1.0/A[i*M + i]; - Ar_index[i] = i+1; // ! First column needs to start with 1 ! - for (j = 0; j < M; j++) { - Ar[i*M + j] = A[i*M + j] - A0[i*M + j]; - } - } - - // Define pointers dim and n_updates to use in Sherman-Morrison(...) function call - MaponiA3(A0_inv, M, M, Ar, Ar_index); - showMatrix(A0_inv, M, "A0_inv"); - - // Deallocate all vectors and matrices - delete [] A, A0, A0_inv, Ar, Ar_index; - - return 0; -} diff --git a/fMaponiA3_test_3x3_3.f90 b/fMaponiA3_test_3x3_3.f90 deleted file mode 100644 index bbc921c..0000000 --- a/fMaponiA3_test_3x3_3.f90 +++ /dev/null @@ -1,59 +0,0 @@ -program Interface_test - use Sherman_Morrison - implicit none - - integer i, j !! Iterators - integer(c_int) :: Dim, N_updates - integer(c_int), dimension(:), allocatable :: Updates_index - real(c_double), dimension(:,:), allocatable :: A, S, Updates - real(c_double), dimension(:,:), allocatable :: S_inv - - Dim = 3 - N_updates = 3 - allocate(Updates_index(Dim), A(Dim,Dim), S(Dim,Dim), Updates(Dim,Dim), S_inv(Dim,Dim)) - - !! Initialize A with M=3 and fill acc. to Eq. (17) from paper - A(1,1) = 1.0d0 - A(1,2) = 1.0d0 - A(1,3) = -1.0d0 - A(2,1) = 1.0d0 - A(2,2) = 1.0d0 - A(2,3) = 0.0d0 - A(3,1) = -1.0d0 - A(3,2) = 0.0d0 - A(3,3) = -1.0d0 - - do i=1,Dim - do j=1,Dim - write(*,"(F3.0,3X)", advance="no") A(i,j) - end do - write(*,*) - end do - write(*,*) - - !! Prepare the diagonal matrix S and the update matrix Updates - do i=1,Dim - Updates_index(i) = i - do j=1,Dim - if (i == j) then - S(i,j) = A(i,j) - S_inv(i,j) = 1.0d0 / S(i,j) - else - S(i,j) = 0.0d0 - S_inv(i,j) = 0.0d0 - end if - Updates(i,j) = A(i,j) - S(i,j) - end do - end do - - call MaponiA3(S_inv, Dim, N_updates, Updates, Updates_index) - - do i=1,Dim - do j=1,Dim - write(*,"(F3.0,3X)", advance="no") S_inv(i,j) - end do - write(*,*) - end do - - deallocate(Updates_index, A, S, Updates, S_inv) -end program diff --git a/fMaponiA3_test_4x4_2.f90 b/fMaponiA3_test_4x4_2.f90 deleted file mode 100644 index 863b87b..0000000 --- a/fMaponiA3_test_4x4_2.f90 +++ /dev/null @@ -1,151 +0,0 @@ -program Interface_test - use Sherman_Morrison - use Helpers - implicit none - - integer i, j, col !! Iterators - integer(c_int) :: Dim, N_updates - integer(c_int), dimension(:), allocatable :: Updates_index - real(c_double), dimension(:,:), allocatable :: S, A, Updates - real(c_double), dimension(:,:), allocatable :: S_inv, S_inv_t, A_inv - - Dim = 4 - N_updates = 2 - allocate( S(Dim,Dim), S_inv(Dim,Dim), S_inv_t(Dim,Dim), A(Dim,Dim), A_inv(Dim,Dim), & - Updates(Dim,N_updates), Updates_index(N_updates)) - - !! Initialize S, S_inv, A and A_inv - S(1,1) = 1.0d0 - S(1,2) = 0.0d0 - S(1,3) = 1.0d0 - S(1,4) = -1.0d0 - S(2,1) = 0.0d0 - S(2,2) = 1.0d0 - S(2,3) = 1.0d0 - S(2,4) = 0.0d0 - S(3,1) = -1.0d0 - S(3,2) = 0.0d0 - S(3,3) = -1.0d0 - S(3,4) = 0.0d0 - S(4,1) = 1.0d0 - S(4,2) = 1.0d0 - S(4,3) = 1.0d0 - S(4,4) = 1.0d0 - - S_inv(1,1) = 1.0d0 - S_inv(1,2) = -1.0d0 - S_inv(1,3) = 1.0d0 - S_inv(1,4) = 1.0d0 - S_inv(2,1) = 1.0d0 - S_inv(2,2) = 0.0d0 - S_inv(2,3) = 2.0d0 - S_inv(2,4) = 1.0d0 - S_inv(3,1) = -1.0d0 - S_inv(3,2) = 1.0d0 - S_inv(3,3) = -2.0d0 - S_inv(3,4) = -1.0d0 - S_inv(4,1) = -1.0d0 - S_inv(4,2) = 0.0d0 - S_inv(4,3) = -1.0d0 - S_inv(4,4) = 0.0d0 - - A(1,1) = 1.0d0 - A(1,2) = 0.0d0 - A(1,3) = 1.0d0 - A(1,4) = -1.0d0 - A(2,1) = 0.0d0 - A(2,2) = -1.0d0 - A(2,3) = 1.0d0 - A(2,4) = -1.0d0 - A(3,1) = -1.0d0 - A(3,2) = 0.0d0 - A(3,3) = -1.0d0 - A(3,4) = 0.0d0 - A(4,1) = 1.0d0 - A(4,2) = 1.0d0 - A(4,3) = 1.0d0 - A(4,4) = 1.0d0 - - A_inv(1,1) = 0.0d0 - A_inv(1,2) = -1.0d0 - A_inv(1,3) = -2.0d0 - A_inv(1,4) = -1.0d0 - A_inv(2,1) = 1.0d0 - A_inv(2,2) = 0.0d0 - A_inv(2,3) = 2.0d0 - A_inv(2,4) = 1.0d0 - A_inv(3,1) = 0.0d0 - A_inv(3,2) = 1.0d0 - A_inv(3,3) = 1.0d0 - A_inv(3,4) = 1.0d0 - A_inv(4,1) = -1.0d0 - A_inv(4,2) = 0.0d0 - A_inv(4,3) = -1.0d0 - A_inv(4,4) = 0.0d0 - - !! Prepare Updates and Updates_index - Updates(1,1) = 0 - Updates(1,2) = 0 - Updates(2,1) = -2 - Updates(2,2) = -1 - Updates(3,1) = 0 - Updates(3,2) = 0 - Updates(4,1) = 0 - Updates(4,2) = 0 - - Updates_index(1) = 2 - Updates_index(2) = 4 - - !! Write current S and S_inv to file for check in Octave - open(unit = 2000, file = "Slater_old.dat") - open(unit = 3000, file = "Slater_old_inv.dat") - do i=1,dim - do j=1,dim - write(2000,"(E23.15, 1X)", advance="no") S(i,j) - write(3000,"(E23.15, 1X)", advance="no") S_inv(i,j) - end do - write(2000,*) - write(3000,*) - end do - close(2000) - close(3000) - - !! Write Updates to file to check - open(unit = 2000, file = "Updates.dat") - do i=1,dim - do j=1,n_updates - write(2000,"(E23.15, 1X)", advance="no") Updates(i,j) - end do - write(2000,*) - end do - close(2000) - - !! Update S - do i=1,N_updates - do j=1,Dim - col = Updates_index(i) - S(j,col) = S(j,col) + Updates(j,i) - end do - end do - - !! Update S_inv - call Transpose(S_inv, S_inv_t, Dim) - call MaponiA3(S_inv_t, Dim, N_updates, Updates, Updates_index) - call Transpose(S_inv_t, S_inv, Dim) - - !! Write new S and S_inv to file for check in Octave - open(unit = 4000, file = "Slater.dat") - open(unit = 5000, file = "Slater_inv.dat") - do i=1,dim - do j=1,dim - write(4000,"(E23.15, 1X)", advance="no") S(i,j) - write(5000,"(E23.15, 1X)", advance="no") S_inv(i,j) - end do - write(4000,*) - write(5000,*) - end do - close(4000) - close(5000) - - deallocate(Updates_index, A, A_inv, S, Updates, S_inv) -end program diff --git a/Helpers.hpp b/include/Helpers.hpp similarity index 100% rename from Helpers.hpp rename to include/Helpers.hpp diff --git a/SM_MaponiA3.hpp b/include/SM_MaponiA3.hpp similarity index 100% rename from SM_MaponiA3.hpp rename to include/SM_MaponiA3.hpp diff --git a/mwe/compile.sh b/mwe/compile.sh deleted file mode 100755 index 72b5010..0000000 --- a/mwe/compile.sh +++ /dev/null @@ -1 +0,0 @@ -icpc -c worker.cpp && ifort -c main.f90 && ifort -lstdc++ worker.o main.o -o test diff --git a/mwe/main.cpp b/mwe/main.cpp deleted file mode 100644 index cdf7867..0000000 --- a/mwe/main.cpp +++ /dev/null @@ -1,23 +0,0 @@ -#include - - -int main() -{ - - typedef int (*to2D)[3]; //pint2 is a pointer to an array of 2 ints - int linArray[9] = {0,1,2,3,4,5,6,7,8}; - - to2D dArray = (to2D)linArray; - - std::cout << dArray[0][0] << std::endl; - std::cout << dArray[0][1] << std::endl; - std::cout << dArray[0][2] << std::endl; - std::cout << dArray[1][0] << std::endl; - std::cout << dArray[1][1] << std::endl; - std::cout << dArray[1][2] << std::endl; - std::cout << dArray[2][0] << std::endl; - std::cout << dArray[2][1] << std::endl; - std::cout << dArray[2][2] << std::endl; - - return 0; -} diff --git a/mwe/main.f90 b/mwe/main.f90 deleted file mode 100644 index 4d9a8e1..0000000 --- a/mwe/main.f90 +++ /dev/null @@ -1,12 +0,0 @@ -program test - use iso_c_binding - implicit none - - interface - subroutine hello() bind(C, name="worker") - end subroutine - end interface - - call hello() - -end program test diff --git a/mwe/worker.cpp b/mwe/worker.cpp deleted file mode 100644 index 1b678b8..0000000 --- a/mwe/worker.cpp +++ /dev/null @@ -1,7 +0,0 @@ -#include "worker.h" - -void worker() -{ - std::cout << "Hello, World!" << std::endl; -} - diff --git a/mwe/worker.h b/mwe/worker.h deleted file mode 100644 index 70ff209..0000000 --- a/mwe/worker.h +++ /dev/null @@ -1,6 +0,0 @@ -#include - -extern "C" -{ - void worker(); -} diff --git a/QMCChem_dataset_test.m b/octave-tests/QMCChem_dataset_test.m similarity index 100% rename from QMCChem_dataset_test.m rename to octave-tests/QMCChem_dataset_test.m diff --git a/Octave-tests/SM-Coppens-1.m b/octave-tests/SM-Coppens-1.m similarity index 100% rename from Octave-tests/SM-Coppens-1.m rename to octave-tests/SM-Coppens-1.m diff --git a/Octave-tests/SMMaponiA3.m b/octave-tests/SMMaponiA3.m similarity index 100% rename from Octave-tests/SMMaponiA3.m rename to octave-tests/SMMaponiA3.m diff --git a/Octave-tests/SMMaponiA4.m b/octave-tests/SMMaponiA4.m similarity index 100% rename from Octave-tests/SMMaponiA4.m rename to octave-tests/SMMaponiA4.m diff --git a/Helpers_mod.f90 b/src/Helpers_mod.f90 similarity index 100% rename from Helpers_mod.f90 rename to src/Helpers_mod.f90 diff --git a/SM_MaponiA3.cpp b/src/SM_MaponiA3.cpp similarity index 100% rename from SM_MaponiA3.cpp rename to src/SM_MaponiA3.cpp diff --git a/SM_MaponiA3_mod.f90 b/src/SM_MaponiA3_mod.f90 similarity index 100% rename from SM_MaponiA3_mod.f90 rename to src/SM_MaponiA3_mod.f90 diff --git a/det.irp.f b/src/det.irp.f similarity index 100% rename from det.irp.f rename to src/det.irp.f diff --git a/QMCChem_dataset_test.f90 b/tests/QMCChem_dataset_test.f90 similarity index 100% rename from QMCChem_dataset_test.f90 rename to tests/QMCChem_dataset_test.f90 diff --git a/tests/test.cpp b/tests/test.cpp index de0b63d..ef96b0e 100644 --- a/tests/test.cpp +++ b/tests/test.cpp @@ -3,8 +3,8 @@ #include "hdf5/serial/hdf5.h" #include "H5Cpp.h" -#include "../SM_MaponiA3.hpp" -#include "../Helpers.hpp" +#include "SM_MaponiA3.hpp" +#include "Helpers.hpp" using namespace H5; //#define DEBUG 0 diff --git a/tests/convert-to-h5.py b/tools/convert-to-h5.py similarity index 100% rename from tests/convert-to-h5.py rename to tools/convert-to-h5.py From 8e0aef7717fad51ed216b6d86b2914fcac1932a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Coppens?= Date: Sat, 27 Feb 2021 12:25:55 +0100 Subject: [PATCH 3/3] Restructuring complete. Updated makefile. --- .gitignore | 5 +- Makefile | 107 ++++++++++++---------- build.sh | 36 -------- tests/cMaponiA3_test_3x3_3.cpp | 53 +++++++++++ tests/fMaponiA3_test_3x3_3.f90 | 59 +++++++++++++ tests/fMaponiA3_test_4x4_2.f90 | 151 ++++++++++++++++++++++++++++++++ tests/{test.cpp => test_h5.cpp} | 0 7 files changed, 323 insertions(+), 88 deletions(-) delete mode 100755 build.sh create mode 100644 tests/cMaponiA3_test_3x3_3.cpp create mode 100644 tests/fMaponiA3_test_3x3_3.f90 create mode 100644 tests/fMaponiA3_test_4x4_2.f90 rename tests/{test.cpp => test_h5.cpp} (100%) diff --git a/.gitignore b/.gitignore index 970fc12..ef95009 100644 --- a/.gitignore +++ b/.gitignore @@ -1,10 +1,7 @@ *.o *.mod .vscode -cMaponiA3_test* -fMaponiA3_test* -QMCChem_dataset_test Slater* Updates* -tests/test datasets/datasets.* +bin/ diff --git a/Makefile b/Makefile index 271570a..147c26e 100644 --- a/Makefile +++ b/Makefile @@ -1,49 +1,36 @@ -SRC_DIR := src -INC_DIR := include -OBJ_DIR := build -BIN_DIR := bin - -## Used compilers +## Compilers ARCH = -xCORE-AVX2 H5CXX = h5c++ CXX = icpc FC = ifort -## Compiler flags & common obs & libs +## Compiler flags H5CXXFLAGS = -O0 -g CXXFLAGS = -O0 -g -traceback FFLAGS = -O0 -g -traceback -INCLUDE = -I$(INC_DIR) + +INCLUDE = -I $(INC_DIR)/ +DEPS_CXX = $(OBJ_DIR)/SM_MaponiA3.o +DEPS_F = $(DEPS_CXX) $(OBJ_DIR)/SM_MaponiA3_mod.o $(OBJ_DIR)/Helpers_mod.o FLIBS = -lstdc++ -## Deps & objs for C++ cMaponiA3_test_3x3_3 -OBJS = $(OBJ_DIR)/SM_MaponiA3.o -cMaponiA3_test_3x3_3OBJ = cMaponiA3_test_3x3_3.o -fMaponiA3_test_3x3_3OBJ = SM_MaponiA3_mod.o fMaponiA3_test_3x3_3.o -fMaponiA3_test_4x4_2OBJ = Helpers_mod.o SM_MaponiA3_mod.o fMaponiA3_test_4x4_2.o -QMCChem_dataset_testOBJ = Helpers_mod.o SM_MaponiA3_mod.o QMCChem_dataset_test.o - - -## Default build target: build everything -all: cMaponiA3_test_3x3_3 fMaponiA3_test_3x3_3 fMaponiA3_test_4x4_2 QMCChem_dataset_test tests/test - - -## Compile recipes for C++ -$(OBJ_DIR)/%.o: $(SRC_DIR)/%.cpp | $(OBJ_DIR) - $(CXX) $(ARCH) $(CXXFLAGS) $(INCLUDE) -c -o $@ $< - -## Compile recepies for Fortran -$(OBJ_DIR)/%.o: $(SRC_DIR)/%.f90 | $(OBJ_DIR) - $(FC) $(ARCH) $(FFLAGS) -c -o $@ $< - -## Explicit recipe to trigger rebuild and relinking when headerfile is changed -$(OBJ_DIR)/SM_MaponiA3.o: $(SRC_DIR)/SM_MaponiA3.cpp $(INC_DIR)/Helpers.hpp| $(OBJ_DIR) - $(CXX) $(ARCH) $(CXXFLAGS) $(INCLUDE) -fPIC -c -o $@ $< +SRC_DIR := src +TST_DIR := tests +INC_DIR := include +OBJ_DIR := build +BIN_DIR := bin +EXEC := $(BIN_DIR)/cMaponiA3_test_3x3_3 \ + $(BIN_DIR)/test_h5 \ + $(BIN_DIR)/fMaponiA3_test_3x3_3 \ + $(BIN_DIR)/fMaponiA3_test_4x4_2 \ + $(BIN_DIR)/QMCChem_dataset_test ## Build tagets .PHONY: all clean distclean +all: $(EXEC) + clean: @rm -vrf $(OBJ_DIR) @@ -52,22 +39,46 @@ distclean: clean Slater* Updates.dat -## Linking the C++ example program -$(BIN_DIR)/cMaponiA3_test_3x3_3: $(OBJ_DIR)/$(cMaponiA3_test_3x3_3OBJ) $(OBJS) | $(BIN_DIR) - $(CXX) $(ARCH) $(CXXFLAGS) $(INCLUDE) -o $@ $^ - -## Linking Fortran example program calling the C++ function -$(BIN_DIR)/fMaponiA3_test_3x3_3: $(OBJ_DIR)/$(fMaponiA3_test_3x3_3OBJ) $(OBJS) | $(BIN_DIR) - $(FC) $(ARCH) $(FFLAGS) $(FLIBS) -o $@ $^ - -$(BIN_DIR)/fMaponiA3_test_4x4_2: $(OBJ_DIR)/$(fMaponiA3_test_4x4_2OBJ) $(OBJS) | $(BIN_DIR) - $(FC) $(ARCH) $(FFLAGS) $(FLIBS) -o $@ $^ - -$(BIN_DIR)/QMCChem_dataset_test: $(OBJ_DIR)/$(QMCChem_dataset_testOBJ) $(OBJS) | $(BIN_DIR) - $(FC) $(ARCH) $(FFLAGS) $(FLIBS) -o $@ $^ - -$(BIN_DIR)/test: $(SRC_DIR)/test.cpp $(OBJS) | $(BIN_DIR) - $(H5CXX) $(H5CXXFLAGS) $(INCLUDE) -o $@ $^ - +#### COMPILING $(BIN_DIR) $(OBJ_DIR): mkdir -p $@ + +### IMPLICIT BUILD RULES +## C++ objects +$(OBJ_DIR)/%.o: $(TST_DIR)/%.cpp $(INC_DIR)/* | $(OBJ_DIR) + $(CXX) $(CXXFLAGS) $(ARCH) $(INCLUDE) -c -o $@ $< + +## HDF5/C++ objects +$(OBJ_DIR)/%_h5.o: $(TST_DIR)/%_h5.cpp $(INC_DIR)/* | $(OBJ_DIR) + $(H5CXX) $(H5CXXFLAGS) $(INCLUDE) -c -o $@ $< + +## Fortran modules +$(OBJ_DIR)/%_mod.o: $(SRC_DIR)/%_mod.f90 | $(OBJ_DIR) + $(FC) $(FFLAGS) $(ARCH) -module $(OBJ_DIR)/ -c -o $@ $< + +## Fortran objects +$(OBJ_DIR)/%.o: $(TST_DIR)/%.f90 | $(OBJ_DIR) + $(FC) $(FFLAGS) $(ARCH) -I $(OBJ_DIR)/ -c -o $@ $< + +### EXPLICIT BUILD RULES +## special compiler flag -fPIC otherwise h5c++ builds fail +$(OBJ_DIR)/SM_MaponiA3.o: $(SRC_DIR)/SM_MaponiA3.cpp $(INC_DIR)/* | $(OBJ_DIR) + $(CXX) $(CXXFLAGS) -fPIC $(ARCH) $(INCLUDE) -c -o $@ $< + + + +#### LINKING +$(BIN_DIR)/cMaponiA3_test_3x3_3: $(OBJ_DIR)/cMaponiA3_test_3x3_3.o $(DEPS_CXX) | $(BIN_DIR) + $(CXX) -o $@ $^ + +$(BIN_DIR)/test_h5: $(OBJ_DIR)/test_h5.o $(DEPS_CXX) | $(BIN_DIR) + $(H5CXX) -o $@ $^ + +$(BIN_DIR)/fMaponiA3_test_3x3_3: $(DEPS_F) $(OBJ_DIR)/fMaponiA3_test_3x3_3.o | $(BIN_DIR) + $(FC) $(FLIBS) -o $@ $^ + +$(BIN_DIR)/fMaponiA3_test_4x4_2: $(DEPS_F) $(OBJ_DIR)/fMaponiA3_test_4x4_2.o | $(BIN_DIR) + $(FC) $(FLIBS) -o $@ $^ + +$(BIN_DIR)/QMCChem_dataset_test: $(DEPS_F) $(OBJ_DIR)/QMCChem_dataset_test.o | $(BIN_DIR) + $(FC) $(FLIBS) -o $@ $^ diff --git a/build.sh b/build.sh deleted file mode 100755 index f4c7e12..0000000 --- a/build.sh +++ /dev/null @@ -1,36 +0,0 @@ - - -mkdir build/ bin/ - -## compile tests/test.cpp -icpc -O0 -fPIC -c src/SM_MaponiA3.cpp -o build/SM_MaponiA3.o -I include/ - -## compile tests/fMaponiA3_test_3x3_3.f90 -ifort -c src/SM_MaponiA3_mod.f90 -o build/SM_MaponiA3_mod.o -module build -ifort -c tests/fMaponiA3_test_3x3_3.f90 -o build/fMaponiA3_test_3x3_3.o -I build/ -## link bin/QMCChem_dataset_test -ifort -o bin/fMaponiA3_test_3x3_3 build/fMaponiA3_test_3x3_3.o build/SM_MaponiA3_mod.o build/SM_MaponiA3.o -lstdc++ - -## compile tests/fMaponiA3_test_4x4_2.f90 -ifort -c src/SM_MaponiA3_mod.f90 -o build/SM_MaponiA3_mod.o -module build -ifort -c src/Helpers_mod.f90 -o build/Helpers_mod.o -module build -ifort -c tests/fMaponiA3_test_4x4_2.f90 -o build/fMaponiA3_test_4x4_2.o -I build/ -## link bin/QMCChem_dataset_test -ifort -o bin/fMaponiA3_test_4x4_2 build/fMaponiA3_test_4x4_2.o build/SM_MaponiA3_mod.o build/Helpers_mod.o build/SM_MaponiA3.o -lstdc++ - -## compile tests/QMCChem_dataset_test.f90 -ifort -c src/SM_MaponiA3_mod.f90 -o build/SM_MaponiA3_mod.o -module build -ifort -c src/Helpers_mod.f90 -o build/Helpers_mod.o -module build -ifort -c tests/QMCChem_dataset_test.f90 -o build/QMCChem_dataset_test.o -I build/ -## link bin/QMCChem_dataset_test -ifort -o bin/QMCChem_dataset_test build/QMCChem_dataset_test.o build/SM_MaponiA3_mod.o build/Helpers_mod.o build/SM_MaponiA3.o -lstdc++ - -## compile tests/test.cpp -h5c++ -c tests/test.cpp -o build/test.o -I include/ -## link bin/test -h5c++ -o bin/test build/test.o build/SM_MaponiA3.o - -## compile tests/cMaponiA3_test_3x3_3.cpp -icpc -c tests/cMaponiA3_test_3x3_3.cpp -o build/cMaponiA3_test_3x3_3.o -I include/ -## link bin/cMaponiA3_test_3x3_3 -icpc -o bin/cMaponiA3_test_3x3_3 build/cMaponiA3_test_3x3_3.o build/SM_MaponiA3.o diff --git a/tests/cMaponiA3_test_3x3_3.cpp b/tests/cMaponiA3_test_3x3_3.cpp new file mode 100644 index 0000000..525d15d --- /dev/null +++ b/tests/cMaponiA3_test_3x3_3.cpp @@ -0,0 +1,53 @@ +// main.cpp +#include "SM_MaponiA3.hpp" +#include "Helpers.hpp" + +int main() { + + unsigned int M = 3; // Dimension of the Slater-matrix + unsigned int i, j; // Indices for iterators + + // Declare, allocate all vectors and matrices and fill them with zeros + unsigned int *Ar_index = new unsigned int[M]; + double *A = new double[M*M]; // The matrix to be inverted + double *A0 = new double[M*M]; // A diagonal matrix with the digonal elements of A + double *Ar = new double[M*M]; // The update matrix + double *A0_inv = new double[M*M]; // The inverse + + // Fill with zeros + for (i = 0; i < M; i++) { + for (j = 0; j < M; j++) { + A0[i*M+j] = 0; + Ar[i*M+j] = 0; + A0_inv[i*M+j] = 0; + } + } + + // Initialize A with M=3 and fill acc. to Eq. (17) from paper + A[0] = 1; A[3] = 1; A[6] = -1; + A[1] = 1; A[4] = 1; A[7] = 0; + A[2] = -1; A[5] = 0; A[8] = -1; + + showMatrix(A, M, "A"); + + // Initialize the diagonal matrix A0, + // the inverse of A0_inv of diagonal matrix A0_inv + // and the update matrix Ar + for (i = 0; i < M; i++) { + A0[i*M + i] = A[i*M + i]; + A0_inv[i*M + i] = 1.0/A[i*M + i]; + Ar_index[i] = i+1; // ! First column needs to start with 1 ! + for (j = 0; j < M; j++) { + Ar[i*M + j] = A[i*M + j] - A0[i*M + j]; + } + } + + // Define pointers dim and n_updates to use in Sherman-Morrison(...) function call + MaponiA3(A0_inv, M, M, Ar, Ar_index); + showMatrix(A0_inv, M, "A0_inv"); + + // Deallocate all vectors and matrices + delete [] A, A0, A0_inv, Ar, Ar_index; + + return 0; +} diff --git a/tests/fMaponiA3_test_3x3_3.f90 b/tests/fMaponiA3_test_3x3_3.f90 new file mode 100644 index 0000000..bbc921c --- /dev/null +++ b/tests/fMaponiA3_test_3x3_3.f90 @@ -0,0 +1,59 @@ +program Interface_test + use Sherman_Morrison + implicit none + + integer i, j !! Iterators + integer(c_int) :: Dim, N_updates + integer(c_int), dimension(:), allocatable :: Updates_index + real(c_double), dimension(:,:), allocatable :: A, S, Updates + real(c_double), dimension(:,:), allocatable :: S_inv + + Dim = 3 + N_updates = 3 + allocate(Updates_index(Dim), A(Dim,Dim), S(Dim,Dim), Updates(Dim,Dim), S_inv(Dim,Dim)) + + !! Initialize A with M=3 and fill acc. to Eq. (17) from paper + A(1,1) = 1.0d0 + A(1,2) = 1.0d0 + A(1,3) = -1.0d0 + A(2,1) = 1.0d0 + A(2,2) = 1.0d0 + A(2,3) = 0.0d0 + A(3,1) = -1.0d0 + A(3,2) = 0.0d0 + A(3,3) = -1.0d0 + + do i=1,Dim + do j=1,Dim + write(*,"(F3.0,3X)", advance="no") A(i,j) + end do + write(*,*) + end do + write(*,*) + + !! Prepare the diagonal matrix S and the update matrix Updates + do i=1,Dim + Updates_index(i) = i + do j=1,Dim + if (i == j) then + S(i,j) = A(i,j) + S_inv(i,j) = 1.0d0 / S(i,j) + else + S(i,j) = 0.0d0 + S_inv(i,j) = 0.0d0 + end if + Updates(i,j) = A(i,j) - S(i,j) + end do + end do + + call MaponiA3(S_inv, Dim, N_updates, Updates, Updates_index) + + do i=1,Dim + do j=1,Dim + write(*,"(F3.0,3X)", advance="no") S_inv(i,j) + end do + write(*,*) + end do + + deallocate(Updates_index, A, S, Updates, S_inv) +end program diff --git a/tests/fMaponiA3_test_4x4_2.f90 b/tests/fMaponiA3_test_4x4_2.f90 new file mode 100644 index 0000000..863b87b --- /dev/null +++ b/tests/fMaponiA3_test_4x4_2.f90 @@ -0,0 +1,151 @@ +program Interface_test + use Sherman_Morrison + use Helpers + implicit none + + integer i, j, col !! Iterators + integer(c_int) :: Dim, N_updates + integer(c_int), dimension(:), allocatable :: Updates_index + real(c_double), dimension(:,:), allocatable :: S, A, Updates + real(c_double), dimension(:,:), allocatable :: S_inv, S_inv_t, A_inv + + Dim = 4 + N_updates = 2 + allocate( S(Dim,Dim), S_inv(Dim,Dim), S_inv_t(Dim,Dim), A(Dim,Dim), A_inv(Dim,Dim), & + Updates(Dim,N_updates), Updates_index(N_updates)) + + !! Initialize S, S_inv, A and A_inv + S(1,1) = 1.0d0 + S(1,2) = 0.0d0 + S(1,3) = 1.0d0 + S(1,4) = -1.0d0 + S(2,1) = 0.0d0 + S(2,2) = 1.0d0 + S(2,3) = 1.0d0 + S(2,4) = 0.0d0 + S(3,1) = -1.0d0 + S(3,2) = 0.0d0 + S(3,3) = -1.0d0 + S(3,4) = 0.0d0 + S(4,1) = 1.0d0 + S(4,2) = 1.0d0 + S(4,3) = 1.0d0 + S(4,4) = 1.0d0 + + S_inv(1,1) = 1.0d0 + S_inv(1,2) = -1.0d0 + S_inv(1,3) = 1.0d0 + S_inv(1,4) = 1.0d0 + S_inv(2,1) = 1.0d0 + S_inv(2,2) = 0.0d0 + S_inv(2,3) = 2.0d0 + S_inv(2,4) = 1.0d0 + S_inv(3,1) = -1.0d0 + S_inv(3,2) = 1.0d0 + S_inv(3,3) = -2.0d0 + S_inv(3,4) = -1.0d0 + S_inv(4,1) = -1.0d0 + S_inv(4,2) = 0.0d0 + S_inv(4,3) = -1.0d0 + S_inv(4,4) = 0.0d0 + + A(1,1) = 1.0d0 + A(1,2) = 0.0d0 + A(1,3) = 1.0d0 + A(1,4) = -1.0d0 + A(2,1) = 0.0d0 + A(2,2) = -1.0d0 + A(2,3) = 1.0d0 + A(2,4) = -1.0d0 + A(3,1) = -1.0d0 + A(3,2) = 0.0d0 + A(3,3) = -1.0d0 + A(3,4) = 0.0d0 + A(4,1) = 1.0d0 + A(4,2) = 1.0d0 + A(4,3) = 1.0d0 + A(4,4) = 1.0d0 + + A_inv(1,1) = 0.0d0 + A_inv(1,2) = -1.0d0 + A_inv(1,3) = -2.0d0 + A_inv(1,4) = -1.0d0 + A_inv(2,1) = 1.0d0 + A_inv(2,2) = 0.0d0 + A_inv(2,3) = 2.0d0 + A_inv(2,4) = 1.0d0 + A_inv(3,1) = 0.0d0 + A_inv(3,2) = 1.0d0 + A_inv(3,3) = 1.0d0 + A_inv(3,4) = 1.0d0 + A_inv(4,1) = -1.0d0 + A_inv(4,2) = 0.0d0 + A_inv(4,3) = -1.0d0 + A_inv(4,4) = 0.0d0 + + !! Prepare Updates and Updates_index + Updates(1,1) = 0 + Updates(1,2) = 0 + Updates(2,1) = -2 + Updates(2,2) = -1 + Updates(3,1) = 0 + Updates(3,2) = 0 + Updates(4,1) = 0 + Updates(4,2) = 0 + + Updates_index(1) = 2 + Updates_index(2) = 4 + + !! Write current S and S_inv to file for check in Octave + open(unit = 2000, file = "Slater_old.dat") + open(unit = 3000, file = "Slater_old_inv.dat") + do i=1,dim + do j=1,dim + write(2000,"(E23.15, 1X)", advance="no") S(i,j) + write(3000,"(E23.15, 1X)", advance="no") S_inv(i,j) + end do + write(2000,*) + write(3000,*) + end do + close(2000) + close(3000) + + !! Write Updates to file to check + open(unit = 2000, file = "Updates.dat") + do i=1,dim + do j=1,n_updates + write(2000,"(E23.15, 1X)", advance="no") Updates(i,j) + end do + write(2000,*) + end do + close(2000) + + !! Update S + do i=1,N_updates + do j=1,Dim + col = Updates_index(i) + S(j,col) = S(j,col) + Updates(j,i) + end do + end do + + !! Update S_inv + call Transpose(S_inv, S_inv_t, Dim) + call MaponiA3(S_inv_t, Dim, N_updates, Updates, Updates_index) + call Transpose(S_inv_t, S_inv, Dim) + + !! Write new S and S_inv to file for check in Octave + open(unit = 4000, file = "Slater.dat") + open(unit = 5000, file = "Slater_inv.dat") + do i=1,dim + do j=1,dim + write(4000,"(E23.15, 1X)", advance="no") S(i,j) + write(5000,"(E23.15, 1X)", advance="no") S_inv(i,j) + end do + write(4000,*) + write(5000,*) + end do + close(4000) + close(5000) + + deallocate(Updates_index, A, A_inv, S, Updates, S_inv) +end program diff --git a/tests/test.cpp b/tests/test_h5.cpp similarity index 100% rename from tests/test.cpp rename to tests/test_h5.cpp