From 1b3a1d9d2282f0317a12d9430fbdecc522a10aba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Coppens?= Date: Fri, 12 Feb 2021 12:04:21 +0100 Subject: [PATCH] Added QMCChem test dataset with 3 updates. Renamed files, added the Fortran program QMCChem_dataset_test.f90 to start testing the QMCChem dataset. Wrote and tested Fortran code to import the test dataset. --- .gitignore | 8 ++++-- Makefile | 41 +++++++++++++++----------- QMCChem_dataset_test.f90 | 48 +++++++++++++++++++++++++++++++ SM_MaponiA3.cpp | 13 +++++---- Utils_mod.f90 | 44 ++++++++++++++++++++++++++++ cppmain.cpp => cMaponiA3_test.cpp | 0 fmain.f90 => fMaponiA3_test.f90 | 0 7 files changed, 129 insertions(+), 25 deletions(-) create mode 100644 QMCChem_dataset_test.f90 create mode 100644 Utils_mod.f90 rename cppmain.cpp => cMaponiA3_test.cpp (100%) rename fmain.f90 => fMaponiA3_test.f90 (100%) diff --git a/.gitignore b/.gitignore index 65d0183..d36ee77 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,7 @@ *.o *.mod -cppSherman-Morrison -fSherman-Morrison -.vscode \ No newline at end of file +.vscode +cMaponiA3_test +fMaponiA3_test +QMCChem_dataset_test + diff --git a/Makefile b/Makefile index e913743..b60d165 100644 --- a/Makefile +++ b/Makefile @@ -7,38 +7,47 @@ CXXFLAGS = -O0 #-debug full -traceback FFLAGS = -O0 #-debug full -traceback # ARCH = -xCORE-AVX2 -## Deps & objs for the C++ stuff -cppDEPS = cppmain.cpp SM_MaponiA3.cpp SM_MaponiA3.hpp Helpers.hpp -cppOBJ = cppmain.o SM_MaponiA3.o +## Deps & objs for C++ cMaponiA3_test +cMaponiA3_testDEP = cMaponiA3_test.cpp SM_MaponiA3.cpp SM_MaponiA3.hpp Helpers.hpp +cMaponiA3_testOBJ = cMaponiA3_test.o SM_MaponiA3.o -## Deps & objs for the Fortran stuff -fDEPS = fmain.f90 SM_MaponiA3_mod.f90 -fOBJ = SM_MaponiA3.o SM_MaponiA3_mod.o fmain.o -fLIBS = -lstdc++ +## Deps & objs for Fortran fMaponiA3_test +fMaponiA3_testDEP = fMaponiA3_test.f90 SM_MaponiA3_mod.f90 +fMaponiA3_testOBJ = SM_MaponiA3.o SM_MaponiA3_mod.o fMaponiA3_test.o +fMaponiA3_testLIB = -lstdc++ -## Compile recipes for C++ stuff -%.o: %.cpp $(cppDEPS) +## Deps & objs for Fortran QMCChem_dataset_test +QMCChem_dataset_testDEP = QMCChem_dataset_test.f90 SM_MaponiA3_mod.f90 +QMCChem_dataset_testOBJ = SM_MaponiA3.o SM_MaponiA3_mod.o QMCChem_dataset_test.o +QMCChem_dataset_testLIB = -lstdc++ + +## Compile recipes for C++ cMaponiA3_test +%.o: %.cpp $(cMaponiA3_testDEP) $(CXX) $(ARCH) $(CXXFLAGS) -c -o $@ $< -## Compile recepies for Fortran stuff -%.o: %.f90 $(fDEPS) +## Compile recepies for Fortran fMaponiA3_test +%.o: %.f90 $(fMaponiA3_testDEP) $(FC) $(ARCH) $(FFLAGS) -c -o $@ $< ## Build tagets .PHONY: all clean distclean -all: cppSherman-Morrison fSherman-Morrison +all: cMaponiA3_test fMaponiA3_test QMCChem_dataset_test clean: @rm -vf *.o *.mod distclean: clean - @rm -vf cppSherman-Morrison fSherman-Morrison + @rm -vf cMaponiA3_test fMaponiA3_test QMCChem_dataset_test ## Linking the C++ example program -cppSherman-Morrison: $(cppOBJ) +cMaponiA3_test: $(cMaponiA3_testOBJ) $(CXX) $(ARCH) $(CXXFLAGS) -o $@ $^ ## Linking Fortran example program calling the C++ function 'Sherman_Morrison()' -fSherman-Morrison: $(fOBJ) - $(FC) $(ARCH) $(FFLAGS) $(fLIBS) -o $@ $^ +fMaponiA3_test: $(fMaponiA3_testOBJ) + $(FC) $(ARCH) $(FFLAGS) $(fMaponiA3_testLIB) -o $@ $^ + +## Linking Fortran example program calling the C++ function 'Sherman_Morrison()' +QMCChem_dataset_test: $(QMCChem_dataset_testOBJ) + $(FC) $(ARCH) $(FFLAGS) $(QMCChem_dataset_testLIB) -o $@ $^ diff --git a/QMCChem_dataset_test.f90 b/QMCChem_dataset_test.f90 new file mode 100644 index 0000000..24745f8 --- /dev/null +++ b/QMCChem_dataset_test.f90 @@ -0,0 +1,48 @@ +program QMCChem_dataset_test + use Sherman_Morrison, only : MaponiA3 + use, intrinsic :: iso_c_binding, only : c_int, c_double + implicit none + + integer :: i, j !! Iterators + integer :: cycle_id, dim, n_updates + integer(c_int), dimension(:), allocatable :: Updates_index + real(c_double), dimension(:,:), allocatable :: S, S_inv, Updates + character (len = 32) :: ignore + + !! Start of reading the dataset from file + open(unit = 1000, file = "test.dataset.dat") + read(1000,*) + read(1000,*) ignore, cycle_id + read(1000,*) ignore, dim + read(1000,*) ignore,n_updates + + allocate(Updates_index(n_updates), S(dim,dim), & + S_inv(dim,dim), Updates(dim,n_updates)) + + !! Read S and S_inv + read(1000,*) + do i=1,dim + do j=1,dim + read(1000,*) ignore, ignore, S(i,j), S_inv(i,j) + end do + end do + + !! Read the updates Updates and Updates_index + do j=1,n_updates + read(1000,*) ignore, Updates_index(j) + do i=1,dim + read(1000,*) ignore, Updates(i,j) + end do + end do + + read(1000,*) ignore + close(1000) + !! End of reading the dataset from file + + !! Send S, S_inv and Updates to MaponiA3 algo + ! + + !! Test if computed S_inv is indeed the inverse of S + + deallocate(S, S_inv, Updates, Updates_index) +end program diff --git a/SM_MaponiA3.cpp b/SM_MaponiA3.cpp index 3a54730..9ffcc3a 100644 --- a/SM_MaponiA3.cpp +++ b/SM_MaponiA3.cpp @@ -92,10 +92,11 @@ void MaponiA3(double *Slater0, double *Slater_inv, unsigned int M, } extern "C" { -void MaponiA3_f(double **linSlater0, double **linSlater_inv, unsigned int *Dim, - unsigned int *N_updates, double **linUpdates, - unsigned int **Updates_index) { - MaponiA3(*linSlater0, *linSlater_inv, *Dim, *N_updates, *linUpdates, - *Updates_index); -} + void MaponiA3_f(double **linSlater0, double **linSlater_inv, unsigned int *Dim, + unsigned int *N_updates, double **linUpdates, + unsigned int **Updates_index) { + MaponiA3(*linSlater0, *linSlater_inv, *Dim, + *N_updates, *linUpdates, + *Updates_index); + } } diff --git a/Utils_mod.f90 b/Utils_mod.f90 new file mode 100644 index 0000000..2f96a26 --- /dev/null +++ b/Utils_mod.f90 @@ -0,0 +1,44 @@ +module Utils + implicit none + + contains + subroutine Read_dataset(filename, cycle_id, dim, n_updates & + S, S_inv, Updates_index, Updates) + + character (len = 64), intent(in) :: filename + + + !! Start of reading the dataset from file + open(unit = 1000, file = "test.dataset.dat") + read(1000,*) + read(1000,*) ignore, cycle_id + read(1000,*) ignore, dim + read(1000,*) ignore,n_updates + + allocate(Updates_index(n_updates), S(dim,dim), & + S_inv(dim,dim), Updates(dim,n_updates)) + + !! Read S and S_inv + read(1000,*) + do i=1,dim + do j=1,dim + read(1000,*) ignore, ignore, S(i,j), S_inv(i,j) + end do + end do + + !! Read the updates Updates and Updates_index + do j=1,n_updates + read(1000,*) ignore, Updates_index(j) + do i=1,dim + read(1000,*) ignore, Updates(i,j) + end do + end do + + read(1000,*) ignore + close(1000) + !! End of reading the dataset from file + end subroutine Read_dataset + end module Utils + + +end module Sherman_Morrison diff --git a/cppmain.cpp b/cMaponiA3_test.cpp similarity index 100% rename from cppmain.cpp rename to cMaponiA3_test.cpp diff --git a/fmain.f90 b/fMaponiA3_test.f90 similarity index 100% rename from fmain.f90 rename to fMaponiA3_test.f90