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