Skip to content

Commit 9c2a820

Browse files
committed
fix: replace move_alloc on patch_ib with allocate/copy for GPU safety
patch_ib has GPU_DECLARE(create=...) in m_global_parameters, which means OpenACC/OpenMP tracks it via plain allocate/deallocate automatically. move_alloc is not reliably intercepted by all GPU runtimes for declare- create variables, so replace all three grow-on-demand sites (m_particle_bed, m_mpi_proxy, s_reduce_ib_patch_array 1-rank/no-MPI) with the established pattern: allocate tmp, copy, deallocate patch_ib, allocate patch_ib.
1 parent de6add6 commit 9c2a820

3 files changed

Lines changed: 14 additions & 6 deletions

File tree

src/simulation/m_mpi_proxy.fpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,9 @@ contains
199199
type(ib_patch_parameters), allocatable :: tmp(:)
200200
integer :: n
201201
n = size(patch_ib)
202-
call move_alloc(patch_ib, tmp)
202+
allocate (tmp(n))
203+
tmp(1:n) = patch_ib(1:n)
204+
deallocate (patch_ib)
203205
allocate (patch_ib(num_ib_patches_max))
204206
patch_ib(1:n) = tmp
205207
end block

src/simulation/m_particle_bed.fpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@ contains
4646
type(ib_patch_parameters), allocatable :: tmp(:)
4747
integer :: n
4848
n = size(patch_ib)
49-
call move_alloc(patch_ib, tmp)
49+
allocate (tmp(n))
50+
tmp(1:n) = patch_ib(1:n)
51+
deallocate (patch_ib)
5052
allocate (patch_ib(num_ib_patches_max))
5153
patch_ib(1:n) = tmp
5254
end block

src/simulation/m_start_up.fpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1241,8 +1241,10 @@ contains
12411241

12421242
#ifdef MFC_MPI
12431243
if (num_procs == 1) then
1244-
! single-rank: every patch is local - transfer ownership directly to avoid truncation
1245-
call move_alloc(patch_ib_gbl, patch_ib)
1244+
! single-rank: every patch is local; allocate to exact size and copy
1245+
allocate (patch_ib(num_gbl_ibs))
1246+
patch_ib(1:num_gbl_ibs) = patch_ib_gbl(1:num_gbl_ibs)
1247+
deallocate (patch_ib_gbl)
12461248
else
12471249
! multi-rank: carve out the local neighbourhood subset
12481250
num_aware_ibs = min(num_local_ibs_max*(2*ib_neighborhood_radius + 1)**num_dims, num_ib_patches_max)
@@ -1271,8 +1273,10 @@ contains
12711273
deallocate (patch_ib_gbl)
12721274
end if
12731275
#else
1274-
! no-MPI: every patch is local - transfer ownership directly to avoid truncation
1275-
call move_alloc(patch_ib_gbl, patch_ib)
1276+
! no-MPI: every patch is local; allocate to exact size and copy
1277+
allocate (patch_ib(num_gbl_ibs))
1278+
patch_ib(1:num_gbl_ibs) = patch_ib_gbl(1:num_gbl_ibs)
1279+
deallocate (patch_ib_gbl)
12761280
#endif
12771281

12781282
@:ALLOCATE(ib_gbl_idx_lookup(1:num_gbl_ibs))

0 commit comments

Comments
 (0)