Skip to content

Commit c6bd685

Browse files
marshallwardHallberg-NOAA
authored andcommitted
Horvisc: Reorder if-blocks in rescaled Kh
This reorders several if-blocks inside of a large do-loop of horizontal_viscosity() associated with rescaled Kh. This should help performance, but will also make it easier to move these loops to GPU.
1 parent f9e1a84 commit c6bd685

1 file changed

Lines changed: 51 additions & 27 deletions

File tree

src/parameterizations/lateral/MOM_hor_visc.F90

Lines changed: 51 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1513,8 +1513,6 @@ subroutine horizontal_viscosity(u, v, h, uh, vh, diffu, diffv, MEKE, VarMix, G,
15131513
endif ; endif
15141514
endif
15151515

1516-
meke_res_fn = 1.
1517-
15181516
if ((CS%Smagorinsky_Kh) .or. (CS%Smagorinsky_Ah)) then
15191517
do J=js-1,Jeq ; do I=is-1,Ieq
15201518
sh_xy_sq = sh_xy(I,J)**2
@@ -1621,40 +1619,55 @@ subroutine horizontal_viscosity(u, v, h, uh, vh, diffu, diffv, MEKE, VarMix, G,
16211619

16221620
! All viscosity contributions above are subject to resolution scaling
16231621

1624-
! NOTE: The following do-block can be decomposed and vectorized after the
1625-
! stack size has been reduced.
1626-
do J=js-1,Jeq ; do I=is-1,Ieq
1627-
if (rescale_Kh) &
1622+
if (rescale_Kh) then
1623+
do J=js-1,Jeq ; do I=is-1,Ieq
16281624
Kh(I,J) = VarMix%Res_fn_q(I,J) * Kh(I,J)
1625+
enddo ; enddo
1626+
endif
16291627

1630-
if (CS%res_scale_MEKE) &
1631-
meke_res_fn = VarMix%Res_fn_q(I,J)
1632-
1628+
if (legacy_bound) then
16331629
! Older method of bounding for stability
1634-
if (legacy_bound) &
1630+
do J=js-1,Jeq ; do I=is-1,Ieq
16351631
Kh(I,J) = min(Kh(I,J), CS%Kh_Max_xy(I,J))
1632+
enddo ; enddo
1633+
endif
16361634

1635+
do J=js-1,Jeq ; do I=is-1,Ieq
16371636
Kh(I,J) = max(Kh(I,J), CS%Kh_bg_min) ! Place a floor on the viscosity, if desired.
1637+
enddo ; enddo
1638+
1639+
if (use_MEKE_Ku .and. .not. CS%EY24_EBT_BS) then
1640+
if (use_kh_struct) then
1641+
do J=js-1,Jeq ; do I=is-1,Ieq
1642+
meke_res_fn = 1.
1643+
if (CS%res_scale_MEKE) meke_res_fn = VarMix%Res_fn_q(I,J)
16381644

1639-
if (use_MEKE_Ku .and. .not. CS%EY24_EBT_BS) then
1640-
! *Add* the MEKE contribution (might be negative)
1641-
if (use_kh_struct) then
16421645
Kh(I,J) = Kh(I,J) + 0.25*( ((MEKE%Ku(i,j)*VarMix%BS_struct(i,j,k)) + &
16431646
(MEKE%Ku(i+1,j+1)*VarMix%BS_struct(i+1,j+1,k))) + &
16441647
((MEKE%Ku(i+1,j)*VarMix%BS_struct(i+1,j,k)) + &
16451648
(MEKE%Ku(i,j+1)*VarMix%BS_struct(i,j+1,k))) ) * meke_res_fn
1646-
else
1647-
Kh(I,J) = Kh(I,J) + 0.25*( (MEKE%Ku(i,j) + &
1648-
MEKE%Ku(i+1,j+1)) + &
1649+
enddo ; enddo
1650+
else
1651+
do J=js-1,Jeq ; do I=is-1,Ieq
1652+
meke_res_fn = 1.
1653+
if (CS%res_scale_MEKE) meke_res_fn = VarMix%Res_fn_q(I,J)
1654+
1655+
Kh(I,J) = Kh(I,J) + 0.25 * ( &
1656+
(MEKE%Ku(i,j) + MEKE%Ku(i+1,j+1)) + &
16491657
(MEKE%Ku(i+1,j) + &
16501658
MEKE%Ku(i,j+1)) ) * meke_res_fn
1651-
endif
1659+
enddo ; enddo
16521660
endif
1661+
endif
16531662

1654-
if (CS%anisotropic) &
1655-
! *Add* the shear component of anisotropic viscosity
1656-
Kh(I,J) = Kh(I,J) + CS%Kh_aniso * CS%n1n2_q(I,J)**2
1663+
if (CS%anisotropic) then
1664+
! *Add* the shear component of anisotropic viscosity
1665+
do J=js-1,Jeq ; do I=is-1,Ieq
1666+
Kh(I,J) = Kh(I,J) + CS%Kh_aniso * CS%n1n2_q(I,J)**2
1667+
enddo ; enddo
1668+
endif
16571669

1670+
do J=js-1,Jeq ; do I=is-1,Ieq
16581671
! Newer method of bounding for stability
16591672
if ((CS%better_bound_Kh) .and. (CS%better_bound_Ah)) then
16601673
visc_bound_rem(I,J) = 1.0
@@ -1668,23 +1681,34 @@ subroutine horizontal_viscosity(u, v, h, uh, vh, diffu, diffv, MEKE, VarMix, G,
16681681
elseif (CS%better_bound_Kh) then
16691682
Kh(I,J) = min(Kh(I,J), hrat_min(I,J) * CS%Kh_Max_xy(I,J))
16701683
endif
1684+
enddo ; enddo
16711685

1686+
if (CS%use_Leithy) then
16721687
! Leith+E doesn't recompute Kh at q points, it just interpolates it from h to q points
1673-
if (CS%use_Leithy) then
1688+
do J=js-1,Jeq ; do I=is-1,Ieq
16741689
Kh(I,J) = 0.25 * ((Kh_h(i,j,k) + Kh_h(i+1,j+1,k)) + (Kh_h(i,j+1,k) + Kh_h(i+1,j,k)))
1675-
end if
1690+
enddo ; enddo
1691+
end if
16761692

1677-
if (CS%id_Kh_q>0 .or. CS%debug) &
1693+
if (CS%id_Kh_q > 0 .or. CS%debug) then
1694+
do J=js-1,Jeq ; do I=is-1,Ieq
16781695
Kh_q(I,J,k) = Kh(I,J)
1696+
enddo ; enddo
1697+
endif
16791698

1680-
if (CS%id_vort_xy_q>0) &
1699+
if (CS%id_vort_xy_q > 0) then
1700+
do J=js-1,Jeq ; do I=is-1,Ieq
16811701
vort_xy_q(I,J,k) = vort_xy(I,J)
1702+
enddo ; enddo
1703+
endif
16821704

1683-
if (CS%id_sh_xy_q>0) &
1705+
if (CS%id_sh_xy_q > 0) then
1706+
do J=js-1,Jeq ; do I=is-1,Ieq
16841707
sh_xy_q(I,J,k) = sh_xy(I,J)
1685-
enddo ; enddo
1708+
enddo ; enddo
1709+
endif
16861710

1687-
if ( .not. CS%use_Leithy) then
1711+
if (.not. CS%use_Leithy) then
16881712
do J=js-1,Jeq ; do I=is-1,Ieq
16891713
str_xy(I,J) = -Kh(I,J) * sh_xy(I,J)
16901714
enddo ; enddo

0 commit comments

Comments
 (0)