Skip to content

Split cism_parallel and glissade_velo_higher_pcg into modules by theme - #113

Open
whlipscomb wants to merge 10 commits into
lipscomb/rename_dirs_modulesfrom
lipscomb/split_modules
Open

whlipscomb wants to merge 10 commits into
lipscomb/rename_dirs_modulesfrom
lipscomb/split_modules

Conversation

@whlipscomb

@whlipscomb whlipscomb commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Branch: lipscomb/split_modules (9 commits, 1d98aad..7a9308a, plus the merge commit ffce0d9)
Base: lipscomb/rename_dirs_modules (#112). Stacked; the base will be changed to main after the earlier PRs are merged.
CISM-wrapper: no change needed (the wrapper's code does not use cism_parallel, and buildlib runs CISM's CMake, which finds the new files).

Update (December 2026): one merge commit at the end of this branch (ffce0d9) brings in the lateral melt fixes from the review of #99, which are now at the end of the #99 branch (they were first made in #114, which no longer changes anything). It changes nothing else in this PR.

Summary

Two long modules are split into shorter ones by theme. The code is moved, not changed; there are no answer changes. One pre-existing bug, found while testing, is fixed first.

  1. Fix (1d98aad): the 1D distributed_get_var/distributed_put_var routines used uninitialized netCDF ids.
  2. cism_parallel (11969 lines) becomes seven modules (972397e..2774976). cism_parallel itself only uses them, so no caller changes.
  3. glissade_velo_higher_pcg (5900 lines) becomes a 2D and a 3D module (7a9308a).

Fix: uninitialized ids in the 1D distributed reads and writes

distributed_get_var_real4_1d, distributed_get_var_real8_1d, distributed_put_var_real4_1d and distributed_put_var_real8_1d look up the ids of x0, y0, x1 and y1 to choose the bounds of the variable being read or written. When one of these is missing from the file (x0 and y0 often are), nf90_inq_varid does not set its id, which was left uninitialized. If the stale value happened to equal the id of the variable being read, the wrong branch was taken. After the split moved code around, the Greenland 4 km run stopped when reading x1 from the geothermal-flux file ("NetCDF: Start+count exceeds dimension bound"). The ids are now set to -1, never a valid id, before the lookups. Runs that worked before take the same branches, so their answers do not change.

The fix is committed before the split, so it can be reviewed on its own.

cism_parallel

module lines contents uses
cism_parallel_core 625 parallel_type and the shared variables (communicator, ranks, halo widths); MPI setup and shutdown; parallel_barrier, parallel_stop; global and local index utilities; parallel_boundary(_value); parallel_convert_haloed_to_nonhaloed -
cism_parallel_broadcast 295 broadcast core
cism_parallel_reduce 1799 parallel_global_sum(_patch, _stagger), parallel_reduce_* (incl. the reproducible sum), parallel_is_zero, parallel_show_minmax core
cism_parallel_halo 3024 parallel_halo(_extrapolate, _tracers, _verify), staggered_parallel_halo(_extrapolate), and the utilities that call them (parallel_convert_nonhaloed_to_haloed, parallel_global_edge_mask, staggered_no_penetration_mask) core
cism_parallel_gather_scatter 4452 gather_var and scatter_var (and row/column variants), distributed_get_var, distributed_put_var, distributed_print, parallel_print, the fc_gather routines core, broadcast
cism_parallel_netcdf 801 the netCDF wrappers (the main task does the I/O and broadcasts the result) core, broadcast
cism_parallel_decomp 1278 the domain decomposition (distributed_grid, distributed_grid_active_blocks, distributed_print_grid, parallel_localindex) and the row and column communicators core, broadcast, reduce, gather_scatter
cism_parallel 53 use of the seven modules, with a comment listing their contents all

The grouping follows the calls between procedures: each module calls only modules above it in the table. Everything in these modules is public, as it was in cism_parallel, so use cism_parallel, only: ... works as before. All 58 files that use cism_parallel import only names defined in it, so the module-level use statements that cism_parallel no longer needs (netcdf, glimmer_global, ...) are removed.

There is one commit per new module. Each moves procedures, generic interfaces and module-level declarations unchanged; a script checked that all 185 procedures and 36 interfaces appear exactly once, verbatim, in the new files. git log -p --color-moved shows the moves.

glissade_velo_higher_pcg

  • glissade_velo_higher_pcg_2d (git mv of the old file, so history follows): the 2D solvers (standard and Chronopoulos-Gear), their diagonal and tridiagonal preconditioners, the 2D tridiagonal solvers and the 2D matrix-vector multiply.
  • glissade_velo_higher_pcg_3d: the 3D solvers, their preconditioners (diagonal, SIA, local and global tridiagonal), the 3D tridiagonal solvers, the 3D matrix-vector multiply, easy_sia_solver and tridiag_solver.

The 3D tridiagonal preconditioner setups and solvers call their 2D counterparts, so those four routines are public in the 2D module and the 3D module uses it. glissade_velo_higher uses both. The 19 subroutines are moved unchanged (checked with a script).

Testing

Commits

1d98aad9 Initialize the coordinate-variable ids in the 1D distributed get/put_var
972397e1 Split cism_parallel: move the core into cism_parallel_core
46806e18 Split cism_parallel: move the broadcasts into cism_parallel_broadcast
9571ce76 Split cism_parallel: move the reductions into cism_parallel_reduce
ec5ad03c Split cism_parallel: move the halo updates into cism_parallel_halo
e342a0e9 Split cism_parallel: move gathers and scatters into cism_parallel_gather_scatter
d4948b62 Split cism_parallel: move the netCDF wrappers into cism_parallel_netcdf
27749760 Split cism_parallel: move the domain decomposition into cism_parallel_decomp
7a9308ac Split glissade_velo_higher_pcg into 2D and 3D modules
ffce0d97 Merge lipscomb/rename_dirs_modules (#112) into #113: lateral melt fixes from the review of #99

🤖 Generated with Claude Code

whlipscomb and others added 9 commits November 20, 2026 19:12
distributed_get_var_real4_1d, distributed_get_var_real8_1d,
distributed_put_var_real4_1d and distributed_put_var_real8_1d look up the
ids of x0, y0, x1 and y1 to choose the bounds of the variable being read
or written. When a variable is missing from the file (x0 and y0 often
are), nf90_inq_varid does not set its id, which was left uninitialized.
If the stale value happened to equal the id of the variable being read,
the wrong branch was taken. The Greenland 4 km run then failed when
reading x1 from the geothermal-flux file (NetCDF: Start+count exceeds
dimension bound) after the cism_parallel split changed the stack
contents. The ids are now set to -1 (never a valid id) before the
lookups.

No answer changes for runs that worked before (the same branches are
taken).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
First step in splitting cism_parallel.F90 (11969 lines) into modules by
theme. cism_parallel_core holds what every other part needs:
- the parallel_type and the shared variables (communicator, ranks,
  halo widths);
- MPI setup and shutdown (parallel_initialise, parallel_set_info,
  parallel_finalise), parallel_barrier, parallel_stop, not_parallel;
- the index utilities (parallel_globalID, parallel_globalindex,
  distributed_owner, ...), parallel_boundary(_value) and
  parallel_convert_haloed_to_nonhaloed.

cism_parallel uses cism_parallel_core, and everything in it is public,
so callers still get these names through cism_parallel; no other file
changes. The procedures, interfaces and declarations are moved
unchanged (checked with a script: each appears verbatim exactly
once).

No answer changes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
cism_parallel_broadcast holds the broadcast interface and its eleven
specific procedures. It uses cism_parallel_core.

The procedures and interfaces are moved unchanged (checked with a script:
each appears verbatim exactly once). cism_parallel uses the new module, so
callers still get these names through cism_parallel; no other file changes.

No answer changes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
cism_parallel_reduce holds the global sums (parallel_global_sum,
parallel_global_sum_patch, parallel_global_sum_stagger), the reductions
(parallel_reduce_sum, _max, _min, _maxloc, _minloc, including the
reproducible sum), parallel_is_zero and parallel_show_minmax. It uses
cism_parallel_core and cism_reprosum_mod.

The procedures and interfaces are moved unchanged (checked with a script:
each appears verbatim exactly once). cism_parallel uses the new module, so
callers still get these names through cism_parallel; no other file changes.

No answer changes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
cism_parallel_halo holds parallel_halo, parallel_halo_extrapolate,
parallel_halo_tracers, parallel_halo_verify (with DEBUG_LEVEL),
staggered_parallel_halo and staggered_parallel_halo_extrapolate, and the
utilities that call them: parallel_convert_nonhaloed_to_haloed,
parallel_global_edge_mask and staggered_no_penetration_mask. It uses
cism_parallel_core.

The procedures and interfaces are moved unchanged (checked with a script:
each appears verbatim exactly once). cism_parallel uses the new module, so
callers still get these names through cism_parallel; no other file changes.

No answer changes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…her_scatter

cism_parallel_gather_scatter holds gather_var (and the row, column and
gather_all variants), scatter_var (and row and column variants), the
distributed reads and writes (distributed_get_var, distributed_put_var),
distributed_print and parallel_print, the fc_gather routines,
get_bounds_info with the private bounds_info_type, and the work arrays
d_gs_mybounds, d_gs_bounds and max_gather_block_size. It uses
cism_parallel_core and cism_parallel_broadcast.

The procedures and interfaces are moved unchanged (checked with a script:
each appears verbatim exactly once). cism_parallel uses the new module, so
callers still get these names through cism_parallel; no other file changes.

No answer changes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
cism_parallel_netcdf holds the netCDF wrappers in which the main task
does the I/O and broadcasts the result: parallel_create, _open, _close,
_sync, _redef, _enddef, _def_dim, _def_var, _inq_*, _inquire*, _get_att,
_put_att, _get_var and _put_var. It uses cism_parallel_core and
cism_parallel_broadcast.

The procedures and interfaces are moved unchanged (checked with a script:
each appears verbatim exactly once). cism_parallel uses the new module, so
callers still get these names through cism_parallel; no other file changes.

No answer changes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…_decomp

cism_parallel_decomp holds distributed_grid, distributed_grid_active_blocks,
distributed_print_grid, parallel_localindex, parallel_create_comm_row,
parallel_create_comm_col and parallel_test_comm_row_col. These call the
broadcast, reduction and gather/scatter modules, so this module comes
last. The procedures are moved unchanged.

cism_parallel.F90 now holds only the use statements for the seven
modules, with a comment listing what each contains. The module-level
use statements it no longer needs (netcdf, glimmer_global,
glimmer_paramets, cism_reprosum_mod) and the empty contains section are
removed; no caller imports those names through cism_parallel.

No answer changes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
glissade_velo_higher_pcg.F90 (5900 lines) is split in two:
- glissade_velo_higher_pcg_2d: the 2D solvers (standard and
  Chronopoulos-Gear), their diagonal and tridiagonal preconditioners,
  the 2D tridiagonal solvers and the 2D matrix-vector multiply
- glissade_velo_higher_pcg_3d: the 3D solvers, their preconditioners
  (diagonal, SIA, local and global tridiagonal), the 3D tridiagonal
  solvers, the 3D matrix-vector multiply, easy_sia_solver and
  tridiag_solver

The subroutines are moved unchanged. The 3D tridiagonal preconditioner
setups and solvers call their 2D counterparts, so those four routines
are public in the 2D module. glissade_velo_higher uses both modules.

No answer changes (dome on 4 tasks with DIVA and Blatter-Pattyn, pcg
and pcg_chrongear, and every preconditioner: BFB with the previous
executable).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…es from the review of #99

The fixes for the issues found in Kate's review of #99, first made in #114,
were added at the end of the #99 branch (lipscomb/lateral_melt). This merge
carries them forward to this branch; it brings in no other changes.

Answers change only for lateral melt (lateral_melt_method = ismip), as in #114.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
whlipscomb added a commit that referenced this pull request Dec 2, 2026
…ow in #99

The lateral melt fixes from the review of #99, first made in this PR, are
now at the end of the #99 branch (lipscomb/lateral_melt) and are carried
forward through #100-#113 by a merge commit in each. This merge brings that
version of #113 into this branch. Its tree is identical to the previous tip
of this branch, so this PR no longer changes anything relative to #113.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants