Skip to content

Commit cfe7935

Browse files
committed
fix(amr): nonpoly QBMM slot side-state uses the pres_field + ACC_SETUP_SFs pattern - the previous fix removed the ghost-fill component-section clause but the fine s_compute_rhs call still passed raw amr_slots(amr_cur)%pb_f/mv_f/rhs_* 5D members as actuals (second CUDA illegal address on device); persistent slot state (pb/mv f, stor, ghost_a/b) is now type(pres_field) with %sf allocated + ACC_SETUP_SFs per slot (the exact pb_ts pattern the coarse solver passes through the same RHS interface on GPU), and the fine rhs scratch moves to shared module arrays amr_rhs_pb_f/amr_rhs_mv_f (slots advance sequentially; mirrors the coarse rhs_pb pattern). CPU nonpoly battery bit-identical (4/4)
1 parent c7fbc1d commit cfe7935

1 file changed

Lines changed: 73 additions & 59 deletions

File tree

src/simulation/m_amr.fpp

Lines changed: 73 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,12 @@ module m_amr
7070
!! only the local cell + the block's own moment fluxes), so the fine treatment is prolong -> advance -> restrict with no
7171
!! reflux; ghosts feed the widened- idwint conversions and are prolonged piecewise-constant (CHyQMOM realizability, like the
7272
!! moments).
73-
real(stp), allocatable :: pb_f(:,:,:,:,:), mv_f(:,:,:,:,:) !< fine pb/mv (ghost-inclusive)
74-
real(stp), allocatable :: pb_stor(:,:,:,:,:), mv_stor(:,:,:,:,:) !< SSP-RK step-entry backup (also the regrid bounce)
73+
type(pres_field) :: pb_f, mv_f !< fine pb/mv (ghost-inclusive)
74+
type(pres_field) :: pb_stor, mv_stor !< SSP-RK step-entry backup (also the regrid bounce)
7575
!> subcycle ghost-lerp sources at coarse t^n / t^{n+1} (ghost shell only): ghost pb feeds the mixture pressure in the
7676
!! widened conversion, so it needs the same time fidelity as q_cons
77-
real(stp), allocatable :: pb_ghost_a(:,:,:,:,:), mv_ghost_a(:,:,:,:,:)
78-
real(stp), allocatable :: pb_ghost_b(:,:,:,:,:), mv_ghost_b(:,:,:,:,:)
79-
real(wp), allocatable :: rhs_pb_f(:,:,:,:,:), rhs_mv_f(:,:,:,:,:) !< fine rhs (ghost-inclusive like rhs)
77+
type(pres_field) :: pb_ghost_a, mv_ghost_a
78+
type(pres_field) :: pb_ghost_b, mv_ghost_b
8079
end type t_level
8180

8281
!> Fixed pool of refined-block slots (at init one slot is active; dynamic regrid activates up to amr_max_blocks). The working
@@ -100,6 +99,12 @@ module m_amr
10099
real(wp), allocatable :: sw_jac(:,:,:), sw_jac_old(:,:,:)
101100
$:GPU_DECLARE(create='[sw_jac, sw_jac_old]')
102101

102+
!> Non-polytropic QBMM fine rhs scratch, shared across slots (slots advance sequentially). Module-level raw arrays mirror the
103+
!! coarse rhs_pb/rhs_mv pattern: derived-type component actuals for these tripped nvfortran's component-section data clauses on
104+
!! device.
105+
real(wp), allocatable :: amr_rhs_pb_f(:,:,:,:,:), amr_rhs_mv_f(:,:,:,:,:)
106+
$:GPU_DECLARE(create='[amr_rhs_pb_f, amr_rhs_mv_f]')
107+
103108
!> Lagrangian bubble-cloud exclusion support: padded global coarse-index bbox of the cloud (positions + mapCells smearing +
104109
!! stencil headroom [+ drift margin at regrid]). Blocks and regrid boxes stay clear of it: a bubble inside a block loses two-way
105110
!! coupling (the fine advance skips the EL hooks and the coarse result under the block is discarded by restriction). Recomputed
@@ -291,17 +296,20 @@ contains
291296
@:ACC_SETUP_SFs(amr_slots(islot)%q_ghost_b(i))
292297
end do
293298
if (qbmm .and. .not. polytropic) then
294-
@:ALLOCATE(amr_slots(islot)%pb_f(mbuf1_lo:mbuf1_hi, mbuf2_lo:mbuf2_hi, mbuf3_lo:mbuf3_hi, 1:nnode, 1:nb))
295-
@:ALLOCATE(amr_slots(islot)%mv_f(mbuf1_lo:mbuf1_hi, mbuf2_lo:mbuf2_hi, mbuf3_lo:mbuf3_hi, 1:nnode, 1:nb))
296-
@:ALLOCATE(amr_slots(islot)%pb_stor(mbuf1_lo:mbuf1_hi, mbuf2_lo:mbuf2_hi, mbuf3_lo:mbuf3_hi, 1:nnode, 1:nb))
297-
@:ALLOCATE(amr_slots(islot)%mv_stor(mbuf1_lo:mbuf1_hi, mbuf2_lo:mbuf2_hi, mbuf3_lo:mbuf3_hi, 1:nnode, 1:nb))
298-
@:ALLOCATE(amr_slots(islot)%rhs_pb_f(mbuf1_lo:mbuf1_hi, mbuf2_lo:mbuf2_hi, mbuf3_lo:mbuf3_hi, 1:nnode, 1:nb))
299-
@:ALLOCATE(amr_slots(islot)%rhs_mv_f(mbuf1_lo:mbuf1_hi, mbuf2_lo:mbuf2_hi, mbuf3_lo:mbuf3_hi, 1:nnode, 1:nb))
299+
#:for PF in ['pb_f', 'mv_f', 'pb_stor', 'mv_stor']
300+
@:ALLOCATE(amr_slots(islot)%${PF}$%sf(mbuf1_lo:mbuf1_hi, mbuf2_lo:mbuf2_hi, mbuf3_lo:mbuf3_hi, 1:nnode, 1:nb))
301+
@:ACC_SETUP_SFs(amr_slots(islot)%${PF}$)
302+
#:endfor
303+
if (islot == 1) then
304+
@:ALLOCATE(amr_rhs_pb_f(mbuf1_lo:mbuf1_hi, mbuf2_lo:mbuf2_hi, mbuf3_lo:mbuf3_hi, 1:nnode, 1:nb))
305+
@:ALLOCATE(amr_rhs_mv_f(mbuf1_lo:mbuf1_hi, mbuf2_lo:mbuf2_hi, mbuf3_lo:mbuf3_hi, 1:nnode, 1:nb))
306+
end if
300307
if (amr_subcycle) then
301-
@:ALLOCATE(amr_slots(islot)%pb_ghost_a(mbuf1_lo:mbuf1_hi, mbuf2_lo:mbuf2_hi, mbuf3_lo:mbuf3_hi, 1:nnode, 1:nb))
302-
@:ALLOCATE(amr_slots(islot)%mv_ghost_a(mbuf1_lo:mbuf1_hi, mbuf2_lo:mbuf2_hi, mbuf3_lo:mbuf3_hi, 1:nnode, 1:nb))
303-
@:ALLOCATE(amr_slots(islot)%pb_ghost_b(mbuf1_lo:mbuf1_hi, mbuf2_lo:mbuf2_hi, mbuf3_lo:mbuf3_hi, 1:nnode, 1:nb))
304-
@:ALLOCATE(amr_slots(islot)%mv_ghost_b(mbuf1_lo:mbuf1_hi, mbuf2_lo:mbuf2_hi, mbuf3_lo:mbuf3_hi, 1:nnode, 1:nb))
308+
#:for PF in ['pb_ghost_a', 'mv_ghost_a', 'pb_ghost_b', 'mv_ghost_b']
309+
@:ALLOCATE(amr_slots(islot)%${PF}$%sf(mbuf1_lo:mbuf1_hi, mbuf2_lo:mbuf2_hi, mbuf3_lo:mbuf3_hi, 1:nnode, &
310+
& 1:nb))
311+
@:ACC_SETUP_SFs(amr_slots(islot)%${PF}$)
312+
#:endfor
305313
end if
306314
end if
307315
end do
@@ -805,8 +813,8 @@ contains
805813
if (qbmm .and. .not. polytropic) then
806814
! mirror the coarse correct-state: non-polytropic QBMM also corrects the block's own
807815
! pb/mv side-state at the body ghost points (bounds match the swapped fine idwbuff)
808-
call s_ibm_correct_state(amr_slots(amr_cur)%q_cons, amr_slots(amr_cur)%q_prim, amr_slots(amr_cur)%pb_f, &
809-
& amr_slots(amr_cur)%mv_f)
816+
call s_ibm_correct_state(amr_slots(amr_cur)%q_cons, amr_slots(amr_cur)%q_prim, amr_slots(amr_cur)%pb_f%sf, &
817+
& amr_slots(amr_cur)%mv_f%sf)
810818
else
811819
call s_ibm_correct_state(amr_slots(amr_cur)%q_cons, amr_slots(amr_cur)%q_prim)
812820
end if
@@ -936,8 +944,8 @@ contains
936944
cj = 0
937945
if (n_glb > 0) cj = lo2 + fj/rr - oy
938946
ci = lo1 + fi/rr - ox
939-
amr_slots(amr_cur)%pb_f(fi, fj, fk, q, ib_) = pb_ts(1)%sf(ci, cj, ck, q, ib_)
940-
amr_slots(amr_cur)%mv_f(fi, fj, fk, q, ib_) = mv_ts(1)%sf(ci, cj, ck, q, ib_)
947+
amr_slots(amr_cur)%pb_f%sf(fi, fj, fk, q, ib_) = pb_ts(1)%sf(ci, cj, ck, q, ib_)
948+
amr_slots(amr_cur)%mv_f%sf(fi, fj, fk, q, ib_) = mv_ts(1)%sf(ci, cj, ck, q, ib_)
941949
end do
942950
end do
943951
end do
@@ -985,8 +993,8 @@ contains
985993
cj = 0
986994
if (d2) cj = lo2 + floor(real(fj, wp)/real(rr, wp)) - oy
987995
ci = lo1 + floor(real(fi, wp)/real(rr, wp)) - ox
988-
amr_slots(amr_cur)%pb_${SFX}$ (fi, fj, fk, q, ib_) = pb_c(ci, cj, ck, q, ib_)
989-
amr_slots(amr_cur)%mv_${SFX}$ (fi, fj, fk, q, ib_) = mv_c(ci, cj, ck, q, ib_)
996+
amr_slots(amr_cur)%pb_${SFX}$%sf(fi, fj, fk, q, ib_) = pb_c(ci, cj, ck, q, ib_)
997+
amr_slots(amr_cur)%mv_${SFX}$%sf(fi, fj, fk, q, ib_) = mv_c(ci, cj, ck, q, ib_)
990998
end if
991999
end do
9921000
end do
@@ -1013,8 +1021,8 @@ contains
10131021
do fk = b3, e3
10141022
do fj = b2, e2
10151023
do fi = b1, e1
1016-
amr_slots(amr_cur)%pb_stor(fi, fj, fk, q, ib_) = amr_slots(amr_cur)%pb_f(fi, fj, fk, q, ib_)
1017-
amr_slots(amr_cur)%mv_stor(fi, fj, fk, q, ib_) = amr_slots(amr_cur)%mv_f(fi, fj, fk, q, ib_)
1024+
amr_slots(amr_cur)%pb_stor%sf(fi, fj, fk, q, ib_) = amr_slots(amr_cur)%pb_f%sf(fi, fj, fk, q, ib_)
1025+
amr_slots(amr_cur)%mv_stor%sf(fi, fj, fk, q, ib_) = amr_slots(amr_cur)%mv_f%sf(fi, fj, fk, q, ib_)
10181026
end do
10191027
end do
10201028
end do
@@ -1038,12 +1046,12 @@ contains
10381046
do fk = 0, fp
10391047
do fj = 0, fn
10401048
do fi = 0, fm
1041-
amr_slots(amr_cur)%pb_f(fi, fj, fk, q, ib_) = (c1*amr_slots(amr_cur)%pb_f(fi, fj, fk, q, &
1042-
& ib_) + c2*amr_slots(amr_cur)%pb_stor(fi, fj, fk, q, &
1043-
& ib_) + c3*dtl*amr_slots(amr_cur)%rhs_pb_f(fi, fj, fk, q, ib_))/c4
1044-
amr_slots(amr_cur)%mv_f(fi, fj, fk, q, ib_) = (c1*amr_slots(amr_cur)%mv_f(fi, fj, fk, q, &
1045-
& ib_) + c2*amr_slots(amr_cur)%mv_stor(fi, fj, fk, q, &
1046-
& ib_) + c3*dtl*amr_slots(amr_cur)%rhs_mv_f(fi, fj, fk, q, ib_))/c4
1049+
amr_slots(amr_cur)%pb_f%sf(fi, fj, fk, q, ib_) = (c1*amr_slots(amr_cur)%pb_f%sf(fi, fj, fk, q, &
1050+
& ib_) + c2*amr_slots(amr_cur)%pb_stor%sf(fi, fj, fk, q, ib_) + c3*dtl*amr_rhs_pb_f(fi, fj, &
1051+
& fk, q, ib_))/c4
1052+
amr_slots(amr_cur)%mv_f%sf(fi, fj, fk, q, ib_) = (c1*amr_slots(amr_cur)%mv_f%sf(fi, fj, fk, q, &
1053+
& ib_) + c2*amr_slots(amr_cur)%mv_stor%sf(fi, fj, fk, q, ib_) + c3*dtl*amr_rhs_mv_f(fi, fj, &
1054+
& fk, q, ib_))/c4
10471055
end do
10481056
end do
10491057
end do
@@ -1083,11 +1091,11 @@ contains
10831091
accp = 0._wp; accm = 0._wp
10841092
do ddk = 0, dk_hi
10851093
do ddj = 0, dj_hi
1086-
accp = accp + real(amr_slots(amr_cur)%pb_f(fi0, fj0 + ddj, fk0 + ddk, q, ib_), &
1087-
& wp) + real(amr_slots(amr_cur)%pb_f(fi0 + 1, fj0 + ddj, fk0 + ddk, q, &
1094+
accp = accp + real(amr_slots(amr_cur)%pb_f%sf(fi0, fj0 + ddj, fk0 + ddk, q, ib_), &
1095+
& wp) + real(amr_slots(amr_cur)%pb_f%sf(fi0 + 1, fj0 + ddj, fk0 + ddk, q, &
10881096
& ib_), wp)
1089-
accm = accm + real(amr_slots(amr_cur)%mv_f(fi0, fj0 + ddj, fk0 + ddk, q, ib_), &
1090-
& wp) + real(amr_slots(amr_cur)%mv_f(fi0 + 1, fj0 + ddj, fk0 + ddk, q, &
1097+
accm = accm + real(amr_slots(amr_cur)%mv_f%sf(fi0, fj0 + ddj, fk0 + ddk, q, ib_), &
1098+
& wp) + real(amr_slots(amr_cur)%mv_f%sf(fi0 + 1, fj0 + ddj, fk0 + ddk, q, &
10911099
& ib_), wp)
10921100
end do
10931101
end do
@@ -1579,10 +1587,12 @@ contains
15791587
do fj = b2, e2
15801588
do fi = b1, e1
15811589
if (.not. (fi >= 0 .and. fi <= fm .and. fj >= 0 .and. fj <= fn .and. fk >= 0 .and. fk <= fp)) then
1582-
amr_slots(amr_cur)%pb_f(fi, fj, fk, q, ib_) = (1._wp - th)*real(amr_slots(amr_cur)%pb_ghost_a(fi, &
1583-
& fj, fk, q, ib_), wp) + th*real(amr_slots(amr_cur)%pb_ghost_b(fi, fj, fk, q, ib_), wp)
1584-
amr_slots(amr_cur)%mv_f(fi, fj, fk, q, ib_) = (1._wp - th)*real(amr_slots(amr_cur)%mv_ghost_a(fi, &
1585-
& fj, fk, q, ib_), wp) + th*real(amr_slots(amr_cur)%mv_ghost_b(fi, fj, fk, q, ib_), wp)
1590+
amr_slots(amr_cur)%pb_f%sf(fi, fj, fk, q, &
1591+
& ib_) = (1._wp - th)*real(amr_slots(amr_cur)%pb_ghost_a%sf(fi, fj, fk, q, ib_), &
1592+
& wp) + th*real(amr_slots(amr_cur)%pb_ghost_b%sf(fi, fj, fk, q, ib_), wp)
1593+
amr_slots(amr_cur)%mv_f%sf(fi, fj, fk, q, &
1594+
& ib_) = (1._wp - th)*real(amr_slots(amr_cur)%mv_ghost_a%sf(fi, fj, fk, q, ib_), &
1595+
& wp) + th*real(amr_slots(amr_cur)%mv_ghost_b%sf(fi, fj, fk, q, ib_), wp)
15861596
end if
15871597
end do
15881598
end do
@@ -1717,8 +1727,8 @@ contains
17171727
! the block's OWN side-state and rhs scratch: the coarse pb_in/rhs_pb must not be
17181728
! touched at fine indices (the coarse stage consumes them after this fine stage)
17191729
call s_compute_rhs(amr_slots(amr_cur)%q_cons, q_T_sf, amr_slots(amr_cur)%q_prim, bc_type, amr_slots(amr_cur)%rhs, &
1720-
& amr_slots(amr_cur)%pb_f, amr_slots(amr_cur)%rhs_pb_f, amr_slots(amr_cur)%mv_f, &
1721-
& amr_slots(amr_cur)%rhs_mv_f, t_step, time_avg, s)
1730+
& amr_slots(amr_cur)%pb_f%sf, amr_rhs_pb_f, amr_slots(amr_cur)%mv_f%sf, amr_rhs_mv_f, t_step, &
1731+
& time_avg, s)
17221732
else
17231733
call s_compute_rhs(amr_slots(amr_cur)%q_cons, q_T_sf, amr_slots(amr_cur)%q_prim, bc_type, amr_slots(amr_cur)%rhs, &
17241734
& pb_in, rhs_pb, mv_in, rhs_mv, t_step, time_avg, s)
@@ -1815,8 +1825,8 @@ contains
18151825
if (qbmm .and. .not. polytropic) then
18161826
! the block's OWN side-state and rhs scratch (the coarse arrays stay untouched)
18171827
call s_compute_rhs(amr_slots(amr_cur)%q_cons, q_T_sf, amr_slots(amr_cur)%q_prim, bc_type, &
1818-
& amr_slots(amr_cur)%rhs, amr_slots(amr_cur)%pb_f, amr_slots(amr_cur)%rhs_pb_f, &
1819-
& amr_slots(amr_cur)%mv_f, amr_slots(amr_cur)%rhs_mv_f, t_step, time_avg, s)
1828+
& amr_slots(amr_cur)%rhs, amr_slots(amr_cur)%pb_f%sf, amr_rhs_pb_f, &
1829+
& amr_slots(amr_cur)%mv_f%sf, amr_rhs_mv_f, t_step, time_avg, s)
18201830
else
18211831
call s_compute_rhs(amr_slots(amr_cur)%q_cons, q_T_sf, amr_slots(amr_cur)%q_prim, bc_type, &
18221832
& amr_slots(amr_cur)%rhs, pb_in, rhs_pb, mv_in, rhs_mv, t_step, time_avg, s)
@@ -2470,11 +2480,11 @@ contains
24702480
! non-polytropic QBMM: the side-state bounces through pb/mv_stor exactly like
24712481
! q_cons (both stors are dead between steps)
24722482
if (qbmm .and. .not. polytropic) then
2473-
$:GPU_UPDATE(host='[amr_slots(k)%pb_f, amr_slots(k)%mv_f]')
2474-
amr_slots(k)%pb_stor(0:old_ext(1, k),0:old_ext(2, k),0:old_ext(3, k),:, &
2475-
& :) = amr_slots(k)%pb_f(0:old_ext(1, k),0:old_ext(2, k),0:old_ext(3, k),:,:)
2476-
amr_slots(k)%mv_stor(0:old_ext(1, k),0:old_ext(2, k),0:old_ext(3, k),:, &
2477-
& :) = amr_slots(k)%mv_f(0:old_ext(1, k),0:old_ext(2, k),0:old_ext(3, k),:,:)
2483+
$:GPU_UPDATE(host='[amr_slots(k)%pb_f%sf, amr_slots(k)%mv_f]')
2484+
amr_slots(k)%pb_stor%sf(0:old_ext(1, k),0:old_ext(2, k),0:old_ext(3, k),:, &
2485+
& :) = amr_slots(k)%pb_f%sf(0:old_ext(1, k),0:old_ext(2, k),0:old_ext(3, k),:,:)
2486+
amr_slots(k)%mv_stor%sf(0:old_ext(1, k),0:old_ext(2, k),0:old_ext(3, k),:, &
2487+
& :) = amr_slots(k)%mv_f%sf(0:old_ext(1, k),0:old_ext(2, k),0:old_ext(3, k),:,:)
24782488
end if
24792489
end if
24802490
end do
@@ -2533,13 +2543,13 @@ contains
25332543
do fi = 0, amr_slots(k)%m
25342544
ofi = fi + sh(1)
25352545
if (ofi < 0 .or. ofi > old_ext(1, kk)) cycle
2536-
amr_slots(k)%pb_f(fi, fj, fk,:,:) = amr_slots(kk)%pb_stor(ofi, ofj, ofk,:,:)
2537-
amr_slots(k)%mv_f(fi, fj, fk,:,:) = amr_slots(kk)%mv_stor(ofi, ofj, ofk,:,:)
2546+
amr_slots(k)%pb_f%sf(fi, fj, fk,:,:) = amr_slots(kk)%pb_stor%sf(ofi, ofj, ofk,:,:)
2547+
amr_slots(k)%mv_f%sf(fi, fj, fk,:,:) = amr_slots(kk)%mv_stor%sf(ofi, ofj, ofk,:,:)
25382548
end do
25392549
end do
25402550
end do
25412551
end do
2542-
$:GPU_UPDATE(device='[amr_slots(k)%pb_f, amr_slots(k)%mv_f]')
2552+
$:GPU_UPDATE(device='[amr_slots(k)%pb_f%sf, amr_slots(k)%mv_f]')
25432553
end if
25442554
call s_mpi_sendrecv_amr_fine_halo(amr_slots(k)%q_cons, amr_slots(k)%m, amr_slots(k)%n, amr_slots(k)%p)
25452555
end do
@@ -3053,17 +3063,21 @@ contains
30533063
@:DEALLOCATE(amr_slots(islot)%q_ghost_a)
30543064
@:DEALLOCATE(amr_slots(islot)%q_ghost_b)
30553065
if (qbmm .and. .not. polytropic) then
3056-
@:DEALLOCATE(amr_slots(islot)%pb_f)
3057-
@:DEALLOCATE(amr_slots(islot)%mv_f)
3058-
@:DEALLOCATE(amr_slots(islot)%pb_stor)
3059-
@:DEALLOCATE(amr_slots(islot)%mv_stor)
3060-
@:DEALLOCATE(amr_slots(islot)%rhs_pb_f)
3061-
@:DEALLOCATE(amr_slots(islot)%rhs_mv_f)
3066+
@:DEALLOCATE(amr_slots(islot)%pb_f%sf)
3067+
@:DEALLOCATE(amr_slots(islot)%mv_f%sf)
3068+
@:DEALLOCATE(amr_slots(islot)%pb_stor%sf)
3069+
@:DEALLOCATE(amr_slots(islot)%mv_stor%sf)
3070+
if (islot == 1) then
3071+
@:DEALLOCATE(amr_rhs_pb_f)
3072+
end if
3073+
if (islot == 1) then
3074+
@:DEALLOCATE(amr_rhs_mv_f)
3075+
end if
30623076
if (amr_subcycle) then
3063-
@:DEALLOCATE(amr_slots(islot)%pb_ghost_a)
3064-
@:DEALLOCATE(amr_slots(islot)%mv_ghost_a)
3065-
@:DEALLOCATE(amr_slots(islot)%pb_ghost_b)
3066-
@:DEALLOCATE(amr_slots(islot)%mv_ghost_b)
3077+
@:DEALLOCATE(amr_slots(islot)%pb_ghost_a%sf)
3078+
@:DEALLOCATE(amr_slots(islot)%mv_ghost_a%sf)
3079+
@:DEALLOCATE(amr_slots(islot)%pb_ghost_b%sf)
3080+
@:DEALLOCATE(amr_slots(islot)%mv_ghost_b%sf)
30673081
end if
30683082
end if
30693083
if (allocated(amr_slots(islot)%x_cb)) deallocate (amr_slots(islot)%x_cb, amr_slots(islot)%x_cc, amr_slots(islot)%dx)

0 commit comments

Comments
 (0)