Skip to content

Size species arrays from the generated mechanism on AMD - #1918

Merged
sbryngelson merged 5 commits into
MFlowCode:masterfrom
sbryngelson:thermochem-num-species
Oct 1, 2026
Merged

sbryngelson merged 5 commits into
MFlowCode:masterfrom
sbryngelson:thermochem-num-species

Conversation

@sbryngelson

@sbryngelson sbryngelson commented Sep 23, 2026 •

Copy link
Copy Markdown
Member

Summary

Follow-up to #1915 and #1852. Generic (non-case-optimized) amdflang builds declared species arrays with AMD_NUM_SPECIES_MAX = 60 and sys_size arrays with AMD_SYS_SIZE_MAX = 70: 26 uses in 11 files, each an #:if not MFC_CASE_OPTIMIZATION and USING_AMD branch. Now that MFC generates m_thermochem, the species count is known at build time.

  • The toolchain writes build/include/<target>/thermochem.fpp next to case.fpp: #:set NUM_SPECIES = <m_thermochem's num_species> and #:set CHEMISTRY = <bool>.
  • Species arrays are declared dimension(${NUM_SPECIES}$) on every backend. Every species USING_AMD branch collapses to one declaration, and the per-thread arrays carry the mechanism's exact count (10 for h2o2, 11 for the Add heterogeneous reacting surface boundary conditions #1821 carbon mechanism) instead of 60. Raise the amdflang species bound so mechanisms above ten species build #1852-style "raise the bound" changes are no longer needed.
  • AMD_SYS_SIZE_MAX = 10 + NUM_SPECIES for chemistry builds (chemistry pins num_fluids to 1, leaving at most 10 flow variables), so HLLC star states and CBC L vectors shrink from 70 to 20 for h2o2. Non-chemistry builds keep 70, so no non-chemistry case loses headroom. The sys_size check stays; the species-count check goes with the bound.
  • Fypp resolves #:include in the including file's directory before -I paths, so the default thermochem.fpp (for Fypp runs outside the toolchain) lives in src/common/include/defaults/, which cmake/Fypp.cmake searches last.

A literal extent rather than dimension(num_species): my first attempt used the num_species parameter directly and failed C4EB58A8 on amdflang GPU (large tolerance mismatch). That run overlapped another build in the same checkout, so I do not claim it proves an amdflang bug, but the literal is what the former fallback used, is identical on every compiler, and passes cleanly.

Performance

MI250X (one GCD), amdflang 23.2.1, generic --gpu mp --no-mpi build, examples/2D_premixed_flame_vortex (1024x512, h2o2, HLLC, reactions + diffusion), 500 steps, interleaved runs:

master fef3c276 this PR
s/step (3 runs) 0.05117, 0.05184, 0.05162 0.05004, 0.04960, 0.04977
mean 0.05154 0.04980 (-3.4%)

Every run of this PR is faster than every master run. All 17 output fields are bit-identical to master at step 500.

Testing

  • amdflang 23.2.1, OpenMP offload, MI250X (OMP_TARGET_OFFLOAD=MANDATORY): ./mfc.sh test --gpu mp --only Chemistry - 16 passed, 0 failed. This is the configuration the guards applied to.
  • gfortran 12.2 CPU: --only Chemistry - 16 passed, 0 failed.
  • Checked that the generated include takes precedence (NUM_SPECIES=10, AMD_SYS_SIZE_MAX=20 for an h2o2 chemistry build) and that the default is used only when no generated file exists.
  • ./mfc.sh precheck passes.

Interaction with #1821

#1821 adds new ${AMD_NUM_SPECIES_MAX}$ declarations in m_ibm.fpp. Whichever of the two merges second needs them switched to ${NUM_SPECIES}$; that is mechanical and I will do it.

Prepared with Claude Code.

Contribution Policy

We do not accept pull requests generated primarily by AI without genuine understanding or real-world usage context.

All contributions are expected to demonstrate:

  • A clear understanding of the codebase
  • Alignment with product direction
  • Thoughtful reasoning behind changes
  • Evidence of real-world usage or hands-on experience with the problem

If these expectations are not met, we would prefer to implement the changes ourselves rather than spend time reviewing low-effort submissions.


Acknowledgement

  • I confirm this PR meets the above expectations and reflects my own understanding and real-world context.

PR template credit: junegunn

Generic (non-case-optimized) amdflang builds declared every species array
with a fixed AMD_NUM_SPECIES_MAX = 60 bound, and sys_size arrays with
AMD_SYS_SIZE_MAX = 70, because the species count was not known when the
guards were written. The toolchain now writes
build/include/<target>/thermochem.fpp with m_thermochem's species count
(NUM_SPECIES) and whether chemistry is on (CHEMISTRY). Species arrays are
declared dimension(${NUM_SPECIES}$) on every backend, so the USING_AMD
species branches collapse to one declaration and carry the mechanism's
exact count. Chemistry pins num_fluids to 1, so the sys_size fallback
becomes 10 + NUM_SPECIES there; other builds keep 70. The species-count
check goes away with the bound.

Fypp searches the including file's directory before -I paths, so the
default thermochem.fpp for toolchain-less Fypp runs lives in
src/common/include/defaults/, searched last.

Done with Claude Code.
Copilot AI balanced review requested due to automatic review settings September 23, 2026 04:45

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@codecov

codecov Bot commented Sep 23, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 62.82%. Comparing base (ed7a238) to head (a674bc3).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1918   +/-   ##
=======================================
  Coverage   62.82%   62.82%           
=======================================
  Files          86       86           
  Lines       22394    22394           
  Branches     3305     3305           
=======================================
  Hits        14070    14070           
  Misses       6071     6071           
  Partials     2253     2253           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Conflict resolution:
- m_ibm: keep master's alpha_rho_GP, drop the per-branch Ys_IP in favor of
  the single ${NUM_SPECIES}$ declaration
- input.py: compute sol before master's syscheck guard; thermochem.fpp
  needs it for every target
- test_thermochem fypp helper: search src/common/include/defaults last, as
  cmake/Fypp.cmake does, for the default thermochem.fpp
Its sandiego.yaml mechanism is the only non-h2o2 one in the suite, so it
forces a second chemistry build of every target just for this case, which
takes too long to compile. It stays in the example skip list.
@github-actions

github-actions Bot commented Oct 1, 2026

Copy link
Copy Markdown

Lines of Code

File Lines Diff
src/common/m_chemistry.fpp 395 -16
src/simulation/m_riemann_state.fpp 1185 -8
src/simulation/m_compute_cbc.fpp 274 -7
src/simulation/m_riemann_solver_hllc.fpp 1308 -5
src/common/include/defaults/thermochem.fpp 2 +2
src/common/m_checker_common.fpp 37 -2
src/common/m_variables_conversion.fpp 960 -2
src/simulation/m_riemann_solver_hll.fpp 607 -2
src/simulation/m_riemann_solver_lf.fpp 509 -2
src/common/include/shared_parallel_macros.fpp 161 -1
src/simulation/m_cbc.fpp 1114 -1
src/simulation/m_ibm.fpp 1450 -1
Directory Lines Diff
common 10416 -19
simulation 28006 -26
total 46950 -45

@sbryngelson
sbryngelson merged commit c7feed2 into MFlowCode:master Oct 1, 2026
92 of 93 checks passed
@sbryngelson
sbryngelson deleted the thermochem-num-species branch October 1, 2026 15:33
sbryngelson added a commit to rocfire11/MFC-tlj that referenced this pull request Oct 1, 2026
Conflicts with MFlowCode#1918, which sizes species locals at ${NUM_SPECIES}$
instead of AMD_NUM_SPECIES_MAX / num_species: the reacting-surface
arrays in s_ibm_correct_state join master's single Ys_IP declaration,
and input.py keeps both the surface module and master's
thermochem.fpp. check_amd_species_array_sizes now points at
${NUM_SPECIES}$, since AMD_NUM_SPECIES_MAX no longer exists.
sbryngelson added a commit to sbryngelson/MFC that referenced this pull request Oct 1, 2026
Conflicts with MFlowCode#1918 in m_chemistry and the HLL/HLLC/LF Riemann solvers:
kept this branch's per-solver case-optimization guards and applied
MFlowCode#1918's change inside them -- species locals are declared once at
${NUM_SPECIES}$ instead of an AMD_NUM_SPECIES_MAX / num_species pair.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants