Skip to main content

Overview

Message Passing Interface (MPI) is an approach to parallelism based on explicit communication between processes. Python bindings to it are available via mpi4py.

Testing code that uses MPI can be awkward. This package provides a pure-python mock MPI communicator that can be used to do so, without requiring actual MPI. It uses multiprocessing to start processes and makes a mocked Communicator (comm) object that takes the place of mpi4py.MPI.COMM_WORLD.

Installation

The code is pure python; you can install it with:

    pip install mockmpi

Usage

Define a function that holds the code that should work in an MPI session:

    def function_to_test(comm):
        ...

If this were a real MPI session, it should work as:

    import mpi4py
    comm = MPI.COMM_WORLD
    function_to_test(comm)

which you would run with mpiexec -n nproc ...

To test the code without MPI, import mock_mpiexec from this package and run:

    mock_mpiexec(nproc, function_to_test)

Extra Arguments

You can also supply additional named or positional arguments to mock_mpiexec and they will be passed to function_to_test:

    mock_mpiexec(nproc, function_to_test, 1, 2, 3, a='b')

mimics:

    import mpi4py
    comm = MPI.COMM_WORLD
    function_to_test(comm, 1, 2, 3, a='b')

This works if the arguments can be pickled (true for most basic python and numpy types).

Caveats

  1. This runs on python 3.5+
  2. Absolutely no attention was paid to making this efficient. This code is designed to be used for unit testing, not production.
  3. Only the IntraComm object is currently mocked, not the many other features like operators, futures, topologies, windows, spawning ...
  4. Many methods are currently missing. Only those below are currently implemented. Others will raise NotImplementedError
  • Get_rank
  • Get_size
  • Barrier
  • send - unlike real MPI this is non-blocking
  • Send - also non-blocking
  • recv
  • Recv
  • barrier
  • bcast
  • Bcast
  • scatter
  • reduce (only with the default sum operation)
  • Reduce (only with the default sum operation)
  • allreduce
  • Allreduce
  • alltoall
  • gather

Contributions and License

We would greatly welcome contributions, especially to fill in missing features.

The code and any contributions are released under a BSD 2-clause license (see the LICENSE file).

Metadata

Release files for MockMPI 0.8.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for MockMPI 0.8.3
File Size Uploaded
mockmpi-0.8.3.tar.gz 8.2 kB Details

Release files / mockmpi-0.8.3.tar.gz

Download URL mockmpi-0.8.3.tar.gz
Size 8.2 kB
Tags Source
SHA-256 checksum
How to use checksums
859711ade022ec1d3c1e6b11d6d32648b57f1133887b2ba990245ace1e53611c
BLAKE2b-256 checksum
How to use checksums
f75ada43264899d0df74b66ee4fe168a449a37e626913b91e597b7c456df4894
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 15, 2025.

Transparency log

Release history Release notifications | RSS feed

This release

0.8.3 This release

1 release file

0.8.2

1 release file

0.8.1

1 release file

0.8.0

1 release file

0.7.0

1 release file

0.6.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page