Skip to content

NgenSimulation MPI interfacing adjustments - #986

Draft
PhilMiller wants to merge 5 commits into
NOAA-OWP:masterfrom
PhilMiller:PhilMiller/ngen-simulation-mpi-fixes
Draft

NgenSimulation MPI interfacing adjustments#986
PhilMiller wants to merge 5 commits into
NOAA-OWP:masterfrom
PhilMiller:PhilMiller/ngen-simulation-mpi-fixes

Conversation

@PhilMiller

Copy link
Copy Markdown
Contributor

[Short description explaining the high-level reason for the pull request]

Additions

Removals

Changes

Testing

Screenshots

Notes

Todos

Checklist

  • PR has an informative and human-readable title
  • Changes are limited to a single goal (no scope creep)
  • Code can be automatically merged (no conflicts)
  • Code follows project standards (link if applicable)
  • Passes all existing automated tests
  • Any change in functionality is tested
  • New functions are documented (with a description, list of inputs, and expected output)
  • Placeholder code is flagged / future todos are captured in comments
  • Project documentation has been updated (including the "Unreleased" section of the CHANGELOG)
  • Reviewers requested with the Reviewers tool ➡️

Testing checklist (automated report can be put here)

Target Environment support

  • Linux

PhilMiller and others added 4 commits June 29, 2026 08:59
Under NGEN_WITH_MPI, add a constructor that takes an MPI_Comm and derives
mpi_rank_ and mpi_num_procs_ from it. The communicator is duplicated with
MPI_Comm_dup so the simulation holds a private communication context,
stored in a new mpi_comm_ member and freed in the destructor.

The existing rank/process-count constructor sets mpi_comm_ to MPI_COMM_NULL
so the destructor leaves it alone. The new constructor is not yet used by
any caller; wiring it into main() follows separately.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
In MPI builds, main() now constructs the simulation via the communicator
constructor, passing MPI_COMM_WORLD; non-MPI builds keep the explicit
rank/process-count constructor. run_routing_bmi()'s MPI_Reduce now uses the
simulation's private mpi_comm_ rather than MPI_COMM_WORLD directly. The
simulation is reset before MPI_Finalize() so its duplicated communicator is
freed while MPI is still active.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Now that parallel::gather_strings and parallel::broadcast_strings take an
MPI_Comm, call them with the simulation's private mpi_comm_, consistent with
the MPI_Reduce in run_routing_bmi. All of the routing collectives now run on
the simulation's own communicator rather than MPI_COMM_WORLD.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
In non-MPI builds, NgenSimulation now takes no MPI-related constructor
arguments: it has a single constructor that initializes mpi_rank_ to 0 and
mpi_num_procs_ to 1, behaving as rank 0 of a single process.

In MPI builds the constructors are unchanged: the MPI_Comm constructor plus
the explicit rank/process-count constructor, the latter now documented as the
no-communicator path (mpi_comm_ stays MPI_COMM_NULL) for single-process and
test use that needs no MPI runtime.

main()'s non-MPI branch constructs with the serial constructor; mpi_num_procs
is marked [[maybe_unused]] there since it is otherwise only read in MPI-guarded
code. The construction test selects the matching constructor per build.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@PhilMiller
PhilMiller requested a review from hellkite500 June 29, 2026 22:27
@PhilMiller

Copy link
Copy Markdown
Contributor Author

Nels, this is some of what I was talking about in terms of "MPI being a compile-time option blows up interface complexity"

In going back over this, though, the solution may be to just pull the communicator parameter and member out entirely, and just pass it in to the routing routines where it's actually used.

@PhilMiller

Copy link
Copy Markdown
Contributor Author

@hellkite500 This is an alternative to #987

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