Lazy-allocate the persistent send/recv buffers used by
halo_exchange_2d_device (and halo_exchange_2d via the same
pool). Sized to the per-rank subdomain; resizes on grid change.
Allocates conservatively in all four directions even if this
rank is at a domain edge – the pack/unpack guards in
halo_exchange_2d_device then skip directions that aren’t
used, but the buffers exist so back-to-back calls don’t hit
cudaMalloc. At ~strip_ew + strip_sn doubles per direction the
total residency is negligible compared with the field arrays.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| integer, | intent(in) | :: | nghost | |||
| integer, | intent(in) | :: | nx_total | |||
| integer, | intent(in) | :: | ny_total |
| Type | Visibility | Attributes | Name | Initial | |||
|---|---|---|---|---|---|---|---|
| logical, | private | :: | needs_realloc | ||||
| integer, | private | :: | strip_ew | ||||
| integer, | private | :: | strip_sn |
subroutine halo_sync_buffers_ensure(nghost, nx_total, ny_total) !! Lazy-allocate the persistent send/recv buffers used by !! `halo_exchange_2d_device` (and `halo_exchange_2d` via the same !! pool). Sized to the per-rank subdomain; resizes on grid change. !! !! Allocates conservatively in all four directions even if this !! rank is at a domain edge -- the pack/unpack guards in !! `halo_exchange_2d_device` then skip directions that aren't !! used, but the buffers exist so back-to-back calls don't hit !! cudaMalloc. At ~strip_ew + strip_sn doubles per direction the !! total residency is negligible compared with the field arrays. integer, intent(in) :: nghost, nx_total, ny_total integer :: strip_ew, strip_sn logical :: needs_realloc strip_ew = nghost*ny_total strip_sn = nx_total*nghost needs_realloc = (.not. allocated(hs_buf_send_west)) .or. & hs_nghost /= nghost .or. & hs_nx_total /= nx_total .or. & hs_ny_total /= ny_total if (.not. needs_realloc) return call halo_sync_buffers_cleanup() allocate (hs_buf_send_west(strip_ew), hs_buf_recv_west(strip_ew)) allocate (hs_buf_send_east(strip_ew), hs_buf_recv_east(strip_ew)) allocate (hs_buf_send_south(strip_sn), hs_buf_recv_south(strip_sn)) allocate (hs_buf_send_north(strip_sn), hs_buf_recv_north(strip_sn)) !$acc enter data create(hs_buf_send_west, hs_buf_recv_west, & !$acc& hs_buf_send_east, hs_buf_recv_east, & !$acc& hs_buf_send_south, hs_buf_recv_south, & !$acc& hs_buf_send_north, hs_buf_recv_north) hs_nghost = nghost hs_nx_total = nx_total hs_ny_total = ny_total end subroutine halo_sync_buffers_ensure