Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
39840b6
Start adding timers to lnd_set_decomp_and_domain_from_readmesh
ekluzek Jul 29, 2025
7003e1d
Make an internal subroutine for deallocation inside of lnd_set_decomp…
ekluzek Aug 1, 2025
f8e934f
Add release of the ESMF objects in the lnd_set_decomp_and_domain_from…
ekluzek Aug 1, 2025
e042339
ESMF tells me that some of these objects are used later and can not b…
ekluzek Aug 1, 2025
90f9210
Turn on removing all ESMF garbage for the things deleted, and add not…
ekluzek Aug 1, 2025
4be1136
Deallocate lndfrac_loc_input
ekluzek Aug 5, 2025
094288c
Add timers
ekluzek Aug 6, 2025
fe74146
Add more timers
ekluzek Aug 6, 2025
bc7bd46
Add return's after endrun calls so that the self-tests can trap expec…
ekluzek Aug 11, 2025
35a101d
Change endrun calls to use new format for file and line, and remove t…
ekluzek Aug 20, 2025
09e1d46
decompInit/decompMod: initialize pointers to null, add checking that …
ekluzek Aug 25, 2025
9367dd5
Allow get_proc_bounds to exit early if only b3gg/endg will be needed,…
ekluzek Aug 26, 2025
57ee0d3
Return up the chain in decompInit after endrun, for the testing. Do s…
ekluzek Aug 27, 2025
0a7ff22
Move comment over for clarity
ekluzek Aug 29, 2025
a892c4c
Add a MPI_SCAN as a temporary to start testing how it works and compa…
ekluzek Sep 2, 2025
a03b616
Start filling other procinfo settings with mpi_scan, this passes for …
ekluzek Sep 5, 2025
c3b43e8
Remove the mpiscan bit about clumpcnt
ekluzek Sep 5, 2025
33c15e5
Add global i,j indices for each gridcell on a processor to the proces…
ekluzek Sep 6, 2025
5cad336
Add more testing, test new processor_type methods, set gindex_global …
ekluzek Sep 6, 2025
d799ece
Can't do this test yest, as only gridcells are set at this point and …
ekluzek Sep 6, 2025
d1e5e5f
Fix setting of gi and gj indices, the serial case runs to completion now
ekluzek Sep 8, 2025
2dd6f06
Add ggidx global index to the processor_type, allocate, set and deall…
ekluzek Sep 8, 2025
ed351d4
Correct the indexing for ggidx
ekluzek Sep 9, 2025
2f0837c
Remove the prints that weren't with an abort
ekluzek Sep 9, 2025
444b834
Get it working for a threaded case, by adding an additional loop over…
ekluzek Sep 9, 2025
93e1bfe
Add more testing for correctness, add some notes about what can be re…
ekluzek Sep 11, 2025
29a334c
Get it working for the threaded case
ekluzek Sep 12, 2025
7a7f2dc
Comment out the old code and just use the new MPI_SCAN way, this work…
ekluzek Sep 13, 2025
623d7b8
Just do the checking over the local processor clumps and not all the …
ekluzek Sep 14, 2025
9f467b0
Remove the decompInit_lnd old code commented out, and extra writes to…
ekluzek Sep 29, 2025
f0b05bc
Initialize the gi/gj arrays to unset
ekluzek Sep 29, 2025
4eff18d
Add in an if for hist_printflds if noio from mpi_scan branch
ekluzek Dec 15, 2025
8bf9e52
Bring some of the missing things from the mpi_scan branch missed in t…
ekluzek Dec 15, 2025
a2e74ae
Remove some of the timers we don't really need on main
ekluzek Dec 15, 2025
cb1a775
A few changes on mpi_scan that don't need to come to main, remove som…
ekluzek Dec 15, 2025
07f9309
Add some comments and comment line breaks for new subroutines
ekluzek Dec 15, 2025
08d5d13
Merge remote-tracking branch 'escomp/b4b-dev' into decomp_mpi_scan_mo…
ekluzek Dec 16, 2025
d2ed480
Use shr_assert rather than assert_equal
ekluzek Dec 16, 2025
6ae1789
Update src/main/decompInitMod.F90
ekluzek Dec 16, 2025
f786948
Apply suggestions from code review
ekluzek Dec 16, 2025
0574ad7
Add explicit if statements around cohort settings for FATES, add and …
ekluzek Dec 16, 2025
d14b998
Only deallocate lndfrac_loc_input if it's associated, and initialize …
ekluzek Dec 18, 2025
cf5c992
Merge branch 'b4b-dev' into decomp_mpi_scan_move_to_b4b
ekluzek Dec 19, 2025
7a95c40
Add add_simple_patch optional argument in #3672, and use it for the o…
ekluzek Dec 20, 2025
fa03c00
Turn on more options to get more fields turned on
ekluzek Jan 7, 2026
2bc86a3
Merge branch 'b4b-dev' into decomp_mpi_scan_move_to_b4b
ekluzek Jan 8, 2026
354d965
Merge branch 'b4b-dev' into decomp_mpi_scan_move_to_b4b
ekluzek Jan 15, 2026
53d8323
Merge branch 'decomp_mpi_scan_move_to_b4b' of github.com:ekluzek/CTSM…
ekluzek Jan 15, 2026
e772ac2
Move nglob_x/nglob_y from decompInit to decompMod as module data
ekluzek Jan 19, 2026
b7f9bed
Merge branch 'decompMod_unittest' into decomp_mpi_scan_move_to_b4b
ekluzek Jan 20, 2026
a74f8be
Merge remote-tracking branch 'escomp/b4b-dev' into decomp_mpi_scan_mo…
ekluzek Jan 22, 2026
c9f5c72
Add call to calc_globalxy_indices in endrun, this leads to problems i…
ekluzek Jan 28, 2026
201889a
Make the calc functions pure so they can be called from endrun, the c…
ekluzek Jan 28, 2026
cd5e29f
Add a test for calc_globalxy_indices, to get this working temporarily…
ekluzek Jan 29, 2026
30b6916
Initialize nglob_x/nglob_y to -1, so can detect it not being set
ekluzek Jan 30, 2026
4c8698c
Add a test for fails of calc_globalxy
ekluzek Jan 30, 2026
42fc652
Make a subroutine public, so can be unit tested, change order of erro…
ekluzek Jan 30, 2026
9a54398
Add some fail tests for calc_ijindices_from_full_global_index that ar…
ekluzek Jan 30, 2026
84aa74c
Make pure again so will be safe to call from endrun
ekluzek Jan 30, 2026
df03ba6
Move msg and add_msg to top of module so doesn't have to be repeated …
ekluzek Jan 30, 2026
d46582a
Move settings of the decomp from the decomp test to the unittest shar…
ekluzek Feb 18, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
hist_fields_list_file = .true.
hist_wrtch4diag = .true.
calc_human_stress_indices = 'ALL'
calc_human_stress_indices = 'ALL'
60 changes: 52 additions & 8 deletions src/cpl/share_esmf/lnd_set_decomp_and_domain.F90
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ subroutine lnd_set_decomp_and_domain_from_readmesh(driver, vm, meshfile_lnd, mes
! local variables
type(ESMF_Mesh) :: mesh_maskinput
type(ESMF_Mesh) :: mesh_lndinput
type(ESMF_DistGrid) :: distgrid_ctsm
type(ESMF_DistGrid) :: distgrid_ctsm ! This appears to be local but is used later in lnd_import_export
type(ESMF_Field) :: field_lnd
type(ESMF_Field) :: field_ctsm
type(ESMF_RouteHandle) :: rhandle_lnd2ctsm
Expand All @@ -84,7 +84,7 @@ subroutine lnd_set_decomp_and_domain_from_readmesh(driver, vm, meshfile_lnd, mes
integer , pointer :: gindex_ctsm(:) ! global index space for land and ocean points
integer , pointer :: lndmask_glob(:)
real(r8) , pointer :: lndfrac_glob(:)
real(r8) , pointer :: lndfrac_loc_input(:)
real(r8) , pointer :: lndfrac_loc_input(:) => null()
real(r8) , pointer :: dataptr1d(:)
!-------------------------------------------------------------------------------

Expand Down Expand Up @@ -149,6 +149,7 @@ subroutine lnd_set_decomp_and_domain_from_readmesh(driver, vm, meshfile_lnd, mes
end if
call t_stopf('lnd_set_decomp_and_domain_from_readmesh: ESMF mesh')
call t_startf ('lnd_set_decomp_and_domain_from_readmesh: final')
call t_startf ('lnd_set_decomp_and_domain_from_readmesh: decomp_init')

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

Expand Down Expand Up @@ -197,8 +198,10 @@ subroutine lnd_set_decomp_and_domain_from_readmesh(driver, vm, meshfile_lnd, mes
gindex_ctsm(n) = gindex_ocn(n-nlnd)
end if
end do
call t_stopf ('lnd_set_decomp_and_domain_from_readmesh: decomp_init')

! Generate a new mesh on the gindex decomposition
! NOTE: The distgrid_ctsm will be used later in lnd_import_export, even though it appears to just be local
distGrid_ctsm = ESMF_DistGridCreate(arbSeqIndexList=gindex_ctsm, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
mesh_ctsm = ESMF_MeshCreate(mesh_lndinput, elementDistGrid=distgrid_ctsm, rc=rc)
Expand Down Expand Up @@ -255,13 +258,52 @@ subroutine lnd_set_decomp_and_domain_from_readmesh(driver, vm, meshfile_lnd, mes

end if

! Deallocate local pointer memory
deallocate(gindex_lnd)
deallocate(gindex_ocn)
deallocate(gindex_ctsm)
! Deallocate local pointer memory including ESMF objects
call from_readmesh_dealloc( rc )
if (chkerr(rc,__LINE__,u_FILE_u)) return

call t_stopf('lnd_set_decomp_and_domain_from_readmesh: final')


!===============================================================================
! Internal subroutines for this subroutine
contains
!===============================================================================

subroutine from_readmesh_dealloc( rc )
use ESMF, only : ESMF_FieldRedistRelease, ESMF_DistGridDestroy, ESMF_FieldDestroy, ESMF_MeshDestroy
integer, intent(out) :: rc ! ESMF return code to indicate deallocate was successful

logical :: no_esmf_garbage = .true. ! If .true. release all ESMF data (which can be problematic if referenced again)

rc = ESMF_SUCCESS

if ( associated(lndfrac_loc_input) ) deallocate(lndfrac_loc_input)
deallocate(gindex_lnd)
deallocate(gindex_ocn)
deallocate(gindex_ctsm)
! Destroy or release all of the ESMF objects
call ESMF_FieldRedistRelease( rhandle_lnd2ctsm, noGarbage=no_esmf_garbage, rc=rc)
if (chkerr(rc,__LINE__,u_FILE_u)) return
!--------------------------------------------------------------------------
! NOTE: We can't destroy the distgrid -- because it will be used later
! As such we don't do the following... EBK 08/01/2025
!call ESMF_DistGridDestroy( distgrid_ctsm, rc=rc)
!if (chkerr(rc,__LINE__,u_FILE_u)) return
!--------------------------------------------------------------------------
call ESMF_FieldDestroy( field_lnd, noGarbage=no_esmf_garbage, rc=rc)
if (chkerr(rc,__LINE__,u_FILE_u)) return
call ESMF_FieldDestroy( field_ctsm, noGarbage=no_esmf_garbage, rc=rc)
if (chkerr(rc,__LINE__,u_FILE_u)) return
call ESMF_MeshDestroy( mesh_maskinput, noGarbage=no_esmf_garbage, rc=rc)
if (chkerr(rc,__LINE__,u_FILE_u)) return
call ESMF_MeshDestroy( mesh_lndinput, noGarbage=no_esmf_garbage, rc=rc)
if (chkerr(rc,__LINE__,u_FILE_u)) return

end subroutine from_readmesh_dealloc

!-------------------------------------------------------------------------------

end subroutine lnd_set_decomp_and_domain_from_readmesh

!===============================================================================
Expand Down Expand Up @@ -331,7 +373,7 @@ subroutine lnd_set_decomp_and_domain_for_single_column(scol_lon, scol_lat, scol_
call t_stopf ('decompInit_lnd')

! Initialize processor bounds
call get_proc_bounds(bounds)
call get_proc_bounds(bounds, only_gridcell=.true.) ! only_gridcell since decomp not fully initialized

! Initialize domain data structure
call domain_init(domain=ldomain, isgrid2d=.false., ni=1, nj=1, nbeg=1, nend=1)
Expand Down Expand Up @@ -469,6 +511,7 @@ subroutine lnd_set_lndmask_from_maskmesh(mesh_lnd, mesh_mask, vm, gsize, lndmask
character(len=CL) :: flandfrac_status
!-------------------------------------------------------------------------------

call t_startf('lnd_set_lndmask_from_maskmesh')
rc = ESMF_SUCCESS

flandfrac = './init_generated_files/ctsm_landfrac'//trim(inst_suffix)//'.nc'
Expand Down Expand Up @@ -569,6 +612,7 @@ subroutine lnd_set_lndmask_from_maskmesh(mesh_lnd, mesh_mask, vm, gsize, lndmask
deallocate(lndmask_loc)

end if
call t_stopf('lnd_set_lndmask_from_maskmesh')

end subroutine lnd_set_lndmask_from_maskmesh

Expand Down
18 changes: 9 additions & 9 deletions src/dyn_subgrid/test/dynInitColumns_test/test_init_columns.pf
Original file line number Diff line number Diff line change
Expand Up @@ -66,24 +66,24 @@ contains

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

call unittest_add_landunit(my_gi=gi, ltype=1, wtgcell=0.5_r8)
this%l1 = li
call unittest_add_column(my_li=li, ctype=1, wtlunit=0.25_r8)
call unittest_add_column(my_li=li, ctype=1, wtlunit=0.25_r8)
call unittest_add_column(my_li=li, ctype=1, wtlunit=0.25_r8, add_simple_patch=.true.)
call unittest_add_column(my_li=li, ctype=1, wtlunit=0.25_r8, add_simple_patch=.true.)
! This column (the second column on the landunit with ltype=1) will be the target for
! some tests of initialization of a new column
this%c_new = ci
call unittest_add_column(my_li=li, ctype=1, wtlunit=0.25_r8)
call unittest_add_column(my_li=li, ctype=1, wtlunit=0.25_r8)
call unittest_add_column(my_li=li, ctype=1, wtlunit=0.25_r8, add_simple_patch=.true.)
call unittest_add_column(my_li=li, ctype=1, wtlunit=0.25_r8, add_simple_patch=.true.)

call unittest_add_landunit(my_gi=gi, ltype=2, wtgcell=0.25_r8)
this%l2 = li
call unittest_add_column(my_li=li, ctype=1, wtlunit=0.25_r8)
call unittest_add_column(my_li=li, ctype=1, wtlunit=0.25_r8)
call unittest_add_column(my_li=li, ctype=1, wtlunit=0.5_r8)
call unittest_add_column(my_li=li, ctype=1, wtlunit=0.25_r8, add_simple_patch=.true.)
call unittest_add_column(my_li=li, ctype=1, wtlunit=0.25_r8, add_simple_patch=.true.)
call unittest_add_column(my_li=li, ctype=1, wtlunit=0.5_r8, add_simple_patch=.true.)

call unittest_subgrid_setup_end()

Expand Down
9 changes: 8 additions & 1 deletion src/main/abortutils.F90
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ subroutine write_point_context(subgrid_index, subgrid_level)
!
use clm_varctl , only : iulog
use decompMod , only : subgrid_level_gridcell, subgrid_level_landunit, subgrid_level_column, subgrid_level_patch
use decompMod , only : get_global_index
use decompMod , only : get_global_index, procinfo
use GridcellType , only : grc
use LandunitType , only : lun
use ColumnType , only : col
Expand All @@ -124,6 +124,7 @@ subroutine write_point_context(subgrid_index, subgrid_level)
integer :: igrc=unset, ilun=unset, icol=unset, ipft=unset ! Local index for grid-cell, landunit, column, and patch
integer :: ggrc=unset, glun=unset, gcol=unset, gpft=unset ! Global index for grid-cell, landunit, column, and patch
logical :: bad_point = .false. ! Flag to indicate if the point is bad (i.e., global index is -1)
integer :: i, j ! 2D global gridcell indices
!-----------------------------------------------------------------------

if (subgrid_level == subgrid_level_gridcell) then
Expand Down Expand Up @@ -243,6 +244,12 @@ subroutine write_point_context(subgrid_index, subgrid_level)
write(iulog,*) 'Continuing the endrun without writing point context information'
return
end if
call procinfo%calc_globalxy_indices( igrc, i, j )
if ( (i /= -1) .and. (j /= -1) ) then
write(iulog,'(a, i0, a, i0)') 'iam = ', iam, ': 2D gridcell indices = (', i, ', ', j, ')'
else
write(iulog,'(a)') 'WARNING: Trouble getting the 2D gridcell indices'
end if

end subroutine write_point_context

Expand Down
10 changes: 6 additions & 4 deletions src/main/clm_initializeMod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,8 @@ subroutine initialize2(ni,nj, currtime)
!-----------------------------------------------------------------------

call t_startf('clm_init2_part1')
! Get processor bounds for gridcells
call get_proc_bounds(bounds_proc)
! Get processor bounds for gridcells, just for gridcells
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
begg = bounds_proc%begg; endg = bounds_proc%endg

! Initialize glc behavior
Expand Down Expand Up @@ -283,7 +283,7 @@ subroutine initialize2(ni,nj, currtime)
call t_stopf('clm_decompInit_clumps')

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

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

! Print history field info to standard out
call hist_printflds()
if ( .not. use_noio )then
call hist_printflds()
end if

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