diff --git a/Makefile b/Makefile index b7182d2..cf37720 100644 --- a/Makefile +++ b/Makefile @@ -7,24 +7,33 @@ FFLAGS=-O0 -debug full -traceback ## 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 the Fortran stuff fDEPS = fmain.f90 SM_MaponiA3_mod.f90 -fOBJ = SM_MaponiA3_mod.o fmain.o +fOBJ = SM_MaponiA3.o SM_MaponiA3_mod.o fmain.o +## Compile recipes for C++ stuff %.o: %.cpp $(cppDEPS) $(CXX) $(ARCH) $(CXXFLAGS) -c -o $@ $< +## Compile recepies for Fortran stuff %.o: %.f90 $(fDEPS) $(FC) $(ARCH) $(FFLAGS) -c -o $@ $< +.PHONY: all clean distclean + all: cppSherman-Morrison fSherman-Morrison -cppSherman-Morrison: $(cppOBJ) - $(CXX) $(ARCH) $(CXXFLAGS) -o $@ $^ - -fSherman-Morrison: $(fOBJ) - $(FC) $(ARCH) $(FFLAGS) -o $@ $^ - clean: @rm -vf *.o *.mod - \ No newline at end of file + +distclean: clean + @rm -vf cppSherman-Morrison fSherman-Morrison + +## Linking the C++ example program +cppSherman-Morrison: $(cppOBJ) + $(CXX) $(ARCH) $(CXXFLAGS) -o $@ $^ + +## Linking Fortran example program calling the C++ function 'Sherman_Morrison()' +fSherman-Morrison: $(fOBJ) + $(FC) $(ARCH) $(FFLAGS) -o $@ $^ diff --git a/SM_MaponiA3.cpp b/SM_MaponiA3.cpp index a652fe2..9fc477c 100644 --- a/SM_MaponiA3.cpp +++ b/SM_MaponiA3.cpp @@ -4,7 +4,7 @@ #include "SM_MaponiA3.hpp" #include "Helpers.hpp" -void Sherman_Morrison_(int **Slater0, double **Slater_inv, unsigned int *Dim, unsigned int *N_updates, int **Updates, unsigned int *Updates_index) { +void Sherman_Morrison(int **Slater0, double **Slater_inv, unsigned int *Dim, unsigned int *N_updates, int **Updates, unsigned int *Updates_index) { unsigned int k, l, lbar, i, j, tmp, M = *Dim; unsigned int *p = new unsigned int[M+1]; unsigned int **Id = new unsigned int*[M]; diff --git a/SM_MaponiA3.hpp b/SM_MaponiA3.hpp index 065d662..0a53741 100644 --- a/SM_MaponiA3.hpp +++ b/SM_MaponiA3.hpp @@ -1,5 +1,5 @@ // SM-MaponiA3.hpp - extern "C" { - void Sherman_Morrison_(int **Slater0, double **Slater_inv, unsigned int *Dim, unsigned int *N_updates, int **Updates, unsigned int *Updates_index); -} \ No newline at end of file + void Sherman_Morrison(int **Slater0, double **Slater_inv, unsigned int *Dim, unsigned int *N_updates, int **Updates, unsigned int *Updates_index); +} + diff --git a/cppmain.cpp b/cppmain.cpp index 79671a5..2592370 100644 --- a/cppmain.cpp +++ b/cppmain.cpp @@ -65,7 +65,7 @@ int main() { // Define pointers dim and n_updates to use in Sherman-Morrison(...) function call unsigned int *dim = new unsigned int(M); unsigned int *n_updates = new unsigned int(M); - Sherman_Morrison_(A0, A0_inv, dim, n_updates, Ar, Ar_index); + Sherman_Morrison(A0, A0_inv, dim, n_updates, Ar, Ar_index); showMatrix(A0_inv, M, "A0_inv"); // Deallocate all vectors and matrices diff --git a/fmain.f90 b/fmain.f90 index 44a2a53..fe6447f 100644 --- a/fmain.f90 +++ b/fmain.f90 @@ -24,12 +24,29 @@ program Interface_test A(3,2) = 0 A(3,3) = -1 - do i=1,3 - do j=1,3 - write(*,"(I)", advance="no") A(i,j) + !! Prepare the diagonal matrix A0 and the update matrix Ar + do i=1,dim + Ar_index(i) = i + do j=1,dim + if (i == j) then + A0(i,j) = A(i,j) + A0_inv(i,j) = 1.0d0 / A0(i,j) + else + A0(i,j) = 0 + A0_inv(i,j) = 0.0d0 + end if + Ar(i,j) = A(i,j) - A0(i,j) end do - write(*,*) end do + ! do i=1,dim + ! do j=1,dim + ! write(*,"(I)", advance="no") Ar_index(i) + ! end do + ! write(*,*) + ! end do + + call MYSUBROUTINE(A0, A0_inv, dim, n_updates, Ar, Ar_index) + deallocate(Ar_index, A, A0, Ar, A0_inv) end program