Skip to content

SE: skip tendency-diagnostic buffers when the fields are not on a history tape - #1762

Open
g8j39 wants to merge 2 commits into
ESCOMP:cam_developmentfrom
g8j39:se-skip-inactive-diag-tendencies
Open

g8j39 wants to merge 2 commits into
ESCOMP:cam_developmentfrom
g8j39:se-skip-inactive-diag-tendencies

Conversation

@g8j39

@g8j39 g8j39 commented Nov 18, 2026

Copy link
Copy Markdown

Fixes #1761

Summary

When TA<constituent> advection-tendency and *_PDC (WV_PDC, WI_PDC, WL_PDC, TT_PDC) history fields are inactive, compute_adv_tends_xyz and applyCAMforcing still allocate about 150 MiB per rank each (adv_tendxyz, ftmp_fvm in 141-tracer B1850CM) and copy every tracer across every element on every step.

  • advect_tend.F90 (compute_adv_tends_xyz): Return early before allocating ftmp or adv_tendxyz when no hist_fld_active(tottnam(ic)) field is active.
  • prim_advance_mod.F90 (applyCAMforcing): Make ftmp allocatable (checked allocate(..., stat=ierr) for ftmp and ftmp_fvm) and guard allocation, clipping-loss stores, and output_qdp_var_dynamics behind pdc_active. When any *_PDC field is active, the exact same statements run (including dp_fvm scaling on cam_development).

Timing & Validation

  • 32-task B1850CM (gfortran 13.4.0 -O2, cesm3_0_beta10, with two other SE changes): comp_adv_tends1+2 drops from 4.98 s to 0.0009 s and applyCAMforc from 3.55 s to 2.28 s, skipping ~150 MiB/rank of transient ftmp_fvm allocation (2-pair whole-run delta sits under 1%, near spread).
  • Single-column SCAM (ne3_ne3_mg37, 1 MPI task): comp_adv_tends1+2 drops from 11.0 s (695h FSCAMARM97) and 12.5 s (120h FCSCAM) down to 0.03 to 0.04 s.
  • Checks: Both cesm3_0_beta10 and cam_development versions compile and match bit-for-bit across gfortran, ifx 2025.0.4, and nvfortran 24.11-0 for all 4 {CSLAM, GLL} x {inactive, active} paths at ftype = 0. Full-model cprnc checks on the equivalent beta10 commit (0 diffs in 2-day and 3-hour B1850CM; earlier pre-allocatable-ftmp checks also passed QPC6, 8x4, DEBUG=TRUE, restart, and SCAM), combined atmosphere numbers, and aux_cam status are in the series overview comment below.

Prepared with AI assistance (Google Gemini).

compute_adv_tends_xyz allocated ftmp and adv_tendxyz and copied all
constituents twice per physics step even when no total advective
tendency field (tottnam) was active. Return on entry when all tottnam
fields are inactive. In applyCAMforcing, make ftmp allocatable and guard
ftmp/ftmp_fvm allocations, clipping-loss stores, and
output_qdp_var_dynamics on WV_PDC, WI_PDC, WL_PDC, or TT_PDC being
active.

With those fields off on cesm3_0_beta10 (gfortran 13.4.0 -O2),
comp_adv_tends1+2 drops from 4.98 s to 0.0009 s and applyCAMforc from
3.55 s to 2.28 s on 3-hour 32-task B1850CM (avoiding ~150 MiB/rank
transient ftmp_fvm), and from 11.0-12.5 s to 0.03-0.04 s on
single-column FSCAMARM97 and FCSCAM.

