mirror of
https://github.com/TREX-CoE/Sherman-Morrison.git
synced 2024-12-25 22:03:57 +01:00
Prepared the main Fortran infrastructure for the C++ calls. Updated the makefile.
This commit is contained in:
parent
5531d9eb12
commit
090847247d
5
.gitignore
vendored
5
.gitignore
vendored
@ -1,4 +1,5 @@
|
|||||||
*.o
|
*.o
|
||||||
SM-MaponiA3
|
*.mod
|
||||||
Sherman-Morrison
|
cppSherman-Morrison
|
||||||
|
fSherman-Morrison
|
||||||
.vscode
|
.vscode
|
31
Makefile
31
Makefile
@ -1,17 +1,30 @@
|
|||||||
CC=icc
|
|
||||||
CXX=icpc
|
CXX=icpc
|
||||||
CFLAGS=-O0 -debug full
|
|
||||||
CXXFLAGS=-O0 -debug full -traceback
|
CXXFLAGS=-O0 -debug full -traceback
|
||||||
|
FC=ifort
|
||||||
|
FFLAGS=-O0 -debug full -traceback
|
||||||
# ARCH=-xCORE-AVX2
|
# ARCH=-xCORE-AVX2
|
||||||
|
|
||||||
DEPS = SM-MaponiA3.cpp
|
## Deps & objs for the C++ stuff
|
||||||
OBJ = SM-MaponiA3.o main.o
|
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
|
||||||
|
|
||||||
%.o: %.cpp $(DEPS)
|
%.o: %.cpp $(cppDEPS)
|
||||||
$(CXX) $(ARCH) -c -o $@ $< $(CFLAGS)
|
$(CXX) $(ARCH) $(CXXFLAGS) -c -o $@ $<
|
||||||
|
|
||||||
Sherman-Morrison: $(OBJ)
|
%.o: %.f90 $(fDEPS)
|
||||||
$(CXX) $(ARCH) -o $@ $^ $(CFLAGS)
|
$(FC) $(ARCH) $(FFLAGS) -c -o $@ $<
|
||||||
|
|
||||||
|
all: cppSherman-Morrison fSherman-Morrison
|
||||||
|
|
||||||
|
cppSherman-Morrison: $(cppOBJ)
|
||||||
|
$(CXX) $(ARCH) $(CXXFLAGS) -o $@ $^
|
||||||
|
|
||||||
|
fSherman-Morrison: $(fOBJ)
|
||||||
|
$(FC) $(ARCH) $(FFLAGS) -o $@ $^
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
@rm -vf *.o
|
@rm -vf *.o *.mod
|
||||||
|
|
@ -1,3 +0,0 @@
|
|||||||
// SM-MaponiA3.hpp
|
|
||||||
|
|
||||||
void Sherman_Morrison(int **Slater0, double **Slater_inv, unsigned int *Dim, unsigned int *N_updates, int **Updates, unsigned int *Updates_index);
|
|
@ -1,10 +1,10 @@
|
|||||||
// SM-MaponiA3.cpp
|
// SM-MaponiA3.cpp
|
||||||
// Algorithm 3 from P. Maponi,
|
// Algorithm 3 from P. Maponi,
|
||||||
// p. 283, doi:10.1016/j.laa.2006.07.007
|
// p. 283, doi:10.1016/j.laa.2006.07.007
|
||||||
#include "SM-MaponiA3.hpp"
|
#include "SM_MaponiA3.hpp"
|
||||||
#include "Helpers.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 k, l, lbar, i, j, tmp, M = *Dim;
|
||||||
unsigned int *p = new unsigned int[M+1];
|
unsigned int *p = new unsigned int[M+1];
|
||||||
unsigned int **Id = new unsigned int*[M];
|
unsigned int **Id = new unsigned int*[M];
|
5
SM_MaponiA3.hpp
Normal file
5
SM_MaponiA3.hpp
Normal file
@ -0,0 +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);
|
||||||
|
}
|
11
SM_MaponiA3_mod.f90
Normal file
11
SM_MaponiA3_mod.f90
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
module MYMODULE
|
||||||
|
interface
|
||||||
|
subroutine MYSUBROUTINE(Slater0, Slater_inv, dim, n_updates, Updates, Updates_index) bind(C, name="Sherman_Morrison")
|
||||||
|
use, intrinsic :: iso_c_binding, only : c_int, c_double
|
||||||
|
integer(c_int), intent(in) :: dim, n_updates
|
||||||
|
integer(c_int), dimension(:), allocatable, intent(in) :: Updates_index
|
||||||
|
integer(c_int), dimension(:,:), allocatable, intent(in) :: Slater0, Updates
|
||||||
|
real(c_double), dimension(:,:), allocatable, intent(in out) :: Slater_inv
|
||||||
|
end subroutine MYSUBROUTINE
|
||||||
|
end interface
|
||||||
|
end module MYMODULE
|
@ -1,5 +1,5 @@
|
|||||||
// main.cpp
|
// main.cpp
|
||||||
#include "SM-MaponiA3.hpp"
|
#include "SM_MaponiA3.hpp"
|
||||||
#include "Helpers.hpp"
|
#include "Helpers.hpp"
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <ctime>
|
#include <ctime>
|
||||||
@ -65,7 +65,7 @@ int main() {
|
|||||||
// Define pointers dim and n_updates to use in Sherman-Morrison(...) function call
|
// Define pointers dim and n_updates to use in Sherman-Morrison(...) function call
|
||||||
unsigned int *dim = new unsigned int(M);
|
unsigned int *dim = new unsigned int(M);
|
||||||
unsigned int *n_updates = 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");
|
showMatrix(A0_inv, M, "A0_inv");
|
||||||
|
|
||||||
// Deallocate all vectors and matrices
|
// Deallocate all vectors and matrices
|
35
fmain.f90
Normal file
35
fmain.f90
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
program Interface_test
|
||||||
|
use, intrinsic :: iso_c_binding, only : c_int, c_double
|
||||||
|
use MYMODULE, only : MYSUBROUTINE
|
||||||
|
implicit none
|
||||||
|
|
||||||
|
integer i, j !! Iterators
|
||||||
|
integer(c_int) :: dim, N_updates
|
||||||
|
integer(c_int), dimension(:), allocatable :: Ar_index
|
||||||
|
integer(c_int), dimension(:,:), allocatable :: A, A0, Ar
|
||||||
|
real(c_double), dimension(:,:), allocatable :: A0_inv
|
||||||
|
|
||||||
|
dim = 3
|
||||||
|
N_updates = dim
|
||||||
|
allocate(Ar_index(dim), A(dim,dim), A0(dim,dim), Ar(dim,dim), A0_inv(dim,dim))
|
||||||
|
|
||||||
|
!! Initialize A with M=3 and fill acc. to Eq. (17) from paper
|
||||||
|
A(1,1) = 1
|
||||||
|
A(1,2) = 1
|
||||||
|
A(1,3) = -1
|
||||||
|
A(2,1) = 1
|
||||||
|
A(2,2) = 1
|
||||||
|
A(2,3) = 0
|
||||||
|
A(3,1) = -1
|
||||||
|
A(3,2) = 0
|
||||||
|
A(3,3) = -1
|
||||||
|
|
||||||
|
do i=1,3
|
||||||
|
do j=1,3
|
||||||
|
write(*,"(I)", advance="no") A(i,j)
|
||||||
|
end do
|
||||||
|
write(*,*)
|
||||||
|
end do
|
||||||
|
|
||||||
|
deallocate(Ar_index, A, A0, Ar, A0_inv)
|
||||||
|
end program
|
Loading…
Reference in New Issue
Block a user