From 22cf76752a1fa07d3922928dbde110647ef290e7 Mon Sep 17 00:00:00 2001 From: David A Minton Date: Sun, 30 Apr 2023 18:02:04 -0400 Subject: [PATCH] Added deallocate statements to get memory issues under control --- src/coarray/coarray_clone.f90 | 37 +++++++++++++++++++++---------- src/coarray/coarray_collect.f90 | 28 ++++++++++++++++------- src/swiftest/swiftest_coarray.f90 | 20 ++++++++++++----- 3 files changed, 59 insertions(+), 26 deletions(-) diff --git a/src/coarray/coarray_clone.f90 b/src/coarray/coarray_clone.f90 index 4e9a34591..9f7e1ea1a 100644 --- a/src/coarray/coarray_clone.f90 +++ b/src/coarray/coarray_clone.f90 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -282,10 +288,9 @@ 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 @@ -293,6 +298,8 @@ module subroutine coarray_component_clone_I4B(var,src_img) var = tmp[si] end if + deallocate(tmp) + return end subroutine coarray_component_clone_I4B @@ -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 @@ -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 @@ -361,10 +370,9 @@ 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 @@ -372,6 +380,8 @@ module subroutine coarray_component_clone_I8B(var,src_img) var = tmp[si] end if + deallocate(tmp) + return end subroutine coarray_component_clone_I8B @@ -397,10 +407,9 @@ 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 @@ -408,6 +417,7 @@ module subroutine coarray_component_clone_lgt(var,src_img) var = tmp[si] end if + deallocate(tmp) return end subroutine coarray_component_clone_lgt @@ -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 @@ -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 @@ -477,10 +489,9 @@ 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 @@ -488,6 +499,8 @@ module subroutine coarray_component_clone_QP(var,src_img) var = tmp[si] end if + deallocate(tmp) + return end subroutine coarray_component_clone_QP diff --git a/src/coarray/coarray_collect.f90 b/src/coarray/coarray_collect.f90 index bf60aa522..0f85bf41a 100644 --- a/src/coarray/coarray_collect.f90 +++ b/src/coarray/coarray_collect.f90 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/src/swiftest/swiftest_coarray.f90 b/src/swiftest/swiftest_coarray.f90 index fe523f64f..a95f8adc8 100644 --- a/src/swiftest/swiftest_coarray.f90 +++ b/src/swiftest/swiftest_coarray.f90 @@ -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 @@ -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 @@ -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 @@ -331,8 +334,8 @@ 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 @@ -340,7 +343,8 @@ module subroutine swiftest_coarray_component_clone_kin_arr1D(var,src_img) si = 1 end if - sync all + allocate(isalloc[*]) + allocate(n[*]) isalloc = allocated(var) if (isalloc) n = size(var) sync 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 @@ -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 @@ -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