Answer impact: Bit-for-bit identical. The equivalent cesm3_0_beta10
commit (differing only by cam_development's dp_fvm factor) gave 0
differing cprnc fields in 2-day and 3-hour B1850CM on gfortran 13.4.0
-O2 (pre-allocatable-ftmp revision also passed QPC6, 8x4 OpenMP, DEBUG,
restart, and SCAM), and this commit passed standalone A/B checks across
active/inactive CSLAM and GLL paths on gfortran, ifx 2025.0.4, and
nvfortran 24.11-0.

Prepared with AI assistance (Google Gemini).
Prepared with AI assistance (Google Gemini).
@g8j39

g8j39 commented Nov 18, 2026 •

Copy link
Copy Markdown
Author

CAM & Atmospheric Physics CPU Optimization Series Overview

This comment summarizes the full 3-PR ESCOMP/CAM CPU optimization series (+266/-105 lines across 7 commits and 7 files on cam_development) together with the companion ESCOMP/atmospheric_physics gravity-wave PR (+39/-7 lines across 3 files on main), plus the shared benchmark setup and verification suite so each PR stays short and focused.

Benchmark Environment

  • Full-model CESM3 runs: cesm3_0_beta10 (cam6_4_203), gfortran 13.4.0 -O2 -ffp-contract=off, 32 MPI tasks (32x1, zero OpenMP threads). Same-machine back-to-back pairs on coupled 2-day B1850CM (ne30pg3_t232, 141 advected tracers, 93 vertical levels; 3 patched-first, 3 stock-first).
  • Upstream rebase check: All 7 CAM commits apply cleanly to cam_development (417212df, cam6_4_223), and the companion gravity-wave commit applies cleanly to ESCOMP/atmospheric_physics:main (592e2ccc). None have been built or run directly on cam_development yet.
  • Standalone 3-compiler checks: gfortran 15.2.0, Intel ifx 2025.0.4, and NVIDIA nvfortran 24.11-0 (file compiles on cam6_4_203 / main plus standalone kernel A/B drivers under stock CIME non-FMA flags).

Combined Atmosphere Speedup (exact submitted code)

  • Coupled 2-day B1850CM (ne30pg3_t232, 6 same-machine pairs): The 7 CAM commits plus the 1 atmospheric_physics gravity-wave commit cut atmosphere (ATM) time by 11.2% (median 10,652.8 to 9,460.7 s; pairs 11.15% to 11.51%, pair median 11.25%).
  • Measured inside the full 24-patch CESM3 build (tested together with 10 CTSM and 6 MOM6 optimization patches), total coupled run time dropped by 11.1% (11,779.0 to 10,471.0 s; pairs 11.05% to 11.42%, pair median 11.18%; peak RSS -0.29%). A large share of coupled B1850CM runtime sits in the auto-generated chemistry solver, which this series leaves untouched.

Per-PR Summary

PR Repo & Branch Commits / Diffstat Modules Touched Representative Individual Timing (gfortran 13.4.0 -O2, 32 MPI ranks)
#1762 ESCOMP/CAM (cam_development) 1 (+43/-15) advect_tend.F90, prim_advance_mod.F90 comp_adv_tends1+2: 4.98 to 0.0009 s (B1850CM), 11.0 to 12.5 s down to 0.03 to 0.04 s (SCAM); skips ~150 MiB/rank transient buffer
#1764 ESCOMP/CAM (cam_development) 2 (+59/-7) modal_aerosol_properties_mod.F90, aerosol_optics_cam.F90 Earlier revisions with other patches active: 1.15% total / 1.38% ATM on 3h B1850CM (Commit 1) and 1.51% total on 6h F2000climo (Commit 2)
SE-CSLAM PR (to follow) ESCOMP/CAM (cam_development) 4 (+164/-83) fvm_reconstruction_mod.F90, fvm_mapping.F90, fvm_consistent_se_cslam.F90 Commits 1 & 2: 14.5% / 83% to 93% less kernel time (~1% or less in 6h QPC6); Commits 3+4 with #1762: 3.64% total / 4.21% ATM on 3h B1850CM
ESCOMP/atmospheric_physics#483 ESCOMP/atmospheric_physics (main) 1 (+39/-7) gravity_wave_drag_ridge.F90, gw_common.F90, gw_diffusion.F90 Earlier broader revision with other patches active: 1.87% total / 2.15% ATM on 3h B1850CM

Totals: +266/-105 lines in ESCOMP/CAM (7 commits across 7 files) plus +39/-7 lines in ESCOMP/atmospheric_physics (1 commit across 3 files).

Shared Verification Matrix

Check Code Tested Scope Result
2-day coupled B1850CM (6 pairs, 32x1 MPI) Exact submitted commits (#1762 in its cesm3_0_beta10 form, differing only by one upstream dp_fvm scaling line from cam_development) 17 NetCDF files / 4,263 cprnc fields 0 diffs (ocean.stats = 0.0)
3-hour coupled B1850CM (32x1 MPI) Exact submitted commits (as above) 16 NetCDF files / 4,183 cprnc fields 0 diffs
6-hour QPC6 aquaplanet (32x1 MPI) Exact submitted commits (SE-CSLAM PR); earlier revisions (#1762, #1764, ESCOMP/atmospheric_physics#483) Full history/restart cprnc 0 diffs
Multi-mode checks (F2000climo, 8x4 OpenMP, DEBUG=TRUE, exact restart, 16 vs 32 ranks) Earlier revisions prior to small final cleanups (constructor stat/sentinels, allocatable ftmp, comment edits) Full cprnc (gfortran 13.4.0) 0 diffs
3-compiler compiles & standalone kernel A/B drivers Exact submitted commits (gfortran 15.2.0, ifx 2025.0.4, nvfortran 24.11-0) Stock CIME non-FMA flags 0 diffs (0 ULP)

Not yet run: aux_cam system tests on Derecho (ifx, nvhpc, gnu) and Izumi (nag, gnu), and full-model builds on cam_development (I do not have NCAR machine access).

Prepared with AI assistance (Google Gemini).

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.

1 participant