Skip to content

Commit

Permalink
mmap is now shared in cholesky
Browse files Browse the repository at this point in the history
  • Loading branch information
scemama committed Jun 20, 2024
1 parent c6712b0 commit 4b578d9
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 16 deletions.
36 changes: 20 additions & 16 deletions src/ao_two_e_ints/cholesky.irp.f
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,11 @@
integer*8 :: ndim8
integer :: rank
double precision :: tau, tau2
double precision, pointer :: L(:,:), Delta(:,:)
double precision, pointer :: L(:,:)

double precision :: s
double precision :: dscale, dscale_tmp

double precision, allocatable :: D(:), Ltmp_p(:,:), Ltmp_q(:,:), D_sorted(:), Delta_col(:)
double precision, allocatable :: D(:), Ltmp_p(:,:), Ltmp_q(:,:), D_sorted(:), Delta_col(:), Delta(:,:)
integer, allocatable :: addr1(:), addr2(:)
integer*8, allocatable :: Lset(:), Dset(:)
logical, allocatable :: computed(:)
Expand Down Expand Up @@ -102,7 +101,7 @@
rank = 0

allocate( D(ndim8), Lset(ndim8), Dset(ndim8), D_sorted(ndim8))
allocate( addr1(ndim8), addr2(ndim8), Delta_col(ndim8) )
allocate( addr1(ndim8), addr2(ndim8), Delta_col(ndim8), computed(ndim8) )

call resident_memory(mem0)

Expand Down Expand Up @@ -149,11 +148,9 @@
Dmax = D_sorted(1)

! 2.
dscale = 1.d0
dscale_tmp = dscale*dscale*Dmax
np8=0_8
do p8=1,ndim8
if ( dscale_tmp*D(p8) >= tau2 ) then
if ( Dmax*D(p8) >= tau2 ) then
np8 = np8+1_8
Lset(np8) = p8
endif
Expand Down Expand Up @@ -203,16 +200,23 @@

mem = mem0 &
+ np*memory_of_double(nq) & ! Delta(np,nq)
+ (np+nq)*memory_of_double(block_size) & ! Ltmp_p(np,block_size) + Ltmp_q(nq,block_size)
+ memory_of_int(nq) ! computed(nq)
+ (np+nq)*memory_of_double(block_size) ! Ltmp_p(np,block_size) + Ltmp_q(nq,block_size)

if (mem > qp_max_mem*0.5d0) then
nq = nq/2
Dmin = D_sorted(nq/2)
do ii=nq/2,np-1
if (D_sorted(ii) < Dmin) then
nq = ii
exit
endif
enddo
else
exit
endif

enddo
!call print_memory_usage
!print *, 'np, nq, Predicted memory: ', np, nq, mem

if (nq <= 0) then
print *, nq
Expand Down Expand Up @@ -247,8 +251,7 @@
endif


allocate(computed(nq))
computed(:) = .False.
computed(1:nq) = .False.


!$OMP PARALLEL DEFAULT(SHARED) PRIVATE(k,p,q)
Expand Down Expand Up @@ -406,7 +409,6 @@

deallocate(Ltmp_p)
deallocate(Ltmp_q)
deallocate(computed)
deallocate(Delta)

! i.
Expand All @@ -419,11 +421,9 @@

Dmax = D_sorted(1)

dscale = 1.d0
dscale_tmp = dscale*dscale*Dmax
np8=0_8
do p8=1,ndim8
if ( dscale_tmp*D(p8) >= tau2 ) then
if ( Dmax*D(p8) >= tau2 ) then
np8 = np8+1_8
Lset(np8) = p8
endif
Expand All @@ -436,6 +436,10 @@
print *, '============ ============='
print *, ''

deallocate( D, Lset, Dset, D_sorted )
deallocate( addr1, addr2, Delta_col, computed )


allocate(cholesky_ao(ao_num,ao_num,rank), stat=ierr)

if (ierr /= 0) then
Expand Down
3 changes: 3 additions & 0 deletions src/utils/fortran_mmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,13 @@ void* mmap_fortran(char* filename, size_t bytes, int* file_descr, int read_only,
}

if (single_node == 1) {
map = mmap(NULL, bytes, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
/*
map = mmap(NULL, bytes, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_POPULATE | MAP_NONBLOCK | MAP_NORESERVE, fd, 0);
if (map == MAP_FAILED) {
map = mmap(NULL, bytes, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0);
}
*/
} else {
map = mmap(NULL, bytes, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
}
Expand Down

0 comments on commit 4b578d9

Please sign in to comment.