Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/technologicat/mpi_shim
MPI support wrapper for optional dependency on mpi4py
https://github.com/technologicat/mpi_shim
mpi mpi4py numpy optional python python2 python27 python3 python34 wrapper
Last synced: about 1 month ago
JSON representation
MPI support wrapper for optional dependency on mpi4py
- Host: GitHub
- URL: https://github.com/technologicat/mpi_shim
- Owner: Technologicat
- License: bsd-2-clause
- Created: 2017-04-26T11:38:23.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2017-04-26T11:40:34.000Z (almost 8 years ago)
- Last Synced: 2024-11-19T05:05:51.582Z (3 months ago)
- Topics: mpi, mpi4py, numpy, optional, python, python2, python27, python3, python34, wrapper
- Language: Python
- Size: 3.91 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.md
Awesome Lists containing this project
README
## mpi_shim
MPI support wrapper for optional dependency on mpi4py
### Introduction
This module is designed to be copied into projects that optionally depend on MPI, to unify handling of MPI and non-MPI cases.
To load MPI, import this module. The module can always be imported, regardless of whether `mpi4py` is installed. The availability of the `mpi4py` library can then be queried at runtime using `mpi_shim.has_mpi()`.
Some rudimentary wrappers (`get_size()`, `get_rank()`, `get_comm_world()`) are provided; all the rest should be done directly via `mpi4py`, and only if `has_mpi()` returns True. This way, the same code can run both with and without MPI.
Also provided is `gather_varlength_array()`, a buffer-based fast gather for rank-1 NumPy arrays of varying lengths (like `gatherv`, but determining the sizes automatically).
### Example
Based on [http://mpi4py.scipy.org/docs/usrman/tutorial.html](http://mpi4py.scipy.org/docs/usrman/tutorial.html):
```python
import mpi_shimMPI = mpi_shim.get_mpi() # either a reference to mpi4py.MPI, or None if n/a
nprocs = mpi_shim.get_size() # actual value from mpi4py, or 1 if n/a
my_id = mpi_shim.get_rank() # actual value from mpi4py, or 0 if n/a
comm = mpi_shim.get_comm_world() # actual value from mpi4py, or None if n/a# The rest works as usual:
data = (my_id+1)**2 #
if MPI is not None:
data = comm.gather(data, root=0)if my_id == 0:
for i in range(nprocs):
assert data[i] == (i+1)**2
else:
assert data is None
```### License
[BSD](LICENSE.md). Copyright 2012-2017 Juha Jeronen and University of Jyväskylä.