Skip to content

maybempi

Run the same code under mpirun and as a plain python script, without starting MPI in the serial run.
import maybempi
MPI = maybempi.get_mpi() # mpi4py.MPI under mpirun/srun, a serial stand-in otherwise
comm = MPI.COMM_WORLD
total = comm.allreduce(local_total, op=MPI.SUM)

No MPI in serial runs

Importing mpi4py.MPI starts MPI, which costs close to a second. maybempi decides from the launcher’s environment variables and never imports mpi4py in a serial run.

One code path

The stand-in has the module constants and communicator methods of mpi4py, with the results MPI gives on one process.

Loud when unsupported

Methods the stand-in does not implement raise AttributeError instead of silently doing nothing.

No dependencies

Pure Python. mpi4py is only needed for MPI runs, NumPy only for array buffers.