Skip to main content

A tool for mocking mpi4py for testing

Project description

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).

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

MockMPI-0.8.1.tar.gz (8.7 kB view details)

Uploaded Source

File details

Details for the file MockMPI-0.8.1.tar.gz.

File metadata

  • Download URL: MockMPI-0.8.1.tar.gz
  • Upload date:
  • Size: 8.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.18.1 setuptools/38.5.1 requests-toolbelt/0.8.0 tqdm/4.23.4 CPython/2.7.18

File hashes

Hashes for MockMPI-0.8.1.tar.gz
Algorithm Hash digest
SHA256 ae333fdb2076175b459b9d1b81bfe5f6e44a577e7adde39ace0d7abd5b678e5d
MD5 57bf62b51a3880c1b08715945c349e49
BLAKE2b-256 489927611735b8b9059e0361a9ecd6cba893bf6fb17a516d1cc0f4cbcd6ddd60

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page