Skip to content
This repository was archived by the owner on Aug 28, 2024. It is now read-only.

Commit

Permalink
Added deallocate statements to get memory issues under control
Browse files Browse the repository at this point in the history
  • Loading branch information
daminton committed Apr 30, 2023
1 parent 15a0556 commit 22cf767
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 26 deletions.
37 changes: 25 additions & 12 deletions src/coarray/coarray_clone.f90
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ module subroutine coarray_component_clone_char(var,src_img)
sync images(si)
var = tmp[si]
end if
deallocate(tmp)

return
end subroutine coarray_component_clone_char
Expand Down Expand Up @@ -78,6 +79,7 @@ module subroutine coarray_component_clone_DP(var,src_img)
var = tmp[si]
end if

deallocate(tmp)

return
end subroutine coarray_component_clone_DP
Expand Down Expand Up @@ -123,6 +125,7 @@ module subroutine coarray_component_clone_DP_arr1D(var,src_img)
if (allocated(var)) deallocate(var)
allocate(var, source=tmp)
end if
deallocate(isalloc,n,tmp)

return
end subroutine coarray_component_clone_DP_arr1D
Expand Down Expand Up @@ -173,6 +176,8 @@ module subroutine coarray_component_clone_DP_arr2D(var,src_img)
allocate(var, source=tmp)
end if

deallocate(isalloc,n1,n2,tmp)

return
end subroutine coarray_component_clone_DP_arr2D

Expand All @@ -199,10 +204,9 @@ module subroutine coarray_component_clone_DP_vec1D(var,src_img)
end if

allocate(tmp(NDIM)[*])
sync all
if (this_image() == si) then
do img = 1, num_images()
tmp(:)[img] = var(:)
tmp(:)[img] = var(:)
end do
sync images(*)
else
Expand Down Expand Up @@ -257,6 +261,8 @@ module subroutine coarray_component_clone_DP_vec2D(var,src_img)
allocate(var, source=tmp)
end if

deallocate(isalloc,n,tmp)

return
end subroutine coarray_component_clone_DP_vec2D

Expand All @@ -282,17 +288,18 @@ module subroutine coarray_component_clone_I4B(var,src_img)
si = 1
end if

sync all
if (this_image() == si) then
do img = 1, num_images()
tmp[img] = var
tmp[img] = var
end do
sync images(*)
else
sync images(si)
var = tmp[si]
end if

deallocate(tmp)

return
end subroutine coarray_component_clone_I4B

Expand Down Expand Up @@ -328,7 +335,7 @@ module subroutine coarray_component_clone_I4B_arr1D(var,src_img)
allocate(tmp(n[si])[*])
if (this_image() == si) then
do img = 1, num_images()
tmp(:)[img] = var
tmp(:)[img] = var
end do
sync images(*)
else
Expand All @@ -337,6 +344,8 @@ module subroutine coarray_component_clone_I4B_arr1D(var,src_img)
allocate(var, source=tmp)
end if

deallocate(isalloc,n,tmp)

return
end subroutine coarray_component_clone_I4B_arr1D

Expand All @@ -361,17 +370,18 @@ module subroutine coarray_component_clone_I8B(var,src_img)
si = 1
end if

sync all
if (this_image() == si) then
do img = 1, num_images()
tmp[img] = var
tmp[img] = var
end do
sync images(*)
else
sync images(si)
var = tmp[si]
end if

deallocate(tmp)

return
end subroutine coarray_component_clone_I8B

Expand All @@ -397,17 +407,17 @@ module subroutine coarray_component_clone_lgt(var,src_img)
si = 1
end if

sync all
if (this_image() == si) then
do img = 1, num_images()
tmp[img] = var
tmp[img] = var
end do
sync images(*)
else
sync images(si)
var = tmp[si]
end if

deallocate(tmp)

return
end subroutine coarray_component_clone_lgt
Expand Down Expand Up @@ -444,7 +454,7 @@ module subroutine coarray_component_clone_lgt_arr1D(var,src_img)
allocate(tmp(n[si])[*])
if (this_image() == si) then
do img = 1, num_images()
tmp(:)[img] = var
tmp(:)[img] = var
end do
sync images(*)
else
Expand All @@ -453,6 +463,8 @@ module subroutine coarray_component_clone_lgt_arr1D(var,src_img)
allocate(var, source=tmp)
end if

deallocate(isalloc,n,tmp)

return
end subroutine coarray_component_clone_lgt_arr1D

Expand All @@ -477,17 +489,18 @@ module subroutine coarray_component_clone_QP(var,src_img)
si = 1
end if

!sync all
if (this_image() == si) then
do img = 1, num_images()
tmp[img] = var
tmp[img] = var
end do
sync images(*)
else
sync images(si)
var = tmp[si]
end if

