Skip to main content

Parallel MPIPoolExecutor implementing the concurrent.futures interface

Project description

Documentation Status

About

zwembad offers an MPIPoolExecutor class, an implementation of the concurrent.futures.Executor class of the standard library.

Example usage

from zwembad import MPIPoolExecutor
from mpi4py import MPI

def menial_task(x):
  return x ** MPI.COMM_WORLD.Get_rank()

with MPIPoolExecutor() as pool:
  pool.workers_exit()
  print("Only the master executes this code.")

  # Submit some tasks to the pool
  fs = [pool.submit(menial_task, i) for i in range(100)]

  # Wait for all of the results and print them
  print([f.result() for f in fs])

  # A shorter notation to dispatch the same function with different args
  # and to wait for all results is the `.map` method:
  results = pool.map(menial_task, range(100))

print("All processes join again here.")

You'll see that some results will have exponentiated either by 1, 2, ..., n depending on which worker they were sent to. It's also important to prevent your workers from running the master code using the pool.workers_exit() call. As a fail safe any attribute access on the pool object made from workers will result in them exiting anyway.

The MPIPoolExecutor of zwembad is designed to function without MPI.Spawn() for cases where this approach isn't feasible, like supercomputers where MPI.Spawn is deliberatly not implemented (for example CrayMPI).

Therefor the pool can only use MPI processes that are spawned when the MPI world is initialised and must be run from the command line using an MPI helper such as mpirun, mpiexec or SLURM's srun:

$ mpirun -n 4 python example.py

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

zwembad-1.2.2-py3-none-any.whl (6.2 kB view details)

Uploaded Python 3

File details

Details for the file zwembad-1.2.2-py3-none-any.whl.

File metadata

  • Download URL: zwembad-1.2.2-py3-none-any.whl
  • Upload date:
  • Size: 6.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.53.0 CPython/3.8.6

File hashes

Hashes for zwembad-1.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 ca9fd0dd3f0cbe92f1e96073ba7742bd580d8f92d3bcf45b0ee6aa6ae45621b7
MD5 38d3e38e7ef1e652205a464c13e9a1da
BLAKE2b-256 b69e75f04f672d4caa83b2a358aee7ff5a1289d8b0d5f1b8a46019db3db2d2bc

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