Skip to content

maybempi

Install from PyPI with

Terminal window
pip install maybempi # serial runs only
pip install "maybempi[mpi]" # with mpi4py, for MPI runs

The same code runs under mpirun/srun and as a plain python script.py, and the serial run never starts MPI:

from maybempi import MPI # instead of: from mpi4py import MPI
# mpi4py.MPI under mpirun/mpiexec/srun, a serial stand-in otherwise
comm = MPI.COMM_WORLD
total = comm.allreduce(local_total, op=MPI.SUM) # local_total in a serial run

Importing mpi4py.MPI calls MPI_Init, which costs close to a second and makes every collective cost something, even on one process. maybempi decides from the environment variables that MPI launchers export, without importing mpi4py, and in a serial run returns a stand-in whose collectives give the results MPI gives on one process. It is pure Python with no dependencies.

You can find the documentation here.

Check out the code on GitHub!

Links: