ocean_halo_buffers_ensure_wide Subroutine

private subroutine ocean_halo_buffers_ensure_wide(ng_wide)

Grow the persistent send/recv buffers to hold at least a wide 2D exchange at ghost width ng_wide. Uses the same exit-delete / dealloc / alloc / enter-create pattern as ocean_halo_buffers_ensure_nz. Safe to call with ng_wide == oh_nghost (no-op if already large enough).

Arguments

Type IntentOptional Attributes Name
integer, intent(in) :: ng_wide

Wide ghost cell width required


Calls

proc~~ocean_halo_buffers_ensure_wide~~CallsGraph proc~ocean_halo_buffers_ensure_wide ocean_halo_buffers_ensure_wide to_string to_string proc~ocean_halo_buffers_ensure_wide->to_string warning warning proc~ocean_halo_buffers_ensure_wide->warning

Called by

proc~~ocean_halo_buffers_ensure_wide~~CalledByGraph proc~ocean_halo_buffers_ensure_wide ocean_halo_buffers_ensure_wide proc~ocean_halo_bt_group_2d_wide ocean_halo_bt_group_2d_wide proc~ocean_halo_bt_group_2d_wide->proc~ocean_halo_buffers_ensure_wide proc~ocean_halo_centre_2d_wide ocean_halo_centre_2d_wide proc~ocean_halo_centre_2d_wide->proc~ocean_halo_buffers_ensure_wide proc~ocean_halo_face_x_2d_wide ocean_halo_face_x_2d_wide proc~ocean_halo_face_x_2d_wide->proc~ocean_halo_buffers_ensure_wide proc~ocean_halo_face_y_2d_wide ocean_halo_face_y_2d_wide proc~ocean_halo_face_y_2d_wide->proc~ocean_halo_buffers_ensure_wide proc~barotropic_substep_nonlinear barotropic_substep_nonlinear proc~barotropic_substep_nonlinear->proc~ocean_halo_bt_group_2d_wide proc~bt_wide_entry_exchange_impl bt_wide_entry_exchange_impl proc~bt_wide_entry_exchange_impl->proc~ocean_halo_bt_group_2d_wide proc~bt_wide_entry_exchange_impl->proc~ocean_halo_centre_2d_wide proc~bt_wide_entry_exchange_impl->proc~ocean_halo_face_x_2d_wide proc~bt_wide_entry_exchange_impl->proc~ocean_halo_face_y_2d_wide proc~engine_enter_data engine_enter_data proc~engine_enter_data->proc~ocean_halo_bt_group_2d_wide proc~barotropic_substep_nonlinear_interior barotropic_substep_nonlinear_interior proc~barotropic_substep_nonlinear_interior->proc~barotropic_substep_nonlinear proc~bt_wide_entry_exchange bt_wide_t%bt_wide_entry_exchange proc~bt_wide_entry_exchange->proc~bt_wide_entry_exchange_impl proc~bt_wide_substep bt_wide_substep proc~bt_wide_substep->proc~barotropic_substep_nonlinear proc~complete_ocean_create complete_ocean_create proc~complete_ocean_create->proc~engine_enter_data proc~driver_run_ocean driver_run_ocean proc~driver_run_ocean->proc~engine_enter_data proc~driver_run driver_run proc~driver_run->proc~driver_run_ocean proc~rdb_ocean_create_finalize rdb_ocean_create_finalize proc~rdb_ocean_create_finalize->proc~complete_ocean_create proc~rdb_ocean_create_from_string rdb_ocean_create_from_string proc~rdb_ocean_create_from_string->proc~complete_ocean_create proc~run_stage_split run_stage_split proc~run_stage_split->proc~barotropic_substep_nonlinear_interior proc~run_stage_split->proc~bt_wide_entry_exchange proc~run_stage_split->proc~bt_wide_substep proc~ocean_dyn_step_split ocean_dyn_step_split proc~ocean_dyn_step_split->proc~run_stage_split

Variables

Type Visibility Attributes Name Initial
integer, private :: need_ew
integer, private :: need_ns
integer, private :: nxt_wide
integer, private :: nyt_wide

Source Code

   subroutine ocean_halo_buffers_ensure_wide(ng_wide)
      !! Grow the persistent send/recv buffers to hold at least a wide
      !! 2D exchange at ghost width ng_wide.
      !! Uses the same exit-delete / dealloc / alloc / enter-create pattern
      !! as ocean_halo_buffers_ensure_nz.  Safe to call with ng_wide ==
      !! oh_nghost (no-op if already large enough).
      integer, intent(in) :: ng_wide
         !! Wide ghost cell width required

      integer :: nyt_wide, nxt_wide, need_ew, need_ns

      nyt_wide = oh_ny_local + 2*ng_wide
      nxt_wide = oh_nx_local + 2*ng_wide
      ! face-x send-east uses (ng_wide+1)*nyt_wide; face-y send-north uses
      ! (ng_wide+1)*nxt_wide.
      need_ew = (ng_wide + 1)*nyt_wide
      need_ns = (ng_wide + 1)*nxt_wide

      if (need_ew <= oh_cap_ew .and. need_ns <= oh_cap_ns) return

      call logger%warning("ocean_halo_buffers_ensure_wide: growing halo buffers "// &
                          "mid-run (E/W: "//to_string(oh_cap_ew)//" -> "// &
                          to_string(need_ew)//", N/S: "//to_string(oh_cap_ns)//" -> "// &
                          to_string(need_ns)//"). "// &
                          "Call ocean_halo_reserve(nz, ng_wide) at init to avoid "// &
                          "a mid-run device reallocation (breaks UCX IPC handle reuse).")

      if (need_ew > oh_cap_ew) then
         !$acc exit data delete(oh_buf_send_east, oh_buf_recv_east, &
         !$acc&                 oh_buf_send_west, oh_buf_recv_west)
         deallocate (oh_buf_send_east, oh_buf_recv_east)
         deallocate (oh_buf_send_west, oh_buf_recv_west)
         allocate (oh_buf_send_east(need_ew), oh_buf_recv_east(need_ew))
         allocate (oh_buf_send_west(need_ew), oh_buf_recv_west(need_ew))
         !$acc enter data create(oh_buf_send_east, oh_buf_recv_east, &
         !$acc&                  oh_buf_send_west, oh_buf_recv_west)
         oh_cap_ew = need_ew
      end if

      if (need_ns > oh_cap_ns) then
         !$acc exit data delete(oh_buf_send_north, oh_buf_recv_north, &
         !$acc&                 oh_buf_send_south, oh_buf_recv_south)
         deallocate (oh_buf_send_north, oh_buf_recv_north)
         deallocate (oh_buf_send_south, oh_buf_recv_south)
         allocate (oh_buf_send_north(need_ns), oh_buf_recv_north(need_ns))
         allocate (oh_buf_send_south(need_ns), oh_buf_recv_south(need_ns))
         !$acc enter data create(oh_buf_send_north, oh_buf_recv_north, &
         !$acc&                  oh_buf_send_south, oh_buf_recv_south)
         oh_cap_ns = need_ns
      end if

   end subroutine ocean_halo_buffers_ensure_wide