mpi4py.util.pkl5¶
New in version 3.1.0.
pickle
protocol 5 (see PEP 574) introduced support for out-of-band
buffers, allowing for more efficient handling of certain object types with
large memory footprints.
MPI for Python uses the traditional in-band handling of buffers. This approach is appropriate for communicating non-buffer Python objects, or buffer-like objects with small memory footprints. For point-to-point communication, in-band buffer handling allows for the communication of a pickled stream with a single MPI message, at the expense of additional CPU and memory overhead in the pickling and unpickling steps.
The mpi4py.util.pkl5
module provides communicator wrapper classes
reimplementing pickle-based point-to-point communication methods using pickle
protocol 5. Handling out-of-band buffers necessarily involve multiple MPI
messages, thus increasing latency and hurting performance in case of small size
data. However, in case of large size data, the zero-copy savings of out-of-band
buffer handling more than offset the extra latency costs. Additionally, these
wrapper methods overcome the infamous 2 GiB message count limit (MPI-1 to
MPI-3).
Note
Support for pickle protocol 5 is available in the pickle
module
within the Python standard library since Python 3.8. Previous Python 3
releases can use the pickle5
backport, which is available on PyPI and can be installed with:
python -m pip install pickle5
- mpi4py.util.pkl5.Request¶
alias of
mpi4py.util.pkl5.
- mpi4py.util.pkl5.Message¶
alias of
mpi4py.util.pkl5.
- mpi4py.util.pkl5.Comm¶
alias of
mpi4py.util.pkl5.
- mpi4py.util.pkl5.Intracomm¶
alias of
mpi4py.util.pkl5.
- mpi4py.util.pkl5.Intercomm¶
alias of
mpi4py.util.pkl5.
Examples¶
test-pkl5-1.py
¶ 1import numpy as np
2from mpi4py import MPI
3from mpi4py.util import pkl5
4
5comm = pkl5.Intracomm(MPI.COMM_WORLD) # comm wrapper
6size = comm.Get_size()
7rank = comm.Get_rank()
8dst = (rank + 1) % size
9src = (rank - 1) % size
10
11sobj = np.full(1024**3, rank, dtype='i4') # > 4 GiB
12sreq = comm.isend(sobj, dst, tag=42)
13robj = comm.recv (None, src, tag=42)
14sreq.Free()
15
16assert np.min(robj) == src
17assert np.max(robj) == src
test-pkl5-2.py
¶ 1import numpy as np
2from mpi4py import MPI
3from mpi4py.util import pkl5
4
5comm = pkl5.Intracomm(MPI.COMM_WORLD) # comm wrapper
6size = comm.Get_size()
7rank = comm.Get_rank()
8dst = (rank + 1) % size
9src = (rank - 1) % size
10
11sobj = np.full(1024**3, rank, dtype='i4') # > 4 GiB
12sreq = comm.isend(sobj, dst, tag=42)
13
14status = MPI.Status()
15rmsg = comm.mprobe(status=status)
16assert status.Get_source() == src
17assert status.Get_tag() == 42
18rreq = rmsg.irecv()
19robj = rreq.wait()
20
21sreq.Free()
22assert np.max(robj) == src
23assert np.min(robj) == src