A simple MPI processing pool for Python
Project description
ezMPI
A simple MPI-based processing pool for Python that distributes tasks across multiple processes using MPI (Message Passing Interface).
Features
- Simple API similar to Python's built-in
map()function - Automatic worker process management
- Support for complex objects via optional
dillintegration - Context manager support for automatic cleanup
- Lightweight and easy to integrate into existing projects
Requirements
- Python 3.8+
- MPI implementation (OpenMPI, MPICH, or similar)
mpi4pylibrary
Installation
Install from source
git clone https://github.com/minask/ezmpi.git
cd ezmpi
pip install -e .
Install with development dependencies
pip install -e ".[dev]"
Install with dill support
pip install -e ".[dill]"
Quick Start
Basic Usage
from ezmpi import MPIPool
def square(x):
return x * x
# Create a pool (must be run with mpiexec)
with MPIPool() as pool:
results = pool.map(square, [1, 2, 3, 4, 5])
print(results) # [1, 4, 9, 16, 25]
Run with multiple processes:
mpiexec -n 4 python your_script.py
Using dill for Complex Objects
from ezmpi import MPIPool
def process_data(data):
# Complex processing logic
return sum(data) / len(data)
# Enable dill for better pickling support
with MPIPool(use_dill=True) as pool:
results = pool.map(process_data, [[1, 2, 3], [4, 5, 6], [7, 8, 9]])
print(results) # [2.0, 5.0, 8.0]
MPI Execution
ezMPI requires at least 2 MPI processes (1 master + 1+ workers):
# Minimum: 2 processes
mpiexec -n 2 python script.py
# Typical: 4-8 processes
mpiexec -n 4 python script.py
# On HPC systems
srun -n 32 python script.py
Note: The master process (rank 0) coordinates tasks, all other processes are workers.
API Reference
MPIPool
class MPIPool(comm=None, use_dill=True)
Parameters:
comm: MPI communicator (optional, defaults to MPI.COMM_WORLD)use_dill: Use dill for pickling instead of standard pickle (default: True)
Methods:
map(worker, tasks): Execute worker function on each task in parallelclose(): Shutdown worker processesis_master(): Check if current process is the masteris_worker(): Check if current process is a worker
Development
Setup Development Environment
git clone https://github.com/minask/ezmpi.git
cd ezmpi
pip install -e ".[dev]"
Running Tests
# Run basic tests pytest -v
# Run MPI tests
mpiexec -n 4 pytest -v
# Run with coverage
pytest --cov=ezmpi --cov-report=html
Code Quality
# Lint code
ruff check .
# Format code
ruff format .
# Type checking
mypy src/ezmpi
# Import sorting
isort src/
License
MIT License - see LICENSE file for details.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Acknowledgments
This implementation is inspired by and adapted from similar MPI pool implementations in the scientific Python community.
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 Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ezmpi-0.1.0.tar.gz.
File metadata
- Download URL: ezmpi-0.1.0.tar.gz
- Upload date:
- Size: 36.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c6df664b347ce4d2194ddb6b5ee3d28ee3268416a39f01dc5cf483cc92168d7c
|
|
| MD5 |
9ab5e515f4761ef7833d39d804d3936f
|
|
| BLAKE2b-256 |
a313fe489f31b2f678e1e942d41f0fb93fd180b43381454d31d735ed57d7ceb1
|
Provenance
The following attestation bundles were made for ezmpi-0.1.0.tar.gz:
Publisher:
release.yml on minaskar/ezmpi
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ezmpi-0.1.0.tar.gz -
Subject digest:
c6df664b347ce4d2194ddb6b5ee3d28ee3268416a39f01dc5cf483cc92168d7c - Sigstore transparency entry: 835818422
- Sigstore integration time:
-
Permalink:
minaskar/ezmpi@6407a28cfaf8d1e846ec845724734c9dd8b3959d -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/minaskar
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@6407a28cfaf8d1e846ec845724734c9dd8b3959d -
Trigger Event:
push
-
Statement type:
File details
Details for the file ezmpi-0.1.0-py3-none-any.whl.
File metadata
- Download URL: ezmpi-0.1.0-py3-none-any.whl
- Upload date:
- Size: 8.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5dbbd6904b1d079bad93bcb5d0ab66cf41a54ec53c40384b89c15ccae8d20d6c
|
|
| MD5 |
4a658d1c2bae93f08e1757c7d01a854e
|
|
| BLAKE2b-256 |
d59bacad884253c25383f91c1cb637288c5f82238ef3fc19ee77cfdf5434bf6b
|
Provenance
The following attestation bundles were made for ezmpi-0.1.0-py3-none-any.whl:
Publisher:
release.yml on minaskar/ezmpi
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ezmpi-0.1.0-py3-none-any.whl -
Subject digest:
5dbbd6904b1d079bad93bcb5d0ab66cf41a54ec53c40384b89c15ccae8d20d6c - Sigstore transparency entry: 835818426
- Sigstore integration time:
-
Permalink:
minaskar/ezmpi@6407a28cfaf8d1e846ec845724734c9dd8b3959d -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/minaskar
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@6407a28cfaf8d1e846ec845724734c9dd8b3959d -
Trigger Event:
push
-
Statement type: