halo_sync_buffers_ensure_3d Subroutine

public subroutine halo_sync_buffers_ensure_3d(nghost, nx_total, ny_total, nz)

Lazy-allocate the persistent 3D send/recv buffers used by halo_exchange_3d_device. Sized to the per-rank subdomain and the largest nz seen so far – subsequent calls with a smaller nz reuse the existing buffer (just write fewer elements), grow-only on nz so an ML run that later does an NH w halo (nz_ml+1) doesn’t free/reallocate. Resizes in full if (nx_total, ny_total, nghost) change.

Arguments

Type IntentOptional Attributes Name
integer, intent(in) :: nghost
integer, intent(in) :: nx_total
integer, intent(in) :: ny_total
integer, intent(in) :: nz

Calls

proc~~halo_sync_buffers_ensure_3d~~CallsGraph proc~halo_sync_buffers_ensure_3d halo_sync_buffers_ensure_3d proc~halo_sync_buffers_cleanup_3d halo_sync_buffers_cleanup_3d proc~halo_sync_buffers_ensure_3d->proc~halo_sync_buffers_cleanup_3d

Called by

proc~~halo_sync_buffers_ensure_3d~~CalledByGraph proc~halo_sync_buffers_ensure_3d halo_sync_buffers_ensure_3d proc~halo_exchange_3d_device halo_exchange_3d_device proc~halo_exchange_3d_device->proc~halo_sync_buffers_ensure_3d

Variables

Type Visibility Attributes Name Initial
integer, private :: cap_nz
logical, private :: needs_full_realloc
logical, private :: needs_grow
integer, private :: strip_ew
integer, private :: strip_sn

Source Code

   subroutine halo_sync_buffers_ensure_3d(nghost, nx_total, ny_total, nz)
      !! Lazy-allocate the persistent 3D send/recv buffers used by
      !! `halo_exchange_3d_device`.  Sized to the per-rank subdomain
      !! and the largest `nz` seen so far -- subsequent calls with a
      !! smaller `nz` reuse the existing buffer (just write fewer
      !! elements), grow-only on `nz` so an ML run that later does an
      !! NH `w` halo (nz_ml+1) doesn't free/reallocate.  Resizes in
      !! full if (nx_total, ny_total, nghost) change.
      integer, intent(in) :: nghost, nx_total, ny_total, nz

      integer :: cap_nz, strip_ew, strip_sn
      logical :: needs_full_realloc, needs_grow

      needs_full_realloc = (.not. allocated(hs3_buf_send_west)) .or. &
                           hs3_nghost /= nghost .or. &
                           hs3_nx_total /= nx_total .or. &
                           hs3_ny_total /= ny_total
      needs_grow = (.not. needs_full_realloc) .and. nz > hs3_nz_capacity

      if (.not. needs_full_realloc .and. .not. needs_grow) return

      call halo_sync_buffers_cleanup_3d()

      cap_nz = nz
      strip_ew = nghost*ny_total*cap_nz
      strip_sn = nx_total*nghost*cap_nz

      allocate (hs3_buf_send_west(strip_ew), hs3_buf_recv_west(strip_ew))
      allocate (hs3_buf_send_east(strip_ew), hs3_buf_recv_east(strip_ew))
      allocate (hs3_buf_send_south(strip_sn), hs3_buf_recv_south(strip_sn))
      allocate (hs3_buf_send_north(strip_sn), hs3_buf_recv_north(strip_sn))
      !$acc enter data create(hs3_buf_send_west, hs3_buf_recv_west, &
      !$acc&                  hs3_buf_send_east, hs3_buf_recv_east, &
      !$acc&                  hs3_buf_send_south, hs3_buf_recv_south, &
      !$acc&                  hs3_buf_send_north, hs3_buf_recv_north)

      hs3_nghost = nghost
      hs3_nx_total = nx_total
      hs3_ny_total = ny_total
      hs3_nz_capacity = cap_nz

   end subroutine halo_sync_buffers_ensure_3d