Refactor variable conversion into stage-independent common code#1679
Draft
sbryngelson wants to merge 13 commits into
Draft
Refactor variable conversion into stage-independent common code#1679sbryngelson wants to merge 13 commits into
sbryngelson wants to merge 13 commits into
Conversation
Resolves conflicts with MFlowCode#1675 (hyperelasticity removal): - accept deletion of src/simulation/m_hyperelastic.fpp - adopt hypoelasticity in place of the removed elasticity flag - drop GPU_DECLARE for elasticity, b_size, tensor_size - drop hyperelasticity from SIM_GPU_DECL_VARS, whose parameter master removed (silent auto-merge break; failed the generator test)
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.
Description
This contains the first incremental steps toward making
src/commongenuinely stage-independent instead of selecting different implementations withMFC_SIMULATION,MFC_PRE_PROCESS, andMFC_POST_PROCESS.The first slice focuses on
m_variables_conversion:Re_idx,Re_size, material arrays, and the new policy scalars.The second slice makes shared grid-buffer population stage-independent:
m_boundary_commonnow receives cell-boundary, cell-center, and cell-width arrays explicitly instead of selecting stage-global representations;buff_sizecell-boundary extent, while post-process supplies its asymmetric Silo/output offsets;glb_boundsand performs the GPU update immediately after the host-side grid population.The third slice removes the superseded grid implementations and separates minimum spacing from width-array storage:
dx_min,dy_min, anddz_minscalars;dx,dy, anddzwidth arrays unchanged;The fourth slice makes MPI I/O field binding and downsampled datatype construction stage-independent:
pb/mvorpb_ts(1)/mv_ts(1)by stage;m_mpi_common, reducing the remaining stage-condition count insrc/commonfrom 30 to 24.The fifth slice makes Dirichlet ghost filling an explicit runtime policy:
s_dirichlet;GPU_ROUTINEtakes the same branch on host and device;src/commonfrom 24 to 23.The sixth slice removes low-risk stage selection from common validation and finite differences:
nGlobalwhile simulation skips the check;src/commonfrom 23 to 19.The seventh slice moves common global declarations, equation indexing, and GPU declarations to explicit ownership:
num_dims,num_vels,weno_polyn, andmuscl_polyndeclarations for all executables, while preserving simulation case optimization;eqn_idx%alfstage guard with an explicit initialization policy, preserving simulation, pre-process, and post-process behavior;src/commonfrom 19 to 14.The eighth slice makes common MPI transport stage-independent:
src/commonfrom 14 to 9.The ninth slice makes MPI domain decomposition stage-independent and removes its repeated directional policy code:
src/commonfrom 9 to 3.The tenth slice makes common STL model setup available in every executable:
s_instantiate_STL_models;num_stl_modelsandstl_modelsto post-process without adding either variable to its namelist;src/commonfrom 3 to 1.The eleventh slice makes the full common phase-change module available in every executable:
palpha_epsandptgalpha_epsto post-process without adding them to its namelist;src/common.Design choices
Stage identity is no longer used as a proxy for accelerator execution. Code inside accelerator regions selects the device-callable kernel with
MFC_GPU; CPU execution uses the host wrapper, which can also populate optional post-processing diagnostics.The scalar conversion kernel is marked with
GPU_ROUTINEand is shared by CPU and accelerator paths. Device-resident module data retains explicitGPU_DECLARE, enter-data, update, and delete lifecycle operations. Material arrays and viscosity metadata are declared only once, in their common owning module.Some variables must now be declared in all three executables because common code references them, but they should not become accepted inputs in every namelist. The parameter generator therefore separates Fortran declaration targets from namelist targets. Existing user-facing scopes for
avg_state,alt_soundspeed,mixture_err,sigR,viscous, andriemann_solverremain unchanged.This change deliberately does not remove capability guards such as
MFC_GPUor backend-specific GPU macros. It removes stage-based implementation selection.Pre-process currently uses
dx,dy, anddzas scalar minimum spacings, whereas simulation and post-process use those names for width arrays. Passing the grid representation explicitly allows the common boundary implementation to compile for every executable without hiding that semantic mismatch behind another stage macro.That mismatch is resolved in the third slice: scalar minimum spacings now have distinct common names, while per-cell width arrays retain the established
dx,dy, anddznames.MPI I/O now follows the same ownership rule: common code constructs views and binds only the objects supplied by its caller. Paired optional data are checked together, preventing a marker without a descriptor or one QBMM node field without the other. Accelerator ownership is unchanged because these routines set host-side MPI pointer/view metadata and introduce no device-data movement.
Dirichlet behavior is configured when the boundary module is initialized, rather than inferred from the executable name. The policy is device resident because
s_dirichletis called inside accelerator boundary loops.Finite-difference routines now compute into caller-provided storage. This keeps allocation and lifetime with the executable that owns the array and avoids hiding post-process reallocation inside common numerical code.
Generated declarations are now the ownership boundary for generated simulation inputs. The generator emits exactly one
GPU_DECLAREfor each device-resident scalar it declares. Manually declared common state retains direct portability macros in the common module. Capability guards such asMFC_GPU, OpenACC, and OpenMP remain intact; only executable-stage selection is being removed.MPI transport now has one implementation. Executables configure whether all chemistry temperatures need halo exchange and whether RDMA transport is enabled; the common layer owns buffer sizing and selects the corresponding transport path. OpenACC/OpenMP data movement remains expressed through the portability macros.
MPI decomposition owns the Cartesian algorithm, while executables provide only the data and policies that are actually stage-specific. Pre-process supplies mutable domain bounds and requests local-domain adjustment for generated grids; post-process supplies mutable output offsets and requests Silo overlap; simulation disables both policies. The common implementation applies both policies dimensionally, eliminating the three copies of each formula.
STL instantiation remains a single common routine. Post-process now has the declarations needed to compile that routine, but no new accepted inputs and no new call site. Generated declaration targets are therefore the compile-time ownership mechanism, while namelist targets remain the user-facing input contract.
Phase-change follows the same ownership rule: the complete numerical implementation is compiled once in common for all executables, while only the stages that currently need it invoke it. The two solver tolerances are declaration-visible in post-process solely so the common module compiles; their accepted input scope remains pre-process/simulation.
Type of change
Testing
pre_process,simulation, andpost_processwithout MPI.examples/1D_euler_convergence/case.py.8EAC3DA7(1D viscous)9DAC4DDC(two-fluid alternative sound speed)CE9DBA3F(QBMM)B9553426(Lagrangian bubbles)1D_euler_convergenceexample.B49877F3(3D grid stretching)8C7AA13B(2D, two MPI ranks)DB670E50(axisymmetric boundary)3008BA80(periodic immersed-boundary case)EA8FA07E(2D IBM STL)E777BE53(3D pre-process ICPP STL)356A5C50(non-polytropic QBMM with parallel I/O)3008BA80(immersed-boundary marker I/O)11x11x11input was read as the expected3x3x3post-process domain.986BC1A2(2D Richtmyer--Meshkov with Dirichlet boundary-buffer input) through pre-process, simulation, and post-process with MPI.examples/2D_richtmyer_meshkov/case.py.FD891191(two-fluid six-equation model) through pre-process, simulation, and post-process with MPI.1550B67E(2D chemistry with diffusion disabled) through pre-process, simulation, and post-process with MPI.B9553426(2D Lagrangian bubbles) through all three stages with MPI to exercise ordinary and beta halo transport.B49877F3(3D grid stretching)8C7AA13B(2D, two MPI ranks, Silo output)DB670E50(axisymmetric)examples/1D_vacuum_restart: generated the original parallel grid, then re-read it withold_grid = Tin a temporary case directory. The temporary restart copy supplied domain bounds required by current validation and disabledold_icso the check exercised grid reuse without requiring a 7000-step restart file.EA8FA07E(2D IBM STL)E777BE53(3D pre-process ICPP STL)E6DBCBD9(1D, model 5, two fluids, six-equation model)02BD9B5E(2D, model 6, three fluids, six-equation model)344FAA70(3D, model 5, two fluids, six-equation model)GPU_ROUTINEkernel directly, and the old stage-specific accelerator routine is absent.acc update device(glb_bounds)/omp target update to(glb_bounds), and common grid routines do not take over device-data ownership.m_mpi_commonfor all three executables with both OpenACC and OpenMP definitions and inspected the new explicit QBMM, immersed-boundary, and downsampled interfaces. A physical accelerator build is unavailable on this macOS/GNU toolchain.acc declare/omp declare targetandacc update device/omp target update, and both buffer-copy and extrapolation paths remain in the device routine.num_dims,num_vels,weno_polyn, andmuscl_polynremain Fortran parameters with no OpenACC/OpenMP device allocation.m_mpi_commonfor all three executables with both OpenACC and OpenMP definitions after transport unification. Every stage receives the same staged and RDMA branches; runtime policy selects one, and the portability macros emit the expected host/device updates or device-address regions.m_mpi_commonfor every executable and both accelerator backends after decomposition unification; each expansion contains the same single policy helper and no stage-selection residue.examples/2D_richtmyer_meshkov/case.pyafter the decomposition interface change.m_modelfor all three executables with OpenACC and OpenMP definitions. Every expansion contains exactly one STL-instantiation routine, its existing device updates, and no stage-selection residue.m_phase_changefor all three executables with OpenACC and OpenMP definitions. Every expansion contains the same full phase-change solver and accelerator loop annotations, with no stage-selection residue.rg -n 'MFC_(PRE_PROCESS|SIMULATION|POST_PROCESS)' src/commonreturns no matches.Checklist
No user-facing parameter behavior changed; the declaration/namelist separation preserves the existing accepted inputs for each executable.
See the developer guide for full coding standards.
GPU changes (expand if you modified
src/simulation/)This machine does not have a supported NVIDIA or AMD GPU compiler/runtime. GPU validation in this PR is limited to generated OpenACC/OpenMP source inspection; physical GPU regression testing is still required.
AI code reviews
Reviews are not retriggered automatically. To request a review, comment on the PR:
@claude full review— Claude full review (also triggers on PR open/reopen/ready)claude-full-review— Claude full review via label