Skip to content

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

Open
sbryngelson wants to merge 1 commit into
MFlowCode:masterfrom
sbryngelson:thermochem-num-species
Open

sbryngelson wants to merge 1 commit into
MFlowCode:masterfrom
sbryngelson:thermochem-num-species

Conversation

@sbryngelson

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.

@github-actions

Copy link
Copy Markdown

Lines of Code

File Lines Diff
src/common/m_chemistry.fpp 404 -16
src/simulation/m_riemann_state.fpp 1185 -8
src/simulation/m_compute_cbc.fpp 274 -7
src/simulation/m_riemann_solver_hllc.fpp 1315 -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 614 -2
src/simulation/m_riemann_solver_lf.fpp 515 -2
src/common/include/shared_parallel_macros.fpp 161 -1
src/simulation/m_cbc.fpp 1117 -1
src/simulation/m_ibm.fpp 1334 -1
Directory Lines Diff
common 10402 -19
simulation 27822 -26
total 46635 -45

@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 61.48%. Comparing base (fef3c27) to head (7958e6f).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1918   +/-   ##
=======================================
  Coverage   61.48%   61.48%           
=======================================
  Files          86       86           
  Lines       22485    22485           
  Branches     3298     3298           
=======================================
  Hits        13826    13826           
  Misses       6206     6206           
  Partials     2453     2453           

☔ 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.

This branch has not been deployed

No deployments
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