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).
| Type | Intent | Optional | 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 |
|
| integer, | intent(in), | optional | :: | i1 |
Optional index window (default: the whole array). Used by the
probe’s |
|
| integer, | intent(in), | optional | :: | j0 |
Optional index window (default: the whole array). Used by the
probe’s |
|
| integer, | intent(in), | optional | :: | j1 |
Optional index window (default: the whole array). Used by the
probe’s |
| 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 |
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