Skip to content

Usage errors for unsupported runs on several MPI ranks - #201

Merged
BenjaminRodenberg merged 3 commits into
mainfrom
mpi-usage-errors
Oct 21, 2026
Merged

BenjaminRodenberg merged 3 commits into
mainfrom
mpi-usage-errors

Conversation

@BenjaminRodenberg

Copy link
Copy Markdown
Collaborator

Extracted from #197 as a small, independent PR.

On main, EBFM on several MPI ranks only works with a pre-partitioned Elmer mesh (--elmer-mesh .../partitioning.N --netcdf-dem-mesh ... --is-partitioned-elmer-mesh, one partition per rank). Every other setup runs the whole grid on every rank and fails late with errors that don't point at the cause; e.g. mpirun -np 2 ebfm --matlab-mesh examples/dem_and_mask.mat fails in the first time step with a PermissionError while both ranks write the same output file. This PR turns these setups into usage errors at startup (exit status 2). It is purely a usability change: no model change and no new parallel capability.

Rejected when EBFM's own communicator has more than one rank, before INIT reads the grid:

  • every grid except a partitioned Elmer mesh: --matlab-mesh, --netcdf-mesh, and --elmer-mesh without --is-partitioned-elmer-mesh (validate_grid_parallel_compat)
  • --forcing-dir (validate_forcing_parallel_compat, from 7a1a987)
  • --restart-dir / --restart-init, also on a partitioned mesh (validate_restart_parallel_compat, from 07b14b0)

Rejected at parse time, independently of the communicator: an MPI launcher started EBFM on several processes (OMPI_COMM_WORLD_SIZE or PMI_SIZE above 1), but mpi4py cannot be imported (from 912b160).

The guards check ebfm_comm, not COMM_WORLD, so a coupled MPMD run with EBFM on one rank (README: mpirun -np 1 ebfm ... --is-partitioned-elmer-mesh --use-part 1 : -np 1 elmer_dummy_f.x ...) is unaffected, restart files included. Pre-partitioned runs on several ranks work as on main, except:

  • --forcing-dir already failed when reading the first forcing file; it now fails at startup.
  • --restart-dir used to finish without a restart file, with a warning at the end; it now fails at startup.
  • --restart-init already failed at the shape check of the restart file; it now fails at startup.

Nothing else from #197 is included. The MATLAB part of #197 (branch mpi-matlab-mesh) builds on this PR: it lifts the --matlab-mesh restriction and adds the shading guard, which cannot be reached until then.

Known issue, not changed here: a usage error raised after the communicator splitting in an MPMD job leaves the other components waiting. With a partner that joins the MPI handshake and then waits in a barrier on the coupler group, mpirun -np 2 ebfm --matlab-mesh ... : -np 1 partner hangs after both EBFM ranks print the usage error (Open MPI 4.1.6). The existing validate_shading_coupling_compat raises at the same point and hangs the same way on main.

Tested:

  • pytest tests: 197 passed (mpi4py 4.1.2, Open MPI 4.1.6)
  • mpirun -np 2 python -m ebfm.main --matlab-mesh examples/dem_and_mask.mat: usage error on both ranks, exit status 2, no hang
  • partitioned mesh (partitioning.128) on 2 ranks: runs as on main; with --forcing-dir, --restart-dir and --restart-init, main behaves as listed above and this branch stops at startup
  • mpirun -np 2 with mpi4py not importable: usage error on both processes, exit status 2; a serial run without mpi4py is unaffected

Generated with Claude Code

@BenjaminRodenberg BenjaminRodenberg self-assigned this Oct 21, 2026
@BenjaminRodenberg BenjaminRodenberg added the usability Improves the user experience label Oct 21, 2026
On several MPI ranks, EBFM only runs on a pre-partitioned Elmer mesh,
one partition per rank. With any other grid, every rank computed the
whole grid and the run failed late, e.g. with the ranks writing the
same output file. On a partitioned mesh, --forcing-dir failed at the
first forcing read, --restart-init at the restart shape check, and
--restart-dir finished without a restart file.

These are now usage errors, raised before INIT reads the grid. The
checks use EBFM's own communicator, so EBFM on a single rank of a
coupled MPMD run is unaffected.

Assisted-by: Claude Code:claude-opus-5-5
Without mpi4py, every process started by mpirun ran as a serial run
over the whole grid, and the processes then failed while writing the
same output file with a misleading PermissionError. EBFM now reads
the process count the launcher puts into the environment,
OMPI_COMM_WORLD_SIZE (Open MPI) or PMI_SIZE (MPICH, Intel MPI,
srun --mpi=pmi2), and stops with a usage error if it is above 1 and
mpi4py cannot be imported. Serial runs without mpi4py are unaffected.

Assisted-by: Claude Code:claude-opus-5-5
--use-part sets the partition of every rank, so on several ranks all
of them computed the same partition. It is now a usage error there;
without it, rank i computes partition i + 1 as before. A single rank,
e.g. EBFM in a coupled MPMD run, may still pick its partition.

The README example for a partitioned mesh now passes the required
--elmer-mesh-crs-epsg and shows a run on several ranks.

Assisted-by: Claude Code:claude-opus-5-5
@BenjaminRodenberg
BenjaminRodenberg merged commit 65a56c2 into main Oct 21, 2026
34 checks passed
@BenjaminRodenberg BenjaminRodenberg added this to the v0.9.0 milestone Oct 21, 2026
@BenjaminRodenberg
BenjaminRodenberg deleted the mpi-usage-errors branch October 21, 2026 10:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

usability Improves the user experience

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant