Skip to content

Commit 2d1490f

Browse files
Reduce memory usage in chgres_cube (#766)
Reduce memory by creating separate ESMF fields for the x,y, and z components of the wind, instead of one 4-D ESMF field that holds all three components. Give the two wind conversion routines unique names to prevent confusion. Update to ESMF v8.4
1 parent dca00a3 commit 2d1490f

11 files changed

+434
-155
lines changed

modulefiles/build.hera.gnu.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ load(pathJoin("hpc-mpich", mpich_ver))
2222
netcdf_ver=os.getenv("netcdf_ver") or "4.7.4"
2323
load(pathJoin("netcdf", netcdf_ver))
2424

25-
esmf_ver=os.getenv("esmf_ver") or "8.2.1b04"
25+
esmf_ver=os.getenv("esmf_ver") or "8.4.0b08"
2626
load(pathJoin("esmf", esmf_ver))
2727

2828
bacio_ver=os.getenv("bacio_ver") or "2.4.1"

modulefiles/build.hera.intel.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ load(pathJoin("netcdf", netcdf_ver))
5858
nccmp_ver=os.getenv("nccmp_ver") or "1.8.9.0"
5959
load(pathJoin("nccmp", nccmp_ver))
6060

61-
esmf_ver=os.getenv("esmf_ver") or "8.2.1b04"
61+
esmf_ver=os.getenv("esmf_ver") or "8.4.0b08"
6262
load(pathJoin("esmf", esmf_ver))
6363

6464
nco_ver=os.getenv("nco_ver") or "4.9.1"

modulefiles/build.jet.intel.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ load(pathJoin("netcdf", netcdf_ver))
2828
nccmp_ver=os.getenv("nccmp_ver") or "1.8.9.0"
2929
load(pathJoin("nccmp", nccmp_ver))
3030

31-
esmf_ver=os.getenv("esmf_ver") or "8.2.0"
31+
esmf_ver=os.getenv("esmf_ver") or "8.4.0b08"
3232
load(pathJoin("esmf", esmf_ver))
3333

3434
w3nco_ver=os.getenv("w3nco_ver") or "2.4.1"

modulefiles/build.orion.intel.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ load(pathJoin("netcdf", netcdf_ver))
5555
nccmp_ver=os.getenv("nccmp_ver") or "1.8.9.0"
5656
load(pathJoin("nccmp", nccmp_ver))
5757

58-
esmf_ver=os.getenv("esmf_ver") or "8.2.0"
58+
esmf_ver=os.getenv("esmf_ver") or "8.4.0b08"
5959
load(pathJoin("esmf", esmf_ver))
6060

6161
nco_ver=os.getenv("nco_ver") or "4.9.3"

modulefiles/build.wcoss2.intel.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ load(pathJoin("nco", nco_ver))
7373
setenv("HPC_OPT","/apps/ops/para/libs")
7474
prepend_path("MODULEPATH", "/apps/ops/para/libs/modulefiles/compiler/intel/19.1.3.304")
7575
prepend_path("MODULEPATH", "/apps/ops/para/libs/modulefiles/mpi/intel/19.1.3.304/cray-mpich/8.1.7")
76-
esmf_ver=os.getenv("esmf_ver") or "8.2.1b04"
76+
esmf_ver=os.getenv("esmf_ver") or "8.4.0b08"
7777
load(pathJoin("esmf", esmf_ver))
7878

7979
whatis("Description: UFS_UTILS build environment")

sorc/chgres_cube.fd/atm_input_data.F90

+65-29
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,9 @@ module atm_input_data
5454

5555
type(esmf_field), public :: u_input_grid !< u/v wind at grid
5656
type(esmf_field), public :: v_input_grid !< box center
57-
type(esmf_field), public :: wind_input_grid !< 3-component wind
57+
type(esmf_field), public :: xwind_input_grid !< x-component wind
58+
type(esmf_field), public :: ywind_input_grid !< y-component wind
59+
type(esmf_field), public :: zwind_input_grid !< z-component wind
5860
type(esmf_field), allocatable, public :: tracers_input_grid(:) !< tracers
5961

6062
integer, public :: lev_input !< number of atmospheric layers
@@ -64,7 +66,7 @@ module atm_input_data
6466

6567
public :: read_input_atm_data
6668
public :: cleanup_input_atm_data
67-
public :: convert_winds
69+
public :: convert_winds_to_xyz
6870

6971
contains
7072

@@ -150,15 +152,6 @@ subroutine init_atm_esmf_fields
150152

151153
print*,"- INITIALIZE ATMOSPHERIC ESMF FIELDS."
152154

153-
print*,"- CALL FieldCreate FOR INPUT GRID 3-D WIND."
154-
wind_input_grid = ESMF_FieldCreate(input_grid, &
155-
typekind=ESMF_TYPEKIND_R8, &
156-
staggerloc=ESMF_STAGGERLOC_CENTER, &
157-
ungriddedLBound=(/1,1/), &
158-
ungriddedUBound=(/lev_input,3/), rc=rc)
159-
if(ESMF_logFoundError(rcToCheck=rc,msg=ESMF_LOGERR_PASSTHRU,line=__LINE__,file=__FILE__)) &
160-
call error_handler("IN FieldCreate", rc)
161-
162155
print*,"- CALL FieldCreate FOR INPUT GRID SURFACE PRESSURE."
163156
ps_input_grid = ESMF_FieldCreate(input_grid, &
164157
typekind=ESMF_TYPEKIND_R8, &
@@ -173,6 +166,33 @@ subroutine init_atm_esmf_fields
173166
if(ESMF_logFoundError(rcToCheck=rc,msg=ESMF_LOGERR_PASSTHRU,line=__LINE__,file=__FILE__)) &
174167
call error_handler("IN FieldCreate", rc)
175168

169+
print*,"- CALL FieldCreate FOR INPUT GRID xwind."
170+
xwind_input_grid = ESMF_FieldCreate(input_grid, &
171+
typekind=ESMF_TYPEKIND_R8, &
172+
staggerloc=ESMF_STAGGERLOC_CENTER, &
173+
ungriddedLBound=(/1/), &
174+
ungriddedUBound=(/lev_input/), rc=rc)
175+
if(ESMF_logFoundError(rcToCheck=rc,msg=ESMF_LOGERR_PASSTHRU,line=__LINE__,file=__FILE__)) &
176+
call error_handler("IN FieldCreate", rc)
177+
178+
print*,"- CALL FieldCreate FOR INPUT GRID ywind."
179+
ywind_input_grid = ESMF_FieldCreate(input_grid, &
180+
typekind=ESMF_TYPEKIND_R8, &
181+
staggerloc=ESMF_STAGGERLOC_CENTER, &
182+
ungriddedLBound=(/1/), &
183+
ungriddedUBound=(/lev_input/), rc=rc)
184+
if(ESMF_logFoundError(rcToCheck=rc,msg=ESMF_LOGERR_PASSTHRU,line=__LINE__,file=__FILE__)) &
185+
call error_handler("IN FieldCreate", rc)
186+
187+
print*,"- CALL FieldCreate FOR INPUT GRID zwind."
188+
zwind_input_grid = ESMF_FieldCreate(input_grid, &
189+
typekind=ESMF_TYPEKIND_R8, &
190+
staggerloc=ESMF_STAGGERLOC_CENTER, &
191+
ungriddedLBound=(/1/), &
192+
ungriddedUBound=(/lev_input/), rc=rc)
193+
if(ESMF_logFoundError(rcToCheck=rc,msg=ESMF_LOGERR_PASSTHRU,line=__LINE__,file=__FILE__)) &
194+
call error_handler("IN FieldCreate", rc)
195+
176196
print*,"- CALL FieldCreate FOR INPUT GRID TEMPERATURE."
177197
temp_input_grid = ESMF_FieldCreate(input_grid, &
178198
typekind=ESMF_TYPEKIND_R8, &
@@ -408,7 +428,7 @@ subroutine read_input_atm_gfs_sigio_file(localpet)
408428
! Convert from 2-d to 3-d component winds.
409429
!---------------------------------------------------------------------------
410430

411-
call convert_winds
431+
call convert_winds_to_xyz
412432

413433
!---------------------------------------------------------------------------
414434
! Compute 3-d pressure from 'ak' and 'bk'.
@@ -668,7 +688,7 @@ subroutine read_input_atm_gfs_gaussian_nemsio_file(localpet)
668688
! Convert from 2-d to 3-d component winds.
669689
!---------------------------------------------------------------------------
670690

671-
call convert_winds
691+
call convert_winds_to_xyz
672692

673693
!---------------------------------------------------------------------------
674694
! Compute 3-d pressure from 'ak' and 'bk'.
@@ -933,7 +953,7 @@ subroutine read_input_atm_gaussian_nemsio_file(localpet)
933953
! Convert from 2-d to 3-d component winds.
934954
!---------------------------------------------------------------------------
935955

936-
call convert_winds
956+
call convert_winds_to_xyz
937957

938958
!---------------------------------------------------------------------------
939959
! Compute 3-d pressure. Mid-layer and surface pressure are computed
@@ -1217,7 +1237,7 @@ subroutine read_input_atm_restart_file(localpet)
12171237
! Convert from 2-d to 3-d cartesian winds.
12181238
!---------------------------------------------------------------------------
12191239

1220-
call convert_winds
1240+
call convert_winds_to_xyz
12211241

12221242
!---------------------------------------------------------------------------
12231243
! Compute pressures
@@ -1587,7 +1607,7 @@ subroutine read_input_atm_gaussian_netcdf_file(localpet)
15871607
! Convert from 2-d to 3-d cartesian winds.
15881608
!---------------------------------------------------------------------------
15891609

1590-
call convert_winds
1610+
call convert_winds_to_xyz
15911611

15921612
!---------------------------------------------------------------------------
15931613
! Compute pressure.
@@ -1893,7 +1913,7 @@ subroutine read_input_atm_tiled_history_file(localpet)
18931913
! Convert from 2-d to 3-d cartesian winds.
18941914
!---------------------------------------------------------------------------
18951915

1896-
call convert_winds
1916+
call convert_winds_to_xyz
18971917

18981918
!---------------------------------------------------------------------------
18991919
! Compute pressure.
@@ -2854,7 +2874,7 @@ subroutine read_input_atm_grib2_file(localpet)
28542874
! Convert from 2-d to 3-d component winds.
28552875
!---------------------------------------------------------------------------
28562876

2857-
call convert_winds
2877+
call convert_winds_to_xyz
28582878

28592879
!---------------------------------------------------------------------------
28602880
! Convert dpdt to dzdt if needed
@@ -3089,25 +3109,39 @@ end subroutine read_winds
30893109
!> Convert winds from 2-d to 3-d components.
30903110
!!
30913111
!! @author George Gayno NCEP/EMC
3092-
subroutine convert_winds
3112+
subroutine convert_winds_to_xyz
30933113

30943114
implicit none
30953115

3096-
integer :: clb(4), cub(4)
3116+
integer :: clb(3), cub(3)
30973117
integer :: i, j, k, rc
30983118

30993119
real(esmf_kind_r8) :: latrad, lonrad
3100-
real(esmf_kind_r8), pointer :: windptr(:,:,:,:)
3120+
real(esmf_kind_r8), pointer :: xptr(:,:,:)
3121+
real(esmf_kind_r8), pointer :: yptr(:,:,:)
3122+
real(esmf_kind_r8), pointer :: zptr(:,:,:)
31013123
real(esmf_kind_r8), pointer :: uptr(:,:,:)
31023124
real(esmf_kind_r8), pointer :: vptr(:,:,:)
31033125
real(esmf_kind_r8), pointer :: latptr(:,:)
31043126
real(esmf_kind_r8), pointer :: lonptr(:,:)
31053127

3106-
print*,"- CALL FieldGet FOR 3-D WIND."
3107-
call ESMF_FieldGet(wind_input_grid, &
3128+
print*,"- CALL FieldGet FOR xwind."
3129+
call ESMF_FieldGet(xwind_input_grid, &
31083130
computationalLBound=clb, &
31093131
computationalUBound=cub, &
3110-
farrayPtr=windptr, rc=rc)
3132+
farrayPtr=xptr, rc=rc)
3133+
if(ESMF_logFoundError(rcToCheck=rc,msg=ESMF_LOGERR_PASSTHRU,line=__LINE__,file=__FILE__)) &
3134+
call error_handler("IN FieldGet", rc)
3135+
3136+
print*,"- CALL FieldGet FOR ywind."
3137+
call ESMF_FieldGet(ywind_input_grid, &
3138+
farrayPtr=yptr, rc=rc)
3139+
if(ESMF_logFoundError(rcToCheck=rc,msg=ESMF_LOGERR_PASSTHRU,line=__LINE__,file=__FILE__)) &
3140+
call error_handler("IN FieldGet", rc)
3141+
3142+
print*,"- CALL FieldGet FOR zwind."
3143+
call ESMF_FieldGet(zwind_input_grid, &
3144+
farrayPtr=zptr, rc=rc)
31113145
if(ESMF_logFoundError(rcToCheck=rc,msg=ESMF_LOGERR_PASSTHRU,line=__LINE__,file=__FILE__)) &
31123146
call error_handler("IN FieldGet", rc)
31133147

@@ -3140,17 +3174,17 @@ subroutine convert_winds
31403174
latrad = latptr(i,j) * acos(-1.) / 180.0
31413175
lonrad = lonptr(i,j) * acos(-1.) / 180.0
31423176
do k = clb(3), cub(3)
3143-
windptr(i,j,k,1) = uptr(i,j,k) * cos(lonrad) - vptr(i,j,k) * sin(latrad) * sin(lonrad)
3144-
windptr(i,j,k,2) = uptr(i,j,k) * sin(lonrad) + vptr(i,j,k) * sin(latrad) * cos(lonrad)
3145-
windptr(i,j,k,3) = vptr(i,j,k) * cos(latrad)
3177+
xptr(i,j,k) = uptr(i,j,k) * cos(lonrad) - vptr(i,j,k) * sin(latrad) * sin(lonrad)
3178+
yptr(i,j,k) = uptr(i,j,k) * sin(lonrad) + vptr(i,j,k) * sin(latrad) * cos(lonrad)
3179+
zptr(i,j,k) = vptr(i,j,k) * cos(latrad)
31463180
enddo
31473181
enddo
31483182
enddo
31493183

31503184
call ESMF_FieldDestroy(u_input_grid, rc=rc)
31513185
call ESMF_FieldDestroy(v_input_grid, rc=rc)
31523186

3153-
end subroutine convert_winds
3187+
end subroutine convert_winds_to_xyz
31543188

31553189
!> Compute grid rotation angle for non-latlon grids.
31563190
!!
@@ -3257,7 +3291,9 @@ subroutine cleanup_input_atm_data
32573291
call ESMF_FieldDestroy(pres_input_grid, rc=rc)
32583292
call ESMF_FieldDestroy(dzdt_input_grid, rc=rc)
32593293
call ESMF_FieldDestroy(temp_input_grid, rc=rc)
3260-
call ESMF_FieldDestroy(wind_input_grid, rc=rc)
3294+
call ESMF_FieldDestroy(xwind_input_grid, rc=rc)
3295+
call ESMF_FieldDestroy(ywind_input_grid, rc=rc)
3296+
call ESMF_FieldDestroy(zwind_input_grid, rc=rc)
32613297
call ESMF_FieldDestroy(ps_input_grid, rc=rc)
32623298

32633299
do n = 1, num_tracers_input

0 commit comments

Comments
 (0)