chksum_stats_3d Subroutine

public subroutine chksum_stats_3d(arr, nx, ny, nz, stats, i0, i1, j0, j1)

Uses

  • proc~~chksum_stats_3d~~UsesGraph proc~chksum_stats_3d chksum_stats_3d ieee_arithmetic ieee_arithmetic proc~chksum_stats_3d->ieee_arithmetic

Device-side sum/min/max/nonfinite over an explicit-shape 3D field. No present clause: present_or_copyin reads the device copy in production and copies-in host data in unmapped unit tests (same convention as the BT fold’s loud count).

Arguments

Type IntentOptional Attributes Name
real(kind=wp), intent(in) :: arr(nx,ny,nz)
integer, intent(in) :: nx
integer, intent(in) :: ny
integer, intent(in) :: nz
type(chksum_stats_t), intent(out) :: stats
integer, intent(in), optional :: i0

Optional index window (default: the whole array). Used by the probe’s interior mode to exclude the ghost ring.

integer, intent(in), optional :: i1

Optional index window (default: the whole array). Used by the probe’s interior mode to exclude the ghost ring.

integer, intent(in), optional :: j0

Optional index window (default: the whole array). Used by the probe’s interior mode to exclude the ghost ring.

integer, intent(in), optional :: j1

Optional index window (default: the whole array). Used by the probe’s interior mode to exclude the ghost ring.


Called by

proc~~chksum_stats_3d~~CalledByGraph proc~chksum_stats_3d chksum_stats_3d proc~rdb_debug_chksum_3d rdb_debug_chksum_3d proc~rdb_debug_chksum_3d->proc~chksum_stats_3d interface~rdb_debug_chksum rdb_debug_chksum interface~rdb_debug_chksum->proc~rdb_debug_chksum_3d proc~chksum_bt chksum_bt proc~chksum_bt->interface~rdb_debug_chksum proc~chksum_state chksum_state proc~chksum_state->interface~rdb_debug_chksum proc~ocean_dyn_step_split ocean_dyn_step_split proc~ocean_dyn_step_split->proc~chksum_state proc~run_stage_split run_stage_split proc~ocean_dyn_step_split->proc~run_stage_split proc~run_stage_split->proc~chksum_bt proc~run_stage_split->proc~chksum_state proc~engine_step engine_step proc~engine_step->proc~ocean_dyn_step_split

Variables

Type Visibility Attributes Name Initial
integer(kind=int64), private :: bsum
integer, private :: i
integer, private :: ia
integer, private :: ib
integer, private :: j
integer, private :: ja
integer, private :: jb
integer, private :: k
real(kind=wp), private :: mn
real(kind=wp), private :: mx
integer, private :: nf
real(kind=wp), private :: s

Source Code

   subroutine chksum_stats_3d(arr, nx, ny, nz, stats, i0, i1, j0, j1)
      !! Device-side sum/min/max/nonfinite over an explicit-shape 3D
      !! field.  No `present` clause: present_or_copyin reads the device
      !! copy in production and copies-in host data in unmapped unit
      !! tests (same convention as the BT fold's loud count).
      use, intrinsic :: ieee_arithmetic, only: ieee_is_finite
      integer, intent(in) :: nx, ny, nz
      real(wp), intent(in) :: arr(nx, ny, nz)
      type(chksum_stats_t), intent(out) :: stats
      integer, intent(in), optional :: i0, i1, j0, j1
         !! Optional index window (default: the whole array).  Used by the
         !! probe's `interior` mode to exclude the ghost ring.
      real(wp) :: s, mn, mx
      integer(int64) :: bsum
      integer :: nf, i, j, k, ia, ib, ja, jb
      ia = 1
      ib = nx
      ja = 1
      jb = ny
      if (present(i0)) ia = i0
      if (present(i1)) ib = i1
      if (present(j0)) ja = j0
      if (present(j1)) jb = j1

      s = 0.0_wp
      mn = huge(1.0_wp)
      mx = -huge(1.0_wp)
      nf = 0
      bsum = 0_int64
      ! GPU-offload risk: transfer()/popcnt() inside a device region has
      ! NO precedent in this tree.  The intended design accumulates `bsum`
      ! here (device-side, in the same reduction).  If nvfortran cannot
      ! offload transfer/popcnt, this ONE accumulation moves to a
      ! window-cadence host fallback (`!$acc update self(arr)` then a plain
      ! host loop) — a localized one-block change; the FP reductions stay.
      !$acc parallel loop collapse(3) reduction(+:s, nf, bsum) &
      !$acc   reduction(min:mn) reduction(max:mx)
      do k = 1, nz
         do j = ja, jb
            do i = ia, ib
               s = s + arr(i, j, k)
               mn = min(mn, arr(i, j, k))
               mx = max(mx, arr(i, j, k))
               if (.not. ieee_is_finite(arr(i, j, k))) nf = nf + 1
               bsum = bsum + int(popcnt(transfer(arr(i, j, k), 0_int64)), int64)
            end do
         end do
      end do
      stats%total = s
      stats%minv = mn
      stats%maxv = mx
      stats%nonfin = nf
      stats%bits = bsum
   end subroutine chksum_stats_3d