sima0_13_003: Fix model crash in MPAS dynamical core and implement assorted code cleanup - #486
Merged
kuanchihwang merged 8 commits intoApr 14, 2026
Conversation
The `entry_id_pg` element in the namelist definition XML file was updated to version 2.0 in PR 460. However, the corresponding Python script was not updated. After updating the Python script, it is also confirmed that: 1. The namelist definition XML file is up to date. 2. The namelist definition XML file is successfully validated against the XML schema at CIME/ParamGen/xml_schema/entry_id_pg.xsd.
The `dyn_inquire_mesh_dimensions` procedure does not need to be a public API because nothing outside the `dyn_grid` module uses it. Privatize it to reduce API surface area.
CAM-SIMA holds information about all constituents. However, MPAS dynamical core only knows about the advected ones. This lookup table maps an index within the set of advected constituents to an index within the set of all constituents. Refactor the rest of code to use it, removing duplicate and error-prone code logic throughout.
When CAM-SIMA is configured with MPAS dynamical core, and is built with GNU Fortran compiler version 14 in debug mode, running the model will lead to a segmentation fault. However, the crash mysteriously disappears when the model is built in optimized mode. Older GNU Fortran compiler version 12 does not exhibit this behavior, neither does Intel Fortran compiler. This issue is caused by a regression in recent GNU Fortran compiler, where a procedure call involving an array argument with indirect indexing is mishandled. Split out the operations into simpler steps to fix this issue.
The `mpas_dynamical_core % map_constituent_index` type-bound function maps MPAS scalar index to CAM-SIMA *advected* constituent index, but we are still one step away. Should also use the `advected_constituent_index` lookup table to map *advected* constituent index to *all* constituent index.
kuanchihwang
temporarily deployed
to
CI-tests-on-CIRRUS
March 31, 2026 20:32 — with
GitHub Actions
Inactive
kuanchihwang
marked this pull request as ready for review
March 31, 2026 20:40
nusbaume
requested changes
Apr 10, 2026
nusbaume
left a comment
Collaborator
There was a problem hiding this comment.
Thanks for the bug fix and cleanup @kuanchihwang! To help us catch these potential issues in the future, I was wondering if we could add another set of MPAS+CAM4 regression tests, but this time with debug flags enabled? This should be doable by just adding the following lines to CAM-SIMA/cime_config/testdefs/testlist_cam.xml, ideally at the end of the CAM4 physics tests section:
<test compset="QPC4" grid="mpasa120_mpasa120" name="SMS_D_Ln9" testmods="cam/outfrq_analy_ic_cam4">
<machines>
<machine name="derecho" compiler="intel" category="aux_sima"/>
<machine name="derecho" compiler="gnu" category="aux_sima"/>
</machines>
<options>
<option name="wallclock">00:20:00</option>
<option name="comment">Aquaplanet CAM4 test with MPAS dycore at 120 km resolution with compiler debug flags enabled</option>
</options>
</test>
I also had one code-related question, but otherwise everything else looked good to me. Thanks again!
kuanchihwang
temporarily deployed
to
CI-tests-on-CIRRUS
April 13, 2026 06:41 — with
GitHub Actions
Inactive
jimmielin
self-requested a review
April 13, 2026 16:56
nusbaume
self-requested a review
April 13, 2026 16:57
nusbaume
approved these changes
Apr 13, 2026
nusbaume
left a comment
Collaborator
There was a problem hiding this comment.
Everything looks great to me now. Thanks again @kuanchihwang!
jimmielin
approved these changes
Apr 13, 2026
jimmielin
left a comment
Collaborator
There was a problem hiding this comment.
Thanks @kuanchihwang!
kuanchihwang
deleted the
staging/mpas-dycore-fix-indirect-indexing-crash
branch
April 15, 2026 00:20
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Tag name (required for release branches):
sima0_13_003 due to newly-added tests, otherwise bit-for-bit.
Originator(s):
kuanchihwang
Descriptions (include the issue title, and the keyword ['closes', 'fixes', 'resolves'] followed by the issue number):
This PR fixes a model crash in MPAS dynamical core, which is caused by a regression in recent versions of GNU Fortran compiler. When CAM-SIMA is configured with MPAS dynamical core, and is built with GNU Fortran compiler version 14 in debug mode, running the model will lead to a segmentation fault. However, the crash mysteriously disappears when the model is built in optimized mode. Older GNU Fortran compiler version 12 does not exhibit this behavior, neither does Intel Fortran compiler.
Closes #484
Additionally, this PR also brings the following:
dyn_inquire_mesh_dimensionsprivateset_physics_state_externalduring dynamics-physics couplingThe rationale behind each change is described in the commit messages.
Describe any changes made to the build system:
None
Describe any changes made to the namelist:
None
List any changes to the defaults for the input datasets (e.g., boundary datasets):
None
List all files eliminated and why:
None
List all files added and what they do:
None
List all existing files that have been modified, and describe the changes:
Regression tests:
Known failing tests.
Newly-added tests.