Skip to content

Commit

Permalink
modsubgrid optimization: replace /dx by *dxi, and same for dy, dzf, a…
Browse files Browse the repository at this point in the history
…nd dzh

Small or no difference with -Ofast (which does this by calculating the inverse once).
5% gain with -O3 on BOMEX case.
  • Loading branch information
fjansson committed Aug 18, 2023
1 parent a733474 commit e265904
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 98 deletions.
13 changes: 8 additions & 5 deletions src/modglobal.f90
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,8 @@ module modglobal


real :: ijtot
real, allocatable :: dzf(:) !< thickness of full level
real, allocatable :: dzh(:) !< thickness of half level
real, allocatable :: dzf(:), dzfi(:) !< thickness of full level, and inverse
real, allocatable :: dzh(:), dzhi(:) !< thickness of half level, and inverse
real, allocatable :: zh(:) !< height of half level [m]
real, allocatable :: zf(:) !< height of full level [m]
real :: xsize = -1 !< domain size in x-direction
Expand Down Expand Up @@ -381,8 +381,8 @@ subroutine initglobal


! Create the physical grid variables
allocate(dzf(k1))
allocate(dzh(k1))
allocate(dzf(k1), dzfi(k1))
allocate(dzh(k1), dzhi(k1))
allocate(zh(k1))
allocate(zf(k1))
allocate(delta(k1),deltai(k1))
Expand Down Expand Up @@ -436,6 +436,9 @@ subroutine initglobal
dzh(k) = zf(k) - zf(k-1)
end do

dzfi = 1.0 / dzf
dzhi = 1.0 / dzh

do k=1,k1

delta(k) = (dx*dy*dzf(k))**(1./3.)
Expand Down Expand Up @@ -496,7 +499,7 @@ subroutine initglobal
end subroutine initglobal
!> Clean up when leaving the run
subroutine exitglobal
deallocate(dsv,dzf,dzh,zh,zf,delta,deltai)
deallocate(dsv,dzf,dzh,dzfi,dzhi,zh,zf,delta,deltai)
end subroutine exitglobal

FUNCTION LACZ_GAMMA(X) RESULT(fn_val)
Expand Down
Loading

0 comments on commit e265904

Please sign in to comment.