function compute_total_h(h_layer, areaT, nghost) result(total)
!! `Σ h_layer(i,j,k)·areaT(i,j)` over PHYSICAL cells (ghosts
!! excluded). Explicit OpenACC reduction — the `sum()` intrinsic on
!! a present-mapped array silently runs host-side under NVHPC
!! non-managed mode and returns the stale host shadow.
real(wp), intent(in) :: h_layer(:, :, :)
real(wp), intent(in) :: areaT(:, :)
integer, intent(in) :: nghost
real(wp) :: total
real(wp) :: acc
integer :: i, j, k, nx, ny, nz, i_lo, i_hi, j_lo, j_hi
nx = min(size(h_layer, 1), size(areaT, 1))
ny = min(size(h_layer, 2), size(areaT, 2))
nz = size(h_layer, 3)
i_lo = nghost + 1
i_hi = nx - nghost
j_lo = nghost + 1
j_hi = ny - nghost
acc = 0.0_wp
!$acc parallel loop collapse(3) reduction(+:acc) present(h_layer, areaT)
do k = 1, nz
do j = j_lo, j_hi
do i = i_lo, i_hi
acc = acc + h_layer(i, j, k)*areaT(i, j)
end do
end do
end do
total = acc
end function compute_total_h