Skip to content

Commit

Permalink
Move underflow code into separate loops
Browse files Browse the repository at this point in the history
  Moved the new user-controlled tracer underflow code into separate loops, in
response to the reviews of this initial commit, in the hopes that this will
provide better computational performance.  All answers are bitwise identical.
  • Loading branch information
Hallberg-NOAA authored and marshallward committed Jun 6, 2022
1 parent c35da37 commit 4288d41
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 9 deletions.
8 changes: 7 additions & 1 deletion src/tracer/MOM_lateral_boundary_diffusion.F90
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,6 @@ subroutine lateral_boundary_diffusion(G, GV, US, h, Coef_x, Coef_y, dt, Reg, CS)
if (G%mask2dT(i,j)>0.) then
tracer%t(i,j,k) = tracer%t(i,j,k) + (( (uFlx(I-1,j,k)-uFlx(I,j,k)) ) + ( (vFlx(i,J-1,k)-vFlx(i,J,k) ) ))* &
G%IareaT(i,j) / ( h(i,j,k) + GV%H_subroundoff )
if (abs(tracer%t(i,j,k)) < tracer%conc_underflow) tracer%t(i,j,k) = 0.0

if (tracer%id_lbdxy_conc > 0 .or. tracer%id_lbdxy_cont > 0 .or. tracer%id_lbdxy_cont_2d > 0 ) then
tendency(i,j,k) = ((uFlx(I-1,j,k)-uFlx(I,j,k)) + (vFlx(i,J-1,k)-vFlx(i,J,k))) * &
Expand All @@ -232,6 +231,13 @@ subroutine lateral_boundary_diffusion(G, GV, US, h, Coef_x, Coef_y, dt, Reg, CS)
endif
enddo ; enddo ; enddo

! Do user controlled underflow of the tracer concentrations.
if (tracer%conc_underflow > 0.0) then
do k=1,GV%ke ; do j=G%jsc,G%jec ; do i=G%isc,G%iec
if (abs(tracer%t(i,j,k)) < tracer%conc_underflow) tracer%t(i,j,k) = 0.0
enddo ; enddo ; enddo
endif

if (CS%debug) then
call hchksum(tracer%t, "after LBD "//tracer%name,G%HI)
! tracer (native grid) integrated tracer amounts before and after LBD
Expand Down
7 changes: 7 additions & 0 deletions src/tracer/MOM_neutral_diffusion.F90
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,13 @@ subroutine neutral_diffusion(G, GV, h, Coef_x, Coef_y, dt, Reg, US, CS)
endif
enddo ; enddo

! Do user controlled underflow of the tracer concentrations.
if (tracer%conc_underflow > 0.0) then
do k=1,GV%ke ; do j=G%jsc,G%jec ; do i=G%isc,G%iec
if (abs(tracer%t(i,j,k)) < tracer%conc_underflow) tracer%t(i,j,k) = 0.0
enddo ; enddo ; enddo
endif

! Diagnose vertically summed zonal flux, giving zonal tracer transport from ndiff.
! Note sign corresponds to downgradient flux convention.
if (tracer%id_dfx_2d > 0) then
Expand Down
19 changes: 14 additions & 5 deletions src/tracer/MOM_tracer_advect.F90
Original file line number Diff line number Diff line change
Expand Up @@ -650,7 +650,6 @@ subroutine advect_x(Tr, hprev, uhr, uh_neglect, OBC, domore_u, ntr, Idt, &
if (Ihnew(i) > 0.0) then
Tr(m)%t(i,j,k) = (Tr(m)%t(i,j,k) * hlst(i) - &
(flux_x(I,j,m) - flux_x(I-1,j,m))) * Ihnew(i)
if (abs(Tr(m)%t(i,j,k)) < Tr(m)%conc_underflow) Tr(m)%t(i,j,k) = 0.0
endif
endif
enddo
Expand All @@ -671,10 +670,14 @@ subroutine advect_x(Tr, hprev, uhr, uh_neglect, OBC, domore_u, ntr, Idt, &

enddo

endif

endif ; enddo ! End of j-loop.

enddo ! End of j-loop.
! Do user controlled underflow of the tracer concentrations.
do m=1,ntr ; if (Tr(m)%conc_underflow > 0.0) then
do j=js,je ; do i=is,ie
if (abs(Tr(m)%t(i,j,k)) < Tr(m)%conc_underflow) Tr(m)%t(i,j,k) = 0.0
enddo ; enddo
endif ; enddo

! compute ad2d_x diagnostic outside above j-loop so as to make the summation ordered when OMP is active.

Expand Down Expand Up @@ -1029,7 +1032,6 @@ subroutine advect_y(Tr, hprev, vhr, vh_neglect, OBC, domore_v, ntr, Idt, &
do i=is,ie ; if (do_i(i,j)) then
Tr(m)%t(i,j,k) = (Tr(m)%t(i,j,k) * hlst(i) - &
(flux_y(i,m,J) - flux_y(i,m,J-1))) * Ihnew(i)
if (abs(Tr(m)%t(i,j,k)) < Tr(m)%conc_underflow) Tr(m)%t(i,j,k) = 0.0
endif ; enddo

! diagnostics
Expand All @@ -1049,6 +1051,13 @@ subroutine advect_y(Tr, hprev, vhr, vh_neglect, OBC, domore_v, ntr, Idt, &
enddo
endif ; enddo ! End of j-loop.

! Do user controlled underflow of the tracer concentrations.
do m=1,ntr ; if (Tr(m)%conc_underflow > 0.0) then
do j=js,je ; do i=is,ie
if (abs(Tr(m)%t(i,j,k)) < Tr(m)%conc_underflow) Tr(m)%t(i,j,k) = 0.0
enddo ; enddo
endif ; enddo

! compute ad2d_y diagnostic outside above j-loop so as to make the summation ordered when OMP is active.

!$OMP ordered
Expand Down
20 changes: 17 additions & 3 deletions src/tracer/MOM_tracer_hor_diff.F90
Original file line number Diff line number Diff line change
Expand Up @@ -507,12 +507,19 @@ subroutine tracer_hordiff(h, dt, MEKE, VarMix, G, GV, US, CS, Reg, tv, do_online
enddo ; enddo ; endif
do j=js,je ; do i=is,ie
Reg%Tr(m)%t(i,j,k) = Reg%Tr(m)%t(i,j,k) + dTr(i,j)
if (abs(Reg%Tr(m)%t(i,j,k)) < Reg%Tr(m)%conc_underflow) Reg%Tr(m)%t(i,j,k) = 0.0
enddo ; enddo
enddo

enddo ! End of k loop.

! Do user controlled underflow of the tracer concentrations.
do m=1,ntr ; if (Reg%Tr(m)%conc_underflow > 0.0) then
!$OMP parallel do default(shared)
do k=1,nz ; do j=js,je ; do i=is,ie
if (abs(Reg%Tr(m)%t(i,j,k)) < Reg%Tr(m)%conc_underflow) Reg%Tr(m)%t(i,j,k) = 0.0
enddo ; enddo ; enddo
endif ; enddo

enddo ! End of "while" loop.

endif ! endif for CS%use_neutral_diffusion
Expand Down Expand Up @@ -1399,16 +1406,23 @@ subroutine tracer_epipycnal_ML_diff(h, dt, Tr, ntr, khdt_epi_x, khdt_epi_y, G, &
endif
enddo
endif ; enddo ; enddo
!$OMP parallel do default(none) shared(PEmax_kRho,is,ie,js,je,G,h,Tr,tr_flux_conv,m)
!$OMP parallel do default(shared)
do k=1,PEmax_kRho ; do j=js,je ; do i=is,ie
if ((G%mask2dT(i,j) > 0.0) .and. (h(i,j,k) > 0.0)) then
Tr(m)%t(i,j,k) = Tr(m)%t(i,j,k) + tr_flux_conv(i,j,k) / &
(h(i,j,k)*G%areaT(i,j))
if (abs(Tr(m)%t(i,j,k)) < Tr(m)%conc_underflow) Tr(m)%t(i,j,k) = 0.0
tr_flux_conv(i,j,k) = 0.0
endif
enddo ; enddo ; enddo

! Do user controlled underflow of the tracer concentrations.
if (Tr(m)%conc_underflow > 0.0) then
!$OMP parallel do default(shared)
do k=1,nz ; do j=js,je ; do i=is,ie
if (abs(Tr(m)%t(i,j,k)) < Tr(m)%conc_underflow) Tr(m)%t(i,j,k) = 0.0
enddo ; enddo ; enddo
endif

enddo ! Loop over tracers
enddo ! Loop over iterations

Expand Down

0 comments on commit 4288d41

Please sign in to comment.