deallocate(tmp)

return
end subroutine coarray_component_clone_QP

Expand Down
28 changes: 20 additions & 8 deletions src/coarray/coarray_collect.f90
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,15 @@ module subroutine coarray_component_collect_DP_arr1D(var,dest_img)

if (this_image() == di) then
do img = 1, num_images()
if (img /= di) then
call util_append(var, tmp(1:n[img])[img])
n = n + n[img]
end if
if (img /= di) then
call util_append(var, tmp(1:n[img])[img])
n = n + n[img]
end if
end do
end if

deallocate(isalloc,n,tmp)

return
end subroutine coarray_component_collect_DP_arr1D

Expand Down Expand Up @@ -117,6 +119,8 @@ module subroutine coarray_component_collect_DP_arr2D(var,dest_img)
end do
end if

deallocate(isalloc,n1,n2,tmp)

return
end subroutine coarray_component_collect_DP_arr2D

Expand Down Expand Up @@ -151,6 +155,8 @@ module subroutine coarray_component_collect_I4B(var,dest_img)
var = 0
end if

deallocate(tmp)

return
end subroutine coarray_component_collect_I4B

Expand Down Expand Up @@ -185,6 +191,8 @@ module subroutine coarray_component_collect_I8B(var,dest_img)
var = 0
end if

deallocate(tmp)

return
end subroutine coarray_component_collect_I8B

Expand Down Expand Up @@ -230,13 +238,15 @@ module subroutine coarray_component_collect_I4B_arr1D(var,dest_img)

if (this_image() == di) then
do img = 1, num_images()
if (img /= di) then
call util_append(var, tmp(1:n[img])[img])
n = n + n[img]
end if
if (img /= di) then
call util_append(var, tmp(1:n[img])[img])
n = n + n[img]
end if
end do
end if

deallocate(isalloc,n,tmp)

return
end subroutine coarray_component_collect_I4B_arr1D

Expand Down Expand Up @@ -289,6 +299,8 @@ module subroutine coarray_component_collect_lgt_arr1D(var,dest_img)
end do
end if

deallocate(isalloc,n,tmp)

return
end subroutine coarray_component_collect_lgt_arr1D

Expand Down
20 changes: 14 additions & 6 deletions src/swiftest/swiftest_coarray.f90
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,7 @@ module subroutine swiftest_coarray_component_clone_info(var,src_img)
else
si = 1
end if

sync all

if (this_image() == si) then
do img = 1, num_images()
tmp[img] = var
Expand All @@ -269,6 +268,8 @@ module subroutine swiftest_coarray_component_clone_info(var,src_img)
sync images(si)
var = tmp[si]
end if

deallocate(tmp)

return
end subroutine swiftest_coarray_component_clone_info
Expand Down Expand Up @@ -314,6 +315,8 @@ module subroutine swiftest_coarray_component_clone_info_arr1D(var,src_img)
if (allocated(var)) deallocate(var)
allocate(var, source=tmp)
end if

deallocate(isalloc,n,tmp)

return
end subroutine swiftest_coarray_component_clone_info_arr1D
Expand All @@ -331,16 +334,17 @@ module subroutine swiftest_coarray_component_clone_kin_arr1D(var,src_img)
! Internals
type(swiftest_kinship), dimension(:), codimension[:], allocatable :: tmp
integer(I4B) :: img, si
integer(I4B), save :: n[*]
logical, save :: isalloc[*]
integer(I4B), allocatable :: n[:]
logical, allocatable :: isalloc[:]

if (present(src_img)) then
si = src_img
else
si = 1
end if

sync all
allocate(isalloc[*])
allocate(n[*])
isalloc = allocated(var)
if (isalloc) n = size(var)
sync all
Expand All @@ -357,6 +361,8 @@ module subroutine swiftest_coarray_component_clone_kin_arr1D(var,src_img)
if (allocated(var)) deallocate(var)
allocate(var, source=tmp)
end if

deallocate(isalloc,n,tmp)

return
end subroutine swiftest_coarray_component_clone_kin_arr1D
Expand Down Expand Up @@ -409,6 +415,8 @@ module subroutine swiftest_coarray_component_collect_info_arr1D(var,dest_img)
end if
end do
end if

deallocate(isalloc,n,tmp)

return
end subroutine swiftest_coarray_component_collect_info_arr1D
Expand Down Expand Up @@ -564,7 +572,7 @@ module subroutine swiftest_coarray_distribute_system(nbody_system, param)
if (param%log_output) flush(param%display_unit)
if (this_image() < num_images()) sync images(this_image() + 1)

deallocate(tmp, cotp)
deallocate(ntp, lspill_list, tmp, cotp)

return
end subroutine swiftest_coarray_distribute_system
Expand Down

0 comments on commit 22cf767

Please sign in to comment.