MPI based task scheduling for both `multiprocessing` and `concurrent.futures` interfaces.
Project description
About
mpipool
offers an MPIExecutor
class, an implementation of the
concurrent.futures.Executor
class of the standard library.
Example usage
from mpipool import MPIExecutor
from mpi4py import MPI
def menial_task(x):
return x ** MPI.COMM_WORLD.Get_rank()
with MPIExecutor() 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 MPIExecutor
of mpipool 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
File details
Details for the file mpipool-1.0.0a0-py3-none-any.whl
.
File metadata
- Download URL: mpipool-1.0.0a0-py3-none-any.whl
- Upload date:
- Size: 7.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/3.9.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2103851dc3111180b4a4ee53cbf71a5332a0099ffb11c4782872cb7d546273c7 |
|
MD5 | 8363f207838b23ba70791716b0adbf35 |
|
BLAKE2b-256 | f90006b7d19b5d2abff7db83e369d17b36307e7ab9de564d9ca453b1987cc2a2 |