Skip to content

Commit 0b9cd04

Browse files
authored
Merge pull request #3666 from ekluzek/decomp_mpi_scan_move_to_b4b
b4b: Move the changes to initialize the task decomposition from mpi_scan to main development
2 parents 445f78d + fa8b40d commit 0b9cd04

13 files changed

Lines changed: 993 additions & 252 deletions

File tree

cime_config/testdefs/ExpectedTestFails.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -293,10 +293,10 @@
293293

294294
<!-- decomp_init test list-->
295295

296-
<test name="SMS_Ln1_PL.mpasa15_mpasa15.I2000Clm45Sp.derecho_intel.clm-run_self_tests">
296+
<test name="SMS_Ln1_PL.mpasa3p75_mpasa3p75_mt13.I2000Clm45Sp.derecho_intel.clm-for_testing_fastsetup_bypassrun--clm-mpasa3p75">
297297
<phase name="RUN">
298298
<status>FAIL</status>
299-
<issue>#3316</issue>
299+
<issue>#4107</issue>
300300
</phase>
301301
</test>
302302

cime_config/testdefs/testlist_clm.xml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4545,6 +4545,7 @@
45454545
<test name="SMS_Ln1" grid="mpasa3p75_mpasa3p75_mt13" compset="I2000Clm45Sp" testmods="clm-for_testing_fastsetup_bypassrun--clm-mpasa3p75">
45464546
<machines>
45474547
<machine name="derecho" compiler="intel" category="uhr_decomp_init"/>
4548+
<machine name="derecho" compiler="intel" category="ctsm_sci"/>
45484549
</machines>
45494550
<options>
45504551
<option name="wallclock">0:15:00</option>
@@ -4556,7 +4557,7 @@
45564557
<machine name="derecho" compiler="intel" category="uhr_decomp_init"/>
45574558
</machines>
45584559
<options>
4559-
<option name="wallclock">1:00:00</option>
4560+
<option name="wallclock">0:15:00</option>
45604561
<option name="comment">Initialization test for mpasa3p75 "Large" layout</option>
45614562
</options>
45624563
</test>
@@ -4565,7 +4566,7 @@
45654566
<machine name="derecho" compiler="intel" category="uhr_decomp_init"/>
45664567
</machines>
45674568
<options>
4568-
<option name="wallclock">1:00:00</option>
4569+
<option name="wallclock">0:15:00</option>
45694570
<option name="comment">Initialization test for mpasa3p75 with "Large" high-memory layout with high memory by only using 80 processors per node</option>
45704571
</options>
45714572
</test>

src/cpl/share_esmf/lnd_set_decomp_and_domain.F90

Lines changed: 60 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ subroutine lnd_set_decomp_and_domain_from_readmesh(driver, vm, meshfile_lnd, mes
6969
! local variables
7070
type(ESMF_Mesh) :: mesh_maskinput
7171
type(ESMF_Mesh) :: mesh_lndinput
72-
type(ESMF_DistGrid) :: distgrid_ctsm
72+
type(ESMF_DistGrid) :: distgrid_ctsm ! This appears to be local but is used later in lnd_import_export
7373
type(ESMF_Field) :: field_lnd
7474
type(ESMF_Field) :: field_ctsm
7575
type(ESMF_RouteHandle) :: rhandle_lnd2ctsm
@@ -84,7 +84,7 @@ subroutine lnd_set_decomp_and_domain_from_readmesh(driver, vm, meshfile_lnd, mes
8484
integer , pointer :: gindex_ctsm(:) ! global index space for land and ocean points
8585
integer , pointer :: lndmask_glob(:)
8686
real(r8) , pointer :: lndfrac_glob(:)
87-
real(r8) , pointer :: lndfrac_loc_input(:)
87+
real(r8) , pointer :: lndfrac_loc_input(:) => null()
8888
real(r8) , pointer :: dataptr1d(:)
8989
!-------------------------------------------------------------------------------
9090

@@ -149,6 +149,7 @@ subroutine lnd_set_decomp_and_domain_from_readmesh(driver, vm, meshfile_lnd, mes
149149
end if
150150
call t_stopf('lnd_set_decomp_and_domain_from_readmesh: ESMF mesh')
151151
call t_startf ('lnd_set_decomp_and_domain_from_readmesh: final')
152+
call t_startf ('lnd_set_decomp_and_domain_from_readmesh: decomp_init')
152153

153154
! Determine lnd decomposition that will be used by ctsm from lndmask_glob
154155
call t_startf ('decompInit_lnd')
@@ -163,7 +164,7 @@ subroutine lnd_set_decomp_and_domain_from_readmesh(driver, vm, meshfile_lnd, mes
163164
! Get JUST gridcell processor bounds
164165
! Remaining bounds (landunits, columns, patches) will be set after calling decompInit_glcp
165166
! so get_proc_bounds is called twice and the gridcell information is just filled in twice
166-
call get_proc_bounds(bounds)
167+
call get_proc_bounds(bounds, only_gridcell=.true.)
167168
begg = bounds%begg
168169
endg = bounds%endg
169170

@@ -197,8 +198,10 @@ subroutine lnd_set_decomp_and_domain_from_readmesh(driver, vm, meshfile_lnd, mes
197198
gindex_ctsm(n) = gindex_ocn(n-nlnd)
198199
end if
199200
end do
201+
call t_stopf ('lnd_set_decomp_and_domain_from_readmesh: decomp_init')
200202

201203
! Generate a new mesh on the gindex decomposition
204+
! NOTE: The distgrid_ctsm will be used later in lnd_import_export, even though it appears to just be local
202205
distGrid_ctsm = ESMF_DistGridCreate(arbSeqIndexList=gindex_ctsm, rc=rc)
203206
if (ChkErr(rc,__LINE__,u_FILE_u)) return
204207
mesh_ctsm = ESMF_MeshCreate(mesh_lndinput, elementDistGrid=distgrid_ctsm, rc=rc)
@@ -238,6 +241,9 @@ subroutine lnd_set_decomp_and_domain_from_readmesh(driver, vm, meshfile_lnd, mes
238241
n = 1 + (g - begg)
239242
ldomain%frac(g) = dataptr1d(n)
240243
end do
244+
! Destroy the memory for the above ESMF objects that can be released
245+
call from_readmesh_destroy_esmf_objects(rc)
246+
if (chkerr(rc,__LINE__,u_FILE_u)) return
241247
else
242248
! ASSUME that land fraction is identical to land mask in this case
243249
do g = begg, endg
@@ -256,12 +262,57 @@ subroutine lnd_set_decomp_and_domain_from_readmesh(driver, vm, meshfile_lnd, mes
256262
end if
257263

258264
! Deallocate local pointer memory
259-
deallocate(gindex_lnd)
260-
deallocate(gindex_ocn)
261-
deallocate(gindex_ctsm)
265+
call from_readmesh_dealloc( )
262266

263267
call t_stopf('lnd_set_decomp_and_domain_from_readmesh: final')
264268

269+
270+
!===============================================================================
271+
! Internal subroutines for this subroutine
272+
contains
273+
!===============================================================================
274+
275+
276+
subroutine from_readmesh_destroy_esmf_objects(rc)
277+
use ESMF, only : ESMF_FieldRedistRelease, ESMF_DistGridDestroy, ESMF_FieldDestroy, ESMF_MeshDestroy
278+
integer, intent(out) :: rc ! ESMF return code to indicate deallocate was successful
279+
280+
logical :: no_esmf_garbage = .true. ! If .true. release all ESMF data (which can be problematic if referenced again)
281+
282+
rc = ESMF_SUCCESS
283+
284+
! Destroy or release all of the ESMF objects
285+
call ESMF_FieldRedistRelease( rhandle_lnd2ctsm, noGarbage=no_esmf_garbage, rc=rc)
286+
if (chkerr(rc,__LINE__,u_FILE_u)) return
287+
!--------------------------------------------------------------------------
288+
! NOTE: We can't destroy the distgrid -- because it will be used later
289+
! As such we don't do the following... EBK 08/01/2025
290+
!call ESMF_DistGridDestroy( distgrid_ctsm, rc=rc)
291+
!if (chkerr(rc,__LINE__,u_FILE_u)) return
292+
!--------------------------------------------------------------------------
293+
call ESMF_FieldDestroy( field_lnd, noGarbage=no_esmf_garbage, rc=rc)
294+
if (chkerr(rc,__LINE__,u_FILE_u)) return
295+
call ESMF_FieldDestroy( field_ctsm, noGarbage=no_esmf_garbage, rc=rc)
296+
if (chkerr(rc,__LINE__,u_FILE_u)) return
297+
call ESMF_MeshDestroy( mesh_maskinput, noGarbage=no_esmf_garbage, rc=rc)
298+
if (chkerr(rc,__LINE__,u_FILE_u)) return
299+
call ESMF_MeshDestroy( mesh_lndinput, noGarbage=no_esmf_garbage, rc=rc)
300+
if (chkerr(rc,__LINE__,u_FILE_u)) return
301+
302+
end subroutine from_readmesh_destroy_esmf_objects
303+
304+
!-------------------------------------------------------------------------------
305+
subroutine from_readmesh_dealloc( )
306+
307+
if ( associated(lndfrac_loc_input) ) deallocate(lndfrac_loc_input)
308+
if ( associated(gindex_lnd) ) deallocate(gindex_lnd)
309+
if ( associated(gindex_ocn) ) deallocate(gindex_ocn)
310+
if ( associated(gindex_ctsm) ) deallocate(gindex_ctsm)
311+
312+
end subroutine from_readmesh_dealloc
313+
314+
!-------------------------------------------------------------------------------
315+
265316
end subroutine lnd_set_decomp_and_domain_from_readmesh
266317

267318
!===============================================================================
@@ -331,7 +382,7 @@ subroutine lnd_set_decomp_and_domain_for_single_column(scol_lon, scol_lat, scol_
331382
call t_stopf ('decompInit_lnd')
332383

333384
! Initialize processor bounds
334-
call get_proc_bounds(bounds)
385+
call get_proc_bounds(bounds, only_gridcell=.true.) ! only_gridcell since decomp not fully initialized
335386

336387
! Initialize domain data structure
337388
call domain_init(domain=ldomain, isgrid2d=.false., ni=1, nj=1, nbeg=1, nend=1)
@@ -469,6 +520,7 @@ subroutine lnd_set_lndmask_from_maskmesh(mesh_lnd, mesh_mask, vm, gsize, lndmask
469520
character(len=CL) :: flandfrac_status
470521
!-------------------------------------------------------------------------------
471522

523+
call t_startf('lnd_set_lndmask_from_maskmesh')
472524
rc = ESMF_SUCCESS
473525

474526
flandfrac = './init_generated_files/ctsm_landfrac'//trim(inst_suffix)//'.nc'
@@ -569,6 +621,7 @@ subroutine lnd_set_lndmask_from_maskmesh(mesh_lnd, mesh_mask, vm, gsize, lndmask
569621
deallocate(lndmask_loc)
570622

571623
end if
624+
call t_stopf('lnd_set_lndmask_from_maskmesh')
572625

573626
end subroutine lnd_set_lndmask_from_maskmesh
574627

src/dyn_subgrid/test/dynInitColumns_test/test_init_columns.pf

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -66,24 +66,24 @@ contains
6666

6767
! The first landunit is neither natural veg nor crop
6868
call unittest_add_landunit(my_gi=gi, ltype=istwet, wtgcell=0.25_r8)
69-
call unittest_add_column(my_li=li, ctype=1, wtlunit=0.5_r8)
70-
call unittest_add_column(my_li=li, ctype=1, wtlunit=0.5_r8)
69+
call unittest_add_column(my_li=li, ctype=1, wtlunit=0.5_r8, add_simple_patch=.true.)
70+
call unittest_add_column(my_li=li, ctype=1, wtlunit=0.5_r8, add_simple_patch=.true.)
7171

7272
call unittest_add_landunit(my_gi=gi, ltype=1, wtgcell=0.5_r8)
7373
this%l1 = li
74-
call unittest_add_column(my_li=li, ctype=1, wtlunit=0.25_r8)
75-
call unittest_add_column(my_li=li, ctype=1, wtlunit=0.25_r8)
74+
call unittest_add_column(my_li=li, ctype=1, wtlunit=0.25_r8, add_simple_patch=.true.)
75+
call unittest_add_column(my_li=li, ctype=1, wtlunit=0.25_r8, add_simple_patch=.true.)
7676
! This column (the second column on the landunit with ltype=1) will be the target for
7777
! some tests of initialization of a new column
7878
this%c_new = ci
79-
call unittest_add_column(my_li=li, ctype=1, wtlunit=0.25_r8)
80-
call unittest_add_column(my_li=li, ctype=1, wtlunit=0.25_r8)
79+
call unittest_add_column(my_li=li, ctype=1, wtlunit=0.25_r8, add_simple_patch=.true.)
80+
call unittest_add_column(my_li=li, ctype=1, wtlunit=0.25_r8, add_simple_patch=.true.)
8181

8282
call unittest_add_landunit(my_gi=gi, ltype=2, wtgcell=0.25_r8)
8383
this%l2 = li
84-
call unittest_add_column(my_li=li, ctype=1, wtlunit=0.25_r8)
85-
call unittest_add_column(my_li=li, ctype=1, wtlunit=0.25_r8)
86-
call unittest_add_column(my_li=li, ctype=1, wtlunit=0.5_r8)
84+
call unittest_add_column(my_li=li, ctype=1, wtlunit=0.25_r8, add_simple_patch=.true.)
85+
call unittest_add_column(my_li=li, ctype=1, wtlunit=0.25_r8, add_simple_patch=.true.)
86+
call unittest_add_column(my_li=li, ctype=1, wtlunit=0.5_r8, add_simple_patch=.true.)
8787

8888
call unittest_subgrid_setup_end()
8989

src/main/abortutils.F90

Lines changed: 35 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ subroutine write_point_context(subgrid_index, subgrid_level)
108108
!
109109
use clm_varctl , only : iulog
110110
use decompMod , only : subgrid_level_gridcell, subgrid_level_landunit, subgrid_level_column, subgrid_level_patch
111-
use decompMod , only : get_global_index
111+
use decompMod , only : get_global_index, procinfo
112112
use GridcellType , only : grc
113113
use LandunitType , only : lun
114114
use ColumnType , only : col
@@ -124,6 +124,7 @@ subroutine write_point_context(subgrid_index, subgrid_level)
124124
integer :: igrc=unset, ilun=unset, icol=unset, ipft=unset ! Local index for grid-cell, landunit, column, and patch
125125
integer :: ggrc=unset, glun=unset, gcol=unset, gpft=unset ! Global index for grid-cell, landunit, column, and patch
126126
logical :: bad_point = .false. ! Flag to indicate if the point is bad (i.e., global index is -1)
127+
integer :: i, j ! 2D global gridcell indices
127128
!-----------------------------------------------------------------------
128129

129130
if (subgrid_level == subgrid_level_gridcell) then
@@ -201,28 +202,19 @@ subroutine write_point_context(subgrid_index, subgrid_level)
201202

202203
write(iulog,'(a, i0, a, i0)') 'iam = ', iam, ': local gridcell index = ', igrc
203204
write(iulog,'(a, i0, a, i0)') 'iam = ', iam, ': global gridcell index = ', ggrc
204-
write(iulog,'(a, i0, a, f12.7)') 'iam = ', iam, ': gridcell longitude = ', grc%londeg(igrc)
205-
write(iulog,'(a, i0, a, f12.7)') 'iam = ', iam, ': gridcell latitude = ', grc%latdeg(igrc)
206205

207206
else if (subgrid_level == subgrid_level_landunit) then
208207

209208
write(iulog,'(a, i0, a, i0)') 'iam = ', iam, ': local landunit index = ', ilun
210209
write(iulog,'(a, i0, a, i0)') 'iam = ', iam, ': global landunit index = ', glun
211210
write(iulog,'(a, i0, a, i0)') 'iam = ', iam, ': global gridcell index = ', ggrc
212-
write(iulog,'(a, i0, a, f12.7)') 'iam = ', iam, ': gridcell longitude = ', grc%londeg(igrc)
213-
write(iulog,'(a, i0, a, f12.7)') 'iam = ', iam, ': gridcell latitude = ', grc%latdeg(igrc)
214-
write(iulog,'(a, i0, a, i0)') 'iam = ', iam, ': landunit type = ', lun%itype(subgrid_index)
215211

216212
else if (subgrid_level == subgrid_level_column) then
217213

218214
write(iulog,'(a, i0, a, i0)') 'iam = ', iam, ': local column index = ', icol
219215
write(iulog,'(a, i0, a, i0)') 'iam = ', iam, ': global column index = ', gcol
220216
write(iulog,'(a, i0, a, i0)') 'iam = ', iam, ': global landunit index = ', glun
221217
write(iulog,'(a, i0, a, i0)') 'iam = ', iam, ': global gridcell index = ', ggrc
222-
write(iulog,'(a, i0, a, f12.7)') 'iam = ', iam, ': gridcell longitude = ', grc%londeg(igrc)
223-
write(iulog,'(a, i0, a, f12.7)') 'iam = ', iam, ': gridcell latitude = ', grc%latdeg(igrc)
224-
write(iulog,'(a, i0, a, i0)') 'iam = ', iam, ': column type = ', col%itype(icol)
225-
write(iulog,'(a, i0, a, i0)') 'iam = ', iam, ': landunit type = ', lun%itype(ilun)
226218

227219
else if (subgrid_level == subgrid_level_patch) then
228220

@@ -231,18 +223,45 @@ subroutine write_point_context(subgrid_index, subgrid_level)
231223
write(iulog,'(a, i0, a, i0)') 'iam = ', iam, ': global column index = ', gcol
232224
write(iulog,'(a, i0, a, i0)') 'iam = ', iam, ': global landunit index = ', glun
233225
write(iulog,'(a, i0, a, i0)') 'iam = ', iam, ': global gridcell index = ', ggrc
234-
write(iulog,'(a, i0, a, f12.7)') 'iam = ', iam, ': gridcell longitude = ', grc%londeg(igrc)
235-
write(iulog,'(a, i0, a, f12.7)') 'iam = ', iam, ': gridcell latitude = ', grc%latdeg(igrc)
236-
write(iulog,'(a, i0, a, i0)') 'iam = ', iam, ': pft type = ', patch%itype(ipft)
237-
write(iulog,'(a, i0, a, i0)') 'iam = ', iam, ': column type = ', col%itype(icol)
238-
write(iulog,'(a, i0, a, i0)') 'iam = ', iam, ': landunit type = ', lun%itype(ilun)
239-
240226
else
241227
write(iulog,*) 'subgrid_level not supported: ', subgrid_level
242228
write(iulog,*) errMsg(sourcefile, __LINE__)
243229
write(iulog,*) 'Continuing the endrun without writing point context information'
244230
return
245231
end if
232+
if ( subgrid_level >= subgrid_level_landunit )then
233+
if ( ilun > 0 )then
234+
write(iulog,'(a, i0, a, i0)') 'iam = ', iam, ': landunit type = ', lun%itype(ilun)
235+
else
236+
write(iulog,'(a)') 'WARNING: Trouble getting the landunit index'
237+
end if
238+
if ( subgrid_level >= subgrid_level_column )then
239+
if ( icol > 0 )then
240+
write(iulog,'(a, i0, a, i0)') 'iam = ', iam, ': column type = ', col%itype(icol)
241+
else
242+
write(iulog,'(a)') 'WARNING: Trouble getting the column index'
243+
end if
244+
if ( subgrid_level >= subgrid_level_patch )then
245+
if ( ipft > 0 )then
246+
write(iulog,'(a, i0, a, i0)') 'iam = ', iam, ': patch type = ', patch%itype(ipft)
247+
else
248+
write(iulog,'(a)') 'WARNING: Trouble getting the patch index'
249+
end if
250+
end if
251+
end if
252+
end if
253+
if ( igrc > 0 ) then
254+
write(iulog,'(a, i0, a, f12.7)') 'iam = ', iam, ': gridcell longitude = ', grc%londeg(igrc)
255+
write(iulog,'(a, i0, a, f12.7)') 'iam = ', iam, ': gridcell latitude = ', grc%latdeg(igrc)
256+
else
257+
write(iulog,'(a)') 'WARNING: Trouble getting the gridcell index'
258+
end if
259+
call procinfo%calc_globalxy_indices( igrc, i, j )
260+
if ( (i /= -1) .and. (j /= -1) ) then
261+
write(iulog,'(a, i0, a, i0)') 'iam = ', iam, ': 2D gridcell indices = (', i, ', ', j, ')'
262+
else
263+
write(iulog,'(a)') 'WARNING: Trouble getting the 2D gridcell indices'
264+
end if
246265

247266
end subroutine write_point_context
248267

src/main/clm_initializeMod.F90

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,8 @@ subroutine initialize2(ni,nj, currtime)
222222
!-----------------------------------------------------------------------
223223

224224
call t_startf('clm_init2_part1')
225-
! Get processor bounds for gridcells
226-
call get_proc_bounds(bounds_proc)
225+
! Get processor bounds for gridcells, just for gridcells
226+
call get_proc_bounds(bounds_proc, only_gridcell=.true.) ! Just get proc bounds for gridcells, other variables won't be set until after decompInit_clumps
227227
begg = bounds_proc%begg; endg = bounds_proc%endg
228228

229229
! Initialize glc behavior
@@ -283,7 +283,7 @@ subroutine initialize2(ni,nj, currtime)
283283
call t_stopf('clm_decompInit_clumps')
284284

285285
! *** Get ALL processor bounds - for gridcells, landunit, columns and patches ***
286-
call get_proc_bounds(bounds_proc)
286+
call get_proc_bounds(bounds_proc) ! This has to be done after decompInit_clumps is called
287287

288288
! Allocate memory for subgrid data structures
289289
! This is needed here BEFORE the following call to initGridcells
@@ -424,7 +424,9 @@ subroutine initialize2(ni,nj, currtime)
424424
call SnowAge_init( ) ! SNICAR aging parameters:
425425

426426
! Print history field info to standard out
427-
call hist_printflds()
427+
if ( .not. use_noio )then
428+
call hist_printflds()
429+
end if
428430

429431
! Initializate dynamic subgrid weights (for prescribed transient Patches, CNDV
430432
! and/or dynamic landunits); note that these will be overwritten in a restart run

0 commit comments

Comments
 (0)