| MPI4PY(3) | MPI for Python | MPI4PY(3) |
mpi4py - MPI for Python
MPI for Python provides Python bindings for the Message Passing Interface (MPI) standard, allowing Python applications to exploit multiple processors on workstations, clusters and supercomputers.
This package builds on the MPI specification and provides an object oriented interface resembling the MPI-2 C++ bindings. It supports point-to-point (sends, receives) and collective (broadcasts, scatters, gathers) communication of any picklable Python object, as well as efficient communication of Python objects exposing the Python buffer interface (e.g. NumPy arrays and builtin bytes/array/memoryview objects).
Over the last years, high performance computing has become an affordable resource to many more researchers in the scientific community than ever before. The conjunction of quality open source software and commodity hardware strongly influenced the now widespread popularity of Beowulf class clusters and cluster of workstations.
Among many parallel computational models, message-passing has proven to be an effective one. This paradigm is specially suited for (but not limited to) distributed memory architectures and is used in today’s most demanding scientific and engineering application related to modeling, simulation, design, and signal processing. However, portable message-passing parallel programming used to be a nightmare in the past because of the many incompatible options developers were faced to. Fortunately, this situation definitely changed after the MPI Forum released its standard specification.
High performance computing is traditionally associated with software development using compiled languages. However, in typical applications programs, only a small part of the code is time-critical enough to require the efficiency of compiled languages. The rest of the code is generally related to memory management, error handling, input/output, and user interaction, and those are usually the most error prone and time-consuming lines of code to write and debug in the whole development process. Interpreted high-level languages can be really advantageous for this kind of tasks.
For implementing general-purpose numerical computations, MATLAB [1] is the dominant interpreted programming language. In the open source side, Octave and Scilab are well known, freely distributed software packages providing compatibility with the MATLAB language. In this work, we present MPI for Python, a new package enabling applications to exploit multiple processors using standard MPI “look and feel” in Python scripts.
MPI, [mpi-using] [mpi-ref] the Message Passing Interface, is a standardized and portable message-passing system designed to function on a wide variety of parallel computers. The standard defines the syntax and semantics of library routines and allows users to write portable programs in the main scientific programming languages (Fortran, C, or C++).
Since its release, the MPI specification [mpi-std1] [mpi-std2] has become the leading standard for message-passing libraries for parallel computers. Implementations are available from vendors of high-performance computers and from well known open source projects like MPICH [mpi-mpich] and Open MPI [mpi-openmpi].
Python is a modern, easy to learn, powerful programming language. It has efficient high-level data structures and a simple but effective approach to object-oriented programming with dynamic typing and dynamic binding. It supports modules and packages, which encourages program modularity and code reuse. Python’s elegant syntax, together with its interpreted nature, make it an ideal language for scripting and rapid application development in many areas on most platforms.
The Python interpreter and the extensive standard library are available in source or binary form without charge for all major platforms, and can be freely distributed. It is easily extended with new functions and data types implemented in C or C++. Python is also suitable as an extension language for customizable applications.
Python is an ideal candidate for writing the higher-level parts of large-scale scientific applications [Hinsen97] and driving simulations in parallel architectures [Beazley97] like clusters of PC’s or SMP’s. Python codes are quickly developed, easily maintained, and can achieve a high degree of integration with other libraries written in compiled languages.
As this work started and evolved, some ideas were borrowed from well known MPI and Python related open source projects from the Internet.
Additionally, we would like to mention some available tools for scientific computing and software development with Python.
MPI for Python provides an object oriented approach to message passing which grounds on the standard MPI-2 C++ bindings. The interface was designed with focus in translating MPI syntax and semantics of standard MPI-2 bindings for C++ to Python. Any user of the standard C/C++ MPI bindings should be able to use this module without need of learning a new interface.
The Python standard library supports different mechanisms for data persistence. Many of them rely on disk storage, but pickling and marshaling can also work with memory buffers.
The pickle modules provide user-extensible facilities to serialize general Python objects using ASCII or binary formats. The marshal module provides facilities to serialize built-in Python objects using a binary format specific to Python, but independent of machine architecture issues.
MPI for Python can communicate any built-in or user-defined Python object taking advantage of the features provided by the pickle module. These facilities will be routinely used to build binary representations of objects to communicate (at sending processes), and restoring them back (at receiving processes).
Although simple and general, the serialization approach (i.e., pickling and unpickling) previously discussed imposes important overheads in memory as well as processor usage, especially in the scenario of objects with large memory footprints being communicated. Pickling general Python objects, ranging from primitive or container built-in types to user-defined classes, necessarily requires computer resources. Processing is also needed for dispatching the appropriate serialization method (that depends on the type of the object) and doing the actual packing. Additional memory is always needed, and if its total amount is not known a priori, many reallocations can occur. Indeed, in the case of large numeric arrays, this is certainly unacceptable and precludes communication of objects occupying half or more of the available memory resources.
MPI for Python supports direct communication of any object exporting the single-segment buffer interface. This interface is a standard Python mechanism provided by some types (e.g., strings and numeric arrays), allowing access in the C side to a contiguous memory buffer (i.e., address and length) containing the relevant data. This feature, in conjunction with the capability of constructing user-defined MPI datatypes describing complicated memory layouts, enables the implementation of many algorithms involving multidimensional numeric arrays (e.g., image processing, fast Fourier transforms, finite difference schemes on structured Cartesian grids) directly in Python, with negligible overhead, and almost as fast as compiled Fortran, C, or C++ codes.
In MPI for Python, Comm is the base class of communicators. The Intracomm and Intercomm classes are subclasses of the Comm class. The Comm.Is_inter method (and Comm.Is_intra, provided for convenience but not part of the MPI specification) is defined for communicator objects and can be used to determine the particular communicator class.
The two predefined intracommunicator instances are available: COMM_SELF and COMM_WORLD. From them, new communicators can be created as needed.
The number of processes in a communicator and the calling process rank can be respectively obtained with methods Comm.Get_size and Comm.Get_rank. The associated process group can be retrieved from a communicator by calling the Comm.Get_group method, which returns an instance of the Group class. Set operations with Group objects like like Group.Union, Group.Intersection and Group.Difference are fully supported, as well as the creation of new communicators from these groups using Comm.Create and Intracomm.Create_group.
New communicator instances can be obtained with the Comm.Clone, Comm.Dup and Comm.Split methods, as well methods Intracomm.Create_intercomm and Intercomm.Merge.
Virtual topologies (Cartcomm, Graphcomm and Distgraphcomm classes, which are specializations of the Intracomm class) are fully supported. New instances can be obtained from intracommunicator instances with factory methods Intracomm.Create_cart and Intracomm.Create_graph.
Point to point communication is a fundamental capability of message passing systems. This mechanism enables the transmission of data between a pair of processes, one side sending, the other receiving.
MPI provides a set of send and receive functions allowing the communication of typed data with an associated tag. The type information enables the conversion of data representation from one architecture to another in the case of heterogeneous computing environments; additionally, it allows the representation of non-contiguous data layouts and user-defined datatypes, thus avoiding the overhead of (otherwise unavoidable) packing/unpacking operations. The tag information allows selectivity of messages at the receiving end.
MPI provides basic send and receive functions that are blocking. These functions block the caller until the data buffers involved in the communication can be safely reused by the application program.
In MPI for Python, the Comm.Send, Comm.Recv and Comm.Sendrecv methods of communicator objects provide support for blocking point-to-point communications within Intracomm and Intercomm instances. These methods can communicate memory buffers. The variants Comm.send, Comm.recv and Comm.sendrecv can communicate general Python objects.
On many systems, performance can be significantly increased by overlapping communication and computation. This is particularly true on systems where communication can be executed autonomously by an intelligent, dedicated communication controller.
MPI provides nonblocking send and receive functions. They allow the possible overlap of communication and computation. Non-blocking communication always come in two parts: posting functions, which begin the requested operation; and test-for-completion functions, which allow to discover whether the requested operation has completed.
In MPI for Python, the Comm.Isend and Comm.Irecv methods initiate send and receive operations, respectively. These methods return a Request instance, uniquely identifying the started operation. Its completion can be managed using the Request.Test, Request.Wait and Request.Cancel methods. The management of Request objects and associated memory buffers involved in communication requires a careful, rather low-level coordination. Users must ensure that objects exposing their memory buffers are not accessed at the Python level while they are involved in nonblocking message-passing operations.
Often a communication with the same argument list is repeatedly executed within an inner loop. In such cases, communication can be further optimized by using persistent communication, a particular case of nonblocking communication allowing the reduction of the overhead between processes and communication controllers. Furthermore , this kind of optimization can also alleviate the extra call overheads associated to interpreted, dynamic languages like Python.
In MPI for Python, the Comm.Send_init and Comm.Recv_init methods create persistent requests for a send and receive operation, respectively. These methods return an instance of the Prequest class, a subclass of the Request class. The actual communication can be effectively started using the Prequest.Start method, and its completion can be managed as previously described.
Collective communications allow the transmittal of data between multiple processes of a group simultaneously. The syntax and semantics of collective functions is consistent with point-to-point communication. Collective functions communicate typed data, but messages are not paired with an associated tag; selectivity of messages is implied in the calling order. Additionally, collective functions come in blocking versions only.
The more commonly used collective communication operations are the following.
In MPI for Python, the Comm.Bcast, Comm.Scatter, Comm.Gather, Comm.Allgather, Comm.Alltoall methods provide support for collective communications of memory buffers. The lower-case variants Comm.bcast, Comm.scatter, Comm.gather, Comm.allgather and Comm.alltoall can communicate general Python objects. The vector variants (which can communicate different amounts of data to each process) Comm.Scatterv, Comm.Gatherv, Comm.Allgatherv, Comm.Alltoallv and Comm.Alltoallw are also supported, they can only communicate objects exposing memory buffers.
Global reduction operations on memory buffers are accessible through the Comm.Reduce, Comm.Reduce_scatter, Comm.Allreduce, Intracomm.Scan and Intracomm.Exscan methods. The lower-case variants Comm.reduce, Comm.allreduce, Intracomm.scan and Intracomm.exscan can communicate general Python objects; however, the actual required reduction computations are performed sequentially at some process. All the predefined (i.e., SUM, PROD, MAX, etc.) reduction operations can be applied.
Several MPI implementations, including Open MPI and MVAPICH, support passing GPU pointers to MPI calls to avoid explicit data movement between host and device. On the Python side, support for handling GPU arrays have been implemented in many libraries related GPU computation such as CuPy, Numba, PyTorch, and PyArrow. To maximize interoperability across library boundaries, two kinds of zero-copy data exchange protocols have been defined and agreed upon: DLPack and CUDA Array Interface (CAI).
MPI for Python provides an experimental support for GPU-aware MPI. This feature requires:
See the Tutorial section for further information. We note that
In the context of the MPI-1 specification, a parallel application is static; that is, no processes can be added to or deleted from a running application after it has been started. Fortunately, this limitation was addressed in MPI-2. The new specification added a process management model providing a basic interface between an application and external resources and process managers.
This MPI-2 extension can be really useful, especially for sequential applications built on top of parallel modules, or parallel applications with a client/server model. The MPI-2 process model provides a mechanism to create new processes and establish communication between them and the existing MPI application. It also provides mechanisms to establish communication between two existing MPI applications, even when one did not start the other.
In MPI for Python, new independent process groups can be created by calling the Intracomm.Spawn method within an intracommunicator. This call returns a new intercommunicator (i.e., an Intercomm instance) at the parent process group. The child process group can retrieve the matching intercommunicator by calling the Comm.Get_parent class method. At each side, the new intercommunicator can be used to perform point to point and collective communications between the parent and child groups of processes.
Alternatively, disjoint groups of processes can establish communication using a client/server approach. Any server application must first call the Open_port function to open a port and the Publish_name function to publish a provided service, and next call the Intracomm.Accept method. Any client applications can first find a published service by calling the Lookup_name function, which returns the port where a server can be contacted; and next call the Intracomm.Connect method. Both Intracomm.Accept and Intracomm.Connect methods return an Intercomm instance. When connection between client/server processes is no longer needed, all of them must cooperatively call the Comm.Disconnect method. Additionally, server applications should release resources by calling the Unpublish_name and Close_port functions.
One-sided communications (also called Remote Memory Access, RMA) supplements the traditional two-sided, send/receive based MPI communication model with a one-sided, put/get based interface. One-sided communication that can take advantage of the capabilities of highly specialized network hardware. Additionally, this extension lowers latency and software overhead in applications written using a shared-memory-like paradigm.
The MPI specification revolves around the use of objects called windows; they intuitively specify regions of a process’s memory that have been made available for remote read and write operations. The published memory blocks can be accessed through three functions for put (remote send), get (remote write), and accumulate (remote update or reduction) data items. A much larger number of functions support different synchronization styles; the semantics of these synchronization operations are fairly complex.
In MPI for Python, one-sided operations are available by using instances of the Win class. New window objects are created by calling the Win.Create method at all processes within a communicator and specifying a memory buffer . When a window instance is no longer needed, the Win.Free method should be called.
The three one-sided MPI operations for remote write, read and reduction are available through calling the methods Win.Put, Win.Get, and Win.Accumulate respectively within a Win instance. These methods need an integer rank identifying the target process and an integer offset relative the base address of the remote memory block being accessed.
The one-sided operations read, write, and reduction are implicitly nonblocking, and must be synchronized by using two primary modes. Active target synchronization requires the origin process to call the Win.Start and Win.Complete methods at the origin process, and target process cooperates by calling the Win.Post and Win.Wait methods. There is also a collective variant provided by the Win.Fence method. Passive target synchronization is more lenient, only the origin process calls the Win.Lock and Win.Unlock methods. Locks are used to protect remote accesses to the locked remote window and to protect local load/store accesses to a locked local window.
The POSIX standard provides a model of a widely portable file system. However, the optimization needed for parallel input/output cannot be achieved with this generic interface. In order to ensure efficiency and scalability, the underlying parallel input/output system must provide a high-level interface supporting partitioning of file data among processes and a collective interface supporting complete transfers of global data structures between process memories and files. Additionally, further efficiencies can be gained via support for asynchronous input/output, strided accesses to data, and control over physical file layout on storage devices. This scenario motivated the inclusion in the MPI-2 standard of a custom interface in order to support more elaborated parallel input/output operations.
The MPI specification for parallel input/output revolves around the use objects called files. As defined by MPI, files are not just contiguous byte streams. Instead, they are regarded as ordered collections of typed data items. MPI supports sequential or random access to any integral set of these items. Furthermore, files are opened collectively by a group of processes.
The common patterns for accessing a shared file (broadcast, scatter, gather, reduction) is expressed by using user-defined datatypes. Compared to the communication patterns of point-to-point and collective communications, this approach has the advantage of added flexibility and expressiveness. Data access operations (read and write) are defined for different kinds of positioning (using explicit offsets, individual file pointers, and shared file pointers), coordination (non-collective and collective), and synchronism (blocking, nonblocking, and split collective with begin/end phases).
In MPI for Python, all MPI input/output operations are performed through instances of the File class. File handles are obtained by calling the File.Open method at all processes within a communicator and providing a file name and the intended access mode. After use, they must be closed by calling the File.Close method. Files even can be deleted by calling method File.Delete.
After creation, files are typically associated with a per-process view. The view defines the current set of data visible and accessible from an open file as an ordered set of elementary datatypes. This data layout can be set and queried with the File.Set_view and File.Get_view methods respectively.
Actual input/output operations are achieved by many methods combining read and write calls with different behavior regarding positioning, coordination, and synchronism. Summing up, MPI for Python provides the thirty (30) methods defined in MPI-2 for reading from or writing to files using explicit offsets or file pointers (individual or shared), in blocking or nonblocking and collective or noncollective versions.
Module functions Init or Init_thread and Finalize provide MPI initialization and finalization respectively. Module functions Is_initialized and Is_finalized provide the respective tests for initialization and finalization.
NOTE:
NOTE:
MPI timer functionalities are available through the Wtime and Wtick functions.
In order to facilitate handle sharing with other Python modules interfacing MPI-based parallel libraries, the predefined MPI error handlers ERRORS_RETURN and ERRORS_ARE_FATAL can be assigned to and retrieved from communicators using methods Comm.Set_errhandler and Comm.Get_errhandler, and similarly for windows and files. New custom error handlers can be created with Comm.Create_errhandler.
When the predefined error handler ERRORS_RETURN is set, errors returned from MPI calls within Python code will raise an instance of the exception class Exception, which is a subclass of the standard Python exception RuntimeError.
NOTE:
WARNING:
WARNING:
TIP:
TIP:
MPI for Python supports convenient, pickle-based communication of generic Python object as well as fast, near C-speed, direct array data communication of buffer-provider objects (e.g., NumPy arrays).
You have to use methods with all-lowercase names, like Comm.send, Comm.recv, Comm.bcast, Comm.scatter, Comm.gather . An object to be sent is passed as a parameter to the communication call, and the received object is simply the return value.
The Comm.isend and Comm.irecv methods return Request instances; completion of these methods can be managed using the Request.test and Request.wait methods.
The Comm.recv and Comm.irecv methods may be passed a buffer object that can be repeatedly used to receive messages avoiding internal memory allocation. This buffer must be sufficiently large to accommodate the transmitted messages; hence, any buffer passed to Comm.recv or Comm.irecv must be at least as long as the pickled data transmitted to the receiver.
Collective calls like Comm.scatter, Comm.gather, Comm.allgather, Comm.alltoall expect a single value or a sequence of Comm.size elements at the root or all process. They return a single value, a list of Comm.size elements, or None.
NOTE:
You have to use method names starting with an upper-case letter, like Comm.Send, Comm.Recv, Comm.Bcast, Comm.Scatter, Comm.Gather.
In general, buffer arguments to these calls must be explicitly specified by using a 2/3-list/tuple like [data, MPI.DOUBLE], or [data, count, MPI.DOUBLE] (the former one uses the byte-size of data and the extent of the MPI datatype to define count).
For vector collectives communication operations like Comm.Scatterv and Comm.Gatherv, buffer arguments are specified as [data, count, displ, datatype], where count and displ are sequences of integral values.
Automatic MPI datatype discovery for NumPy/GPU arrays and PEP-3118 buffers is supported, but limited to basic C types (all C/C99-native signed/unsigned integral types and single/double precision real/complex floating types) and availability of matching datatypes in the underlying MPI implementation. In this case, the buffer-provider object can be passed directly as a buffer argument, the count and MPI datatype will be inferred.
If mpi4py is built against a GPU-aware MPI implementation, GPU arrays can be passed to upper-case methods as long as they have either the __dlpack__ and __dlpack_device__ methods or the __cuda_array_interface__ attribute that are compliant with the respective standard specifications. Moreover, only C-contiguous or Fortran-contiguous GPU arrays are supported. It is important to note that GPU buffers must be fully ready before any MPI routines operate on them to avoid race conditions. This can be ensured by using the synchronization API of your array library. mpi4py does not have access to any GPU-specific functionality and thus cannot perform this operation automatically for users.
Most MPI programs can be run with the command mpiexec. In practice, running Python programs looks like:
$ mpiexec -n 4 python script.py
to run the program with 4 processors.
from mpi4py import MPI comm = MPI.COMM_WORLD rank = comm.Get_rank() if rank == 0:
data = {'a': 7, 'b': 3.14}
comm.send(data, dest=1, tag=11) elif rank == 1:
data = comm.recv(source=0, tag=11)
from mpi4py import MPI comm = MPI.COMM_WORLD rank = comm.Get_rank() if rank == 0:
data = {'a': 7, 'b': 3.14}
req = comm.isend(data, dest=1, tag=11)
req.wait() elif rank == 1:
req = comm.irecv(source=0, tag=11)
data = req.wait()
from mpi4py import MPI import numpy comm = MPI.COMM_WORLD rank = comm.Get_rank() # passing MPI datatypes explicitly if rank == 0:
data = numpy.arange(1000, dtype='i')
comm.Send([data, MPI.INT], dest=1, tag=77) elif rank == 1:
data = numpy.empty(1000, dtype='i')
comm.Recv([data, MPI.INT], source=0, tag=77) # automatic MPI datatype discovery if rank == 0:
data = numpy.arange(100, dtype=numpy.float64)
comm.Send(data, dest=1, tag=13) elif rank == 1:
data = numpy.empty(100, dtype=numpy.float64)
comm.Recv(data, source=0, tag=13)
from mpi4py import MPI comm = MPI.COMM_WORLD rank = comm.Get_rank() if rank == 0:
data = {'key1' : [7, 2.72, 2+3j],
'key2' : ( 'abc', 'xyz')} else:
data = None data = comm.bcast(data, root=0)
from mpi4py import MPI comm = MPI.COMM_WORLD size = comm.Get_size() rank = comm.Get_rank() if rank == 0:
data = [(i+1)**2 for i in range(size)] else:
data = None data = comm.scatter(data, root=0) assert data == (rank+1)**2
from mpi4py import MPI comm = MPI.COMM_WORLD size = comm.Get_size() rank = comm.Get_rank() data = (rank+1)**2 data = comm.gather(data, root=0) if rank == 0:
for i in range(size):
assert data[i] == (i+1)**2 else:
assert data is None
from mpi4py import MPI import numpy as np comm = MPI.COMM_WORLD rank = comm.Get_rank() if rank == 0:
data = np.arange(100, dtype='i') else:
data = np.empty(100, dtype='i') comm.Bcast(data, root=0) for i in range(100):
assert data[i] == i
from mpi4py import MPI import numpy as np comm = MPI.COMM_WORLD size = comm.Get_size() rank = comm.Get_rank() sendbuf = None if rank == 0:
sendbuf = np.empty([size, 100], dtype='i')
sendbuf.T[:,:] = range(size) recvbuf = np.empty(100, dtype='i') comm.Scatter(sendbuf, recvbuf, root=0) assert np.allclose(recvbuf, rank)
from mpi4py import MPI import numpy as np comm = MPI.COMM_WORLD size = comm.Get_size() rank = comm.Get_rank() sendbuf = np.zeros(100, dtype='i') + rank recvbuf = None if rank == 0:
recvbuf = np.empty([size, 100], dtype='i') comm.Gather(sendbuf, recvbuf, root=0) if rank == 0:
for i in range(size):
assert np.allclose(recvbuf[i,:], i)
from mpi4py import MPI import numpy def matvec(comm, A, x):
m = A.shape[0] # local rows
p = comm.Get_size()
xg = numpy.zeros(m*p, dtype='d')
comm.Allgather([x, MPI.DOUBLE],
[xg, MPI.DOUBLE])
y = numpy.dot(A, xg)
return y
from mpi4py import MPI import numpy as np amode = MPI.MODE_WRONLY|MPI.MODE_CREATE comm = MPI.COMM_WORLD fh = MPI.File.Open(comm, "./datafile.contig", amode) buffer = np.empty(10, dtype=np.int) buffer[:] = comm.Get_rank() offset = comm.Get_rank()*buffer.nbytes fh.Write_at_all(offset, buffer) fh.Close()
from mpi4py import MPI import numpy as np comm = MPI.COMM_WORLD rank = comm.Get_rank() size = comm.Get_size() amode = MPI.MODE_WRONLY|MPI.MODE_CREATE fh = MPI.File.Open(comm, "./datafile.noncontig", amode) item_count = 10 buffer = np.empty(item_count, dtype='i') buffer[:] = rank filetype = MPI.INT.Create_vector(item_count, 1, size) filetype.Commit() displacement = MPI.INT.Get_size()*rank fh.Set_view(displacement, filetype=filetype) fh.Write_all(buffer) filetype.Free() fh.Close()
#!/usr/bin/env python from mpi4py import MPI import numpy import sys comm = MPI.COMM_SELF.Spawn(sys.executable,
args=['cpi.py'],
maxprocs=5) N = numpy.array(100, 'i') comm.Bcast([N, MPI.INT], root=MPI.ROOT) PI = numpy.array(0.0, 'd') comm.Reduce(None, [PI, MPI.DOUBLE],
op=MPI.SUM, root=MPI.ROOT) print(PI) comm.Disconnect()
#!/usr/bin/env python from mpi4py import MPI import numpy comm = MPI.Comm.Get_parent() size = comm.Get_size() rank = comm.Get_rank() N = numpy.array(0, dtype='i') comm.Bcast([N, MPI.INT], root=0) h = 1.0 / N; s = 0.0 for i in range(rank, N, size):
x = h * (i + 0.5)
s += 4.0 / (1.0 + x**2) PI = numpy.array(s * h, dtype='d') comm.Reduce([PI, MPI.DOUBLE], None,
op=MPI.SUM, root=0) comm.Disconnect()
from mpi4py import MPI import cupy as cp comm = MPI.COMM_WORLD size = comm.Get_size() rank = comm.Get_rank() sendbuf = cp.arange(10, dtype='i') recvbuf = cp.empty_like(sendbuf) cp.cuda.get_current_stream().synchronize() comm.Allreduce(sendbuf, recvbuf) assert cp.allclose(recvbuf, sendbuf*size)
import numpy as np from mpi4py import MPI from mpi4py.util import dtlib comm = MPI.COMM_WORLD rank = comm.Get_rank() datatype = MPI.FLOAT np_dtype = dtlib.to_numpy_dtype(datatype) itemsize = datatype.Get_size() N = 10 win_size = N * itemsize if rank == 0 else 0 win = MPI.Win.Allocate(win_size, comm=comm) buf = np.empty(N, dtype=np_dtype) if rank == 0:
buf.fill(42)
win.Lock(rank=0)
win.Put(buf, target_rank=0)
win.Unlock(rank=0)
comm.Barrier() else:
comm.Barrier()
win.Lock(rank=0)
win.Get(buf, target_rank=0)
win.Unlock(rank=0)
assert np.all(buf == 42)
import numpy as np from mpi4py import MPI from mpi4py.util import dtlib comm = MPI.COMM_WORLD rank = comm.Get_rank() datatype = MPI.FLOAT np_dtype = dtlib.to_numpy_dtype(datatype) itemsize = datatype.Get_size() N = comm.Get_size() + 1 win_size = N * itemsize if rank == 0 else 0 win = MPI.Win.Allocate(
size=win_size,
disp_unit=itemsize,
comm=comm, ) if rank == 0:
mem = np.frombuffer(win, dtype=np_dtype)
mem[:] = np.arange(len(mem), dtype=np_dtype) comm.Barrier() buf = np.zeros(3, dtype=np_dtype) target = (rank, 2, datatype) win.Lock(rank=0) win.Get(buf, target_rank=0, target=target) win.Unlock(rank=0) assert np.all(buf == [rank, rank+1, 0])
/* file: helloworld.c */
void sayhello(MPI_Comm comm)
{
int size, rank;
MPI_Comm_size(comm, &size);
MPI_Comm_rank(comm, &rank);
printf("Hello, World! "
"I am process %d of %d.\n",
rank, size);
}
// file: helloworld.i
%module helloworld
%{
#include <mpi.h>
#include "helloworld.c"
}%
%include mpi4py/mpi4py.i
%mpi4py_typemap(Comm, MPI_Comm);
void sayhello(MPI_Comm comm);
>>> from mpi4py import MPI >>> import helloworld >>> helloworld.sayhello(MPI.COMM_WORLD) Hello, World! I am process 0 of 1.
! file: helloworld.f90 subroutine sayhello(comm)
use mpi
implicit none
integer :: comm, rank, size, ierr
call MPI_Comm_size(comm, size, ierr)
call MPI_Comm_rank(comm, rank, ierr)
print *, 'Hello, World! I am process ',rank,' of ',size,'.' end subroutine sayhello
$ f2py -c --f90exec=mpif90 helloworld.f90 -m helloworld
>>> from mpi4py import MPI >>> import helloworld >>> fcomm = MPI.COMM_WORLD.py2f() >>> helloworld.sayhello(fcomm) Hello, World! I am process 0 of 1.
The MPI for Python package.
The Message Passing Interface (MPI) is a standardized and portable message-passing system designed to function on a wide variety of parallel computers. The MPI standard defines the syntax and semantics of library routines and allows users to write portable programs in the main scientific programming languages (Fortran, C, or C++). Since its release, the MPI specification has become the leading standard for message-passing libraries for parallel computers.
MPI for Python provides MPI bindings for the Python programming language, allowing any Python program to exploit multiple processors. This package build on the MPI specification and provides an object oriented interface which closely follows MPI-2 C++ bindings.
Attributes Summary
| initialize | Automatic MPI initialization at import |
| threads | Request initialization with thread support |
| thread_level | Level of thread support to request |
| finalize | Automatic MPI finalization at exit |
| fast_reduce | Use tree-based reductions for objects |
| recv_mprobe | Use matched probes to receive objects |
| irecv_bufsz | Default buffer size in bytes for irecv() |
| errors | Error handling policy |
Attributes Documentation
SEE ALSO:
Added in version 4.0.0.
Example
MPI for Python features automatic initialization and finalization of the MPI execution environment. By using the mpi4py.rc object, MPI initialization and finalization can be handled programmatically:
import mpi4py mpi4py.rc.initialize = False # do not initialize MPI automatically mpi4py.rc.finalize = False # do not finalize MPI automatically from mpi4py import MPI # import the 'MPI' module MPI.Init() # manual initialization of the MPI environment ... # your finest code here ... MPI.Finalize() # manual finalization of the MPI environment
The following environment variables override the corresponding attributes of the mpi4py.rc and MPI.pickle objects at import time of the MPI module.
NOTE:
Whether to automatically initialize MPI at import time of the mpi4py.MPI module.
SEE ALSO:
Added in version 4.0.0.
Whether to automatically finalize MPI at exit time of the Python process.
SEE ALSO:
Added in version 4.0.0.
Whether to initialize MPI with thread support.
SEE ALSO:
Added in version 3.1.0.
The level of required thread support.
SEE ALSO:
Added in version 3.1.0.
Whether to use tree-based reductions for objects.
SEE ALSO:
Added in version 3.1.0.
Whether to use matched probes to receive objects.
SEE ALSO:
Default buffer size in bytes for irecv().
SEE ALSO:
Added in version 4.0.0.
Controls default MPI error handling policy.
SEE ALSO:
Added in version 3.1.0.
Controls the default pickle protocol to use when communicating Python objects.
SEE ALSO:
Added in version 3.1.0.
Controls the default buffer size threshold for switching from in-band to out-of-band buffer handling when using pickle protocol version 5 or higher.
SEE ALSO:
Added in version 3.1.2.
Extension modules that need to compile against mpi4py should use this function to locate the appropriate include directory. Using Python distutils (or perhaps NumPy distutils):
import mpi4py
Extension('extension_name', ...
include_dirs=[..., mpi4py.get_include()])
Changed in version 4.0.0: By default, this function returns an empty dictionary. However, downstream packagers and distributors may alter such behavior. To that end, MPI information must be provided under an mpi section within a UTF-8 encoded INI-style configuration file mpi.cfg located at the top-level package directory. The configuration file is read and parsed using the configparser module.
Ancillary
| Datatype | Datatype object. |
| Status | Status object. |
| Request | Request handler. |
| Prequest | Persistent request handler. |
| Grequest | Generalized request handler. |
| Op | Reduction operation. |
| Group | Group of processes. |
| Info | Info object. |
| Session | Session context. |
Communication
| Comm | Communication context. |
| Intracomm | Intracommunicator. |
| Topocomm | Topology intracommunicator. |
| Cartcomm | Cartesian topology intracommunicator. |
| Graphcomm | General graph topology intracommunicator. |
| Distgraphcomm | Distributed graph topology intracommunicator. |
| Intercomm | Intercommunicator. |
| Message | Matched message. |
One-sided operations
| Win | Remote memory access context. |
Input/Output
| File | File I/O context. |
Error handling
| Errhandler | Error handler. |
| Exception | Exception class. |
Auxiliary
| Pickle | Pickle/unpickle Python objects. |
| buffer | Buffer. |
Version inquiry
| Get_version() | Obtain the version number of the MPI standard. |
| Get_library_version() | Obtain the version string of the MPI library. |
Initialization and finalization
| Init() | Initialize the MPI execution environment. |
| Init_thread([required]) | Initialize the MPI execution environment. |
| Finalize() | Terminate the MPI execution environment. |
| Is_initialized() | Indicate whether Init has been called. |
| Is_finalized() | Indicate whether Finalize has completed. |
| Query_thread() | Return the level of thread support provided by the MPI library. |
| Is_thread_main() | Indicate whether this thread called Init or Init_thread. |
Memory allocation
| Alloc_mem(size[, info]) | Allocate memory for message passing and remote memory access. |
| Free_mem(mem) | Free memory allocated with Alloc_mem. |
Address manipulation
| Get_address(location) | Get the address of a location in memory. |
| Aint_add(base, disp) | Return the sum of base address and displacement. |
| Aint_diff(addr1, addr2) | Return the difference between absolute addresses. |
Timer
| Wtick() | Return the resolution of Wtime. |
| Wtime() | Return an elapsed time on the calling processor. |
Error handling
| Get_error_class(errorcode) | Convert an error code into an error class. |
| Get_error_string(errorcode) | Return the error string for a given error class or error code. |
| Add_error_class() | Add an error class to the known error classes. |
| Add_error_code(errorclass) | Add an error code to an error class. |
| Add_error_string(errorcode, string) | Associate an error string with an error class or error code. |
| Remove_error_class(errorclass) | Remove an error class from the known error classes. |
| Remove_error_code(errorcode) | Remove an error code from the known error codes. |
| Remove_error_string(errorcode) | Remove error string association from error class or error code. |
Dynamic process management
| Open_port([info]) | Return an address used to connect group of processes. |
| Close_port(port_name) | Close a port. |
| Publish_name(service_name, port_name[, info]) | Publish a service name. |
| Unpublish_name(service_name, port_name[, info]) | Unpublish a service name. |
| Lookup_name(service_name[, info]) | Lookup a port name given a service name. |
Miscellanea
| Attach_buffer(buf) | Attach a user-provided buffer for sending in buffered mode. |
| Detach_buffer() | Remove an existing attached buffer. |
| Flush_buffer() | Block until all buffered messages have been transmitted. |
| Iflush_buffer() | Nonblocking flush for buffered messages. |
| Compute_dims(nnodes, dims) | Return a balanced distribution of processes per coordinate direction. |
| Get_processor_name() | Obtain the name of the calling processor. |
| Register_datarep(datarep, read_fn, write_fn, ...) | Register user-defined data representations. |
| Pcontrol(level) | Control profiling. |
Utilities
| get_vendor() | Information about the underlying MPI implementation. |
| UNDEFINED | Constant UNDEFINED of type int |
| ANY_SOURCE | Constant ANY_SOURCE of type int |
| ANY_TAG | Constant ANY_TAG of type int |
| PROC_NULL | Constant PROC_NULL of type int |
| ROOT | Constant ROOT of type int |
| BOTTOM | Constant BOTTOM of type BottomType |
| IN_PLACE | Constant IN_PLACE of type InPlaceType |
| BUFFER_AUTOMATIC | Constant BUFFER_AUTOMATIC of type BufferAutomaticType |
| KEYVAL_INVALID | Constant KEYVAL_INVALID of type int |
| TAG_UB | Constant TAG_UB of type int |
| IO | Constant IO of type int |
| WTIME_IS_GLOBAL | Constant WTIME_IS_GLOBAL of type int |
| UNIVERSE_SIZE | Constant UNIVERSE_SIZE of type int |
| APPNUM | Constant APPNUM of type int |
| LASTUSEDCODE | Constant LASTUSEDCODE of type int |
| WIN_BASE | Constant WIN_BASE of type int |
| WIN_SIZE | Constant WIN_SIZE of type int |
| WIN_DISP_UNIT | Constant WIN_DISP_UNIT of type int |
| WIN_CREATE_FLAVOR | Constant WIN_CREATE_FLAVOR of type int |
| WIN_FLAVOR | Constant WIN_FLAVOR of type int |
| WIN_MODEL | Constant WIN_MODEL of type int |
| SUCCESS | Constant SUCCESS of type int |
| ERR_LASTCODE | Constant ERR_LASTCODE of type int |
| ERR_COMM | Constant ERR_COMM of type int |
| ERR_GROUP | Constant ERR_GROUP of type int |
| ERR_TYPE | Constant ERR_TYPE of type int |
| ERR_REQUEST | Constant ERR_REQUEST of type int |
| ERR_OP | Constant ERR_OP of type int |
| ERR_ERRHANDLER | Constant ERR_ERRHANDLER of type int |
| ERR_BUFFER | Constant ERR_BUFFER of type int |
| ERR_COUNT | Constant ERR_COUNT of type int |
| ERR_TAG | Constant ERR_TAG of type int |
| ERR_RANK | Constant ERR_RANK of type int |
| ERR_ROOT | Constant ERR_ROOT of type int |
| ERR_TRUNCATE | Constant ERR_TRUNCATE of type int |
| ERR_IN_STATUS | Constant ERR_IN_STATUS of type int |
| ERR_PENDING | Constant ERR_PENDING of type int |
| ERR_TOPOLOGY | Constant ERR_TOPOLOGY of type int |
| ERR_DIMS | Constant ERR_DIMS of type int |
| ERR_ARG | Constant ERR_ARG of type int |
| ERR_OTHER | Constant ERR_OTHER of type int |
| ERR_UNKNOWN | Constant ERR_UNKNOWN of type int |
| ERR_INTERN | Constant ERR_INTERN of type int |
| ERR_INFO | Constant ERR_INFO of type int |
| ERR_FILE | Constant ERR_FILE of type int |
| ERR_WIN | Constant ERR_WIN of type int |
| ERR_KEYVAL | Constant ERR_KEYVAL of type int |
| ERR_INFO_KEY | Constant ERR_INFO_KEY of type int |
| ERR_INFO_VALUE | Constant ERR_INFO_VALUE of type int |
| ERR_INFO_NOKEY | Constant ERR_INFO_NOKEY of type int |
| ERR_ACCESS | Constant ERR_ACCESS of type int |
| ERR_AMODE | Constant ERR_AMODE of type int |
| ERR_BAD_FILE | Constant ERR_BAD_FILE of type int |
| ERR_FILE_EXISTS | Constant ERR_FILE_EXISTS of type int |
| ERR_FILE_IN_USE | Constant ERR_FILE_IN_USE of type int |
| ERR_NO_SPACE | Constant ERR_NO_SPACE of type int |
| ERR_NO_SUCH_FILE | Constant ERR_NO_SUCH_FILE of type int |
| ERR_IO | Constant ERR_IO of type int |
| ERR_READ_ONLY | Constant ERR_READ_ONLY of type int |
| ERR_CONVERSION | Constant ERR_CONVERSION of type int |
| ERR_DUP_DATAREP | Constant ERR_DUP_DATAREP of type int |
| ERR_UNSUPPORTED_DATAREP | Constant ERR_UNSUPPORTED_DATAREP of type int |
| ERR_UNSUPPORTED_OPERATION | Constant ERR_UNSUPPORTED_OPERATION of type int |
| ERR_NAME | Constant ERR_NAME of type int |
| ERR_NO_MEM | Constant ERR_NO_MEM of type int |
| ERR_NOT_SAME | Constant ERR_NOT_SAME of type int |
| ERR_PORT | Constant ERR_PORT of type int |
| ERR_QUOTA | Constant ERR_QUOTA of type int |
| ERR_SERVICE | Constant ERR_SERVICE of type int |
| ERR_SPAWN | Constant ERR_SPAWN of type int |
| ERR_BASE | Constant ERR_BASE of type int |
| ERR_SIZE | Constant ERR_SIZE of type int |
| ERR_DISP | Constant ERR_DISP of type int |
| ERR_ASSERT | Constant ERR_ASSERT of type int |
| ERR_LOCKTYPE | Constant ERR_LOCKTYPE of type int |
| ERR_RMA_CONFLICT | Constant ERR_RMA_CONFLICT of type int |
| ERR_RMA_SYNC | Constant ERR_RMA_SYNC of type int |
| ERR_RMA_RANGE | Constant ERR_RMA_RANGE of type int |
| ERR_RMA_ATTACH | Constant ERR_RMA_ATTACH of type int |
| ERR_RMA_SHARED | Constant ERR_RMA_SHARED of type int |
| ERR_RMA_FLAVOR | Constant ERR_RMA_FLAVOR of type int |
| ORDER_C | Constant ORDER_C of type int |
| ORDER_F | Constant ORDER_F of type int |
| ORDER_FORTRAN | Constant ORDER_FORTRAN of type int |
| TYPECLASS_INTEGER | Constant TYPECLASS_INTEGER of type int |
| TYPECLASS_REAL | Constant TYPECLASS_REAL of type int |
| TYPECLASS_COMPLEX | Constant TYPECLASS_COMPLEX of type int |
| DISTRIBUTE_NONE | Constant DISTRIBUTE_NONE of type int |
| DISTRIBUTE_BLOCK | Constant DISTRIBUTE_BLOCK of type int |
| DISTRIBUTE_CYCLIC | Constant DISTRIBUTE_CYCLIC of type int |
| DISTRIBUTE_DFLT_DARG | Constant DISTRIBUTE_DFLT_DARG of type int |
| COMBINER_NAMED | Constant COMBINER_NAMED of type int |
| COMBINER_DUP | Constant COMBINER_DUP of type int |
| COMBINER_CONTIGUOUS | Constant COMBINER_CONTIGUOUS of type int |
| COMBINER_VECTOR | Constant COMBINER_VECTOR of type int |
| COMBINER_HVECTOR | Constant COMBINER_HVECTOR of type int |
| COMBINER_INDEXED | Constant COMBINER_INDEXED of type int |
| COMBINER_HINDEXED | Constant COMBINER_HINDEXED of type int |
| COMBINER_INDEXED_BLOCK | Constant COMBINER_INDEXED_BLOCK of type int |
| COMBINER_HINDEXED_BLOCK | Constant COMBINER_HINDEXED_BLOCK of type int |
| COMBINER_STRUCT | Constant COMBINER_STRUCT of type int |
| COMBINER_SUBARRAY | Constant COMBINER_SUBARRAY of type int |
| COMBINER_DARRAY | Constant COMBINER_DARRAY of type int |
| COMBINER_RESIZED | Constant COMBINER_RESIZED of type int |
| COMBINER_VALUE_INDEX | Constant COMBINER_VALUE_INDEX of type int |
| COMBINER_F90_REAL | Constant COMBINER_F90_REAL of type int |
| COMBINER_F90_COMPLEX | Constant COMBINER_F90_COMPLEX of type int |
| COMBINER_F90_INTEGER | Constant COMBINER_F90_INTEGER of type int |
| IDENT | Constant IDENT of type int |
| CONGRUENT | Constant CONGRUENT of type int |
| SIMILAR | Constant SIMILAR of type int |
| UNEQUAL | Constant UNEQUAL of type int |
| CART | Constant CART of type int |
| GRAPH | Constant GRAPH of type int |
| DIST_GRAPH | Constant DIST_GRAPH of type int |
| UNWEIGHTED | Constant UNWEIGHTED of type int |
| WEIGHTS_EMPTY | Constant WEIGHTS_EMPTY of type int |
| COMM_TYPE_SHARED | Constant COMM_TYPE_SHARED of type int |
| BSEND_OVERHEAD | Constant BSEND_OVERHEAD of type int |
| WIN_FLAVOR_CREATE | Constant WIN_FLAVOR_CREATE of type int |
| WIN_FLAVOR_ALLOCATE | Constant WIN_FLAVOR_ALLOCATE of type int |
| WIN_FLAVOR_DYNAMIC | Constant WIN_FLAVOR_DYNAMIC of type int |
| WIN_FLAVOR_SHARED | Constant WIN_FLAVOR_SHARED of type int |
| WIN_SEPARATE | Constant WIN_SEPARATE of type int |
| WIN_UNIFIED | Constant WIN_UNIFIED of type int |
| MODE_NOCHECK | Constant MODE_NOCHECK of type int |
| MODE_NOSTORE | Constant MODE_NOSTORE of type int |
| MODE_NOPUT | Constant MODE_NOPUT of type int |
| MODE_NOPRECEDE | Constant MODE_NOPRECEDE of type int |
| MODE_NOSUCCEED | Constant MODE_NOSUCCEED of type int |
| LOCK_EXCLUSIVE | Constant LOCK_EXCLUSIVE of type int |
| LOCK_SHARED | Constant LOCK_SHARED of type int |
| MODE_RDONLY | Constant MODE_RDONLY of type int |
| MODE_WRONLY | Constant MODE_WRONLY of type int |
| MODE_RDWR | Constant MODE_RDWR of type int |
| MODE_CREATE | Constant MODE_CREATE of type int |
| MODE_EXCL | Constant MODE_EXCL of type int |
| MODE_DELETE_ON_CLOSE | Constant MODE_DELETE_ON_CLOSE of type int |
| MODE_UNIQUE_OPEN | Constant MODE_UNIQUE_OPEN of type int |
| MODE_SEQUENTIAL | Constant MODE_SEQUENTIAL of type int |
| MODE_APPEND | Constant MODE_APPEND of type int |
| SEEK_SET | Constant SEEK_SET of type int |
| SEEK_CUR | Constant SEEK_CUR of type int |
| SEEK_END | Constant SEEK_END of type int |
| DISPLACEMENT_CURRENT | Constant DISPLACEMENT_CURRENT of type int |
| DISP_CUR | Constant DISP_CUR of type int |
| THREAD_SINGLE | Constant THREAD_SINGLE of type int |
| THREAD_FUNNELED | Constant THREAD_FUNNELED of type int |
| THREAD_SERIALIZED | Constant THREAD_SERIALIZED of type int |
| THREAD_MULTIPLE | Constant THREAD_MULTIPLE of type int |
| VERSION | Constant VERSION of type int |
| SUBVERSION | Constant SUBVERSION of type int |
| MAX_PROCESSOR_NAME | Constant MAX_PROCESSOR_NAME of type int |
| MAX_ERROR_STRING | Constant MAX_ERROR_STRING of type int |
| MAX_PORT_NAME | Constant MAX_PORT_NAME of type int |
| MAX_INFO_KEY | Constant MAX_INFO_KEY of type int |
| MAX_INFO_VAL | Constant MAX_INFO_VAL of type int |
| MAX_OBJECT_NAME | Constant MAX_OBJECT_NAME of type int |
| MAX_DATAREP_STRING | Constant MAX_DATAREP_STRING of type int |
| MAX_LIBRARY_VERSION_STRING | Constant MAX_LIBRARY_VERSION_STRING of type int |
| DATATYPE_NULL | Object DATATYPE_NULL of type Datatype |
| PACKED | Object PACKED of type Datatype |
| BYTE | Object BYTE of type Datatype |
| AINT | Object AINT of type Datatype |
| OFFSET | Object OFFSET of type Datatype |
| COUNT | Object COUNT of type Datatype |
| CHAR | Object CHAR of type Datatype |
| WCHAR | Object WCHAR of type Datatype |
| SIGNED_CHAR | Object SIGNED_CHAR of type Datatype |
| SHORT | Object SHORT of type Datatype |
| INT | Object INT of type Datatype |
| LONG | Object LONG of type Datatype |
| LONG_LONG | Object LONG_LONG of type Datatype |
| UNSIGNED_CHAR | Object UNSIGNED_CHAR of type Datatype |
| UNSIGNED_SHORT | Object UNSIGNED_SHORT of type Datatype |
| UNSIGNED | Object UNSIGNED of type Datatype |
| UNSIGNED_LONG | Object UNSIGNED_LONG of type Datatype |
| UNSIGNED_LONG_LONG | Object UNSIGNED_LONG_LONG of type Datatype |
| FLOAT | Object FLOAT of type Datatype |
| DOUBLE | Object DOUBLE of type Datatype |
| LONG_DOUBLE | Object LONG_DOUBLE of type Datatype |
| C_BOOL | Object C_BOOL of type Datatype |
| INT8_T | Object INT8_T of type Datatype |
| INT16_T | Object INT16_T of type Datatype |
| INT32_T | Object INT32_T of type Datatype |
| INT64_T | Object INT64_T of type Datatype |
| UINT8_T | Object UINT8_T of type Datatype |
| UINT16_T | Object UINT16_T of type Datatype |
| UINT32_T | Object UINT32_T of type Datatype |
| UINT64_T | Object UINT64_T of type Datatype |
| C_COMPLEX | Object C_COMPLEX of type Datatype |
| C_FLOAT_COMPLEX | Object C_FLOAT_COMPLEX of type Datatype |
| C_DOUBLE_COMPLEX | Object C_DOUBLE_COMPLEX of type Datatype |
| C_LONG_DOUBLE_COMPLEX | Object C_LONG_DOUBLE_COMPLEX of type Datatype |
| CXX_BOOL | Object CXX_BOOL of type Datatype |
| CXX_FLOAT_COMPLEX | Object CXX_FLOAT_COMPLEX of type Datatype |
| CXX_DOUBLE_COMPLEX | Object CXX_DOUBLE_COMPLEX of type Datatype |
| CXX_LONG_DOUBLE_COMPLEX | Object CXX_LONG_DOUBLE_COMPLEX of type Datatype |
| SHORT_INT | Object SHORT_INT of type Datatype |
| INT_INT | Object INT_INT of type Datatype |
| TWOINT | Object TWOINT of type Datatype |
| LONG_INT | Object LONG_INT of type Datatype |
| FLOAT_INT | Object FLOAT_INT of type Datatype |
| DOUBLE_INT | Object DOUBLE_INT of type Datatype |
| LONG_DOUBLE_INT | Object LONG_DOUBLE_INT of type Datatype |
| CHARACTER | Object CHARACTER of type Datatype |
| LOGICAL | Object LOGICAL of type Datatype |
| INTEGER | Object INTEGER of type Datatype |
| REAL | Object REAL of type Datatype |
| DOUBLE_PRECISION | Object DOUBLE_PRECISION of type Datatype |
| COMPLEX | Object COMPLEX of type Datatype |
| DOUBLE_COMPLEX | Object DOUBLE_COMPLEX of type Datatype |
| LOGICAL1 | Object LOGICAL1 of type Datatype |
| LOGICAL2 | Object LOGICAL2 of type Datatype |
| LOGICAL4 | Object LOGICAL4 of type Datatype |
| LOGICAL8 | Object LOGICAL8 of type Datatype |
| INTEGER1 | Object INTEGER1 of type Datatype |
| INTEGER2 | Object INTEGER2 of type Datatype |
| INTEGER4 | Object INTEGER4 of type Datatype |
| INTEGER8 | Object INTEGER8 of type Datatype |
| INTEGER16 | Object INTEGER16 of type Datatype |
| REAL2 | Object REAL2 of type Datatype |
| REAL4 | Object REAL4 of type Datatype |
| REAL8 | Object REAL8 of type Datatype |
| REAL16 | Object REAL16 of type Datatype |
| COMPLEX4 | Object COMPLEX4 of type Datatype |
| COMPLEX8 | Object COMPLEX8 of type Datatype |
| COMPLEX16 | Object COMPLEX16 of type Datatype |
| COMPLEX32 | Object COMPLEX32 of type Datatype |
| UNSIGNED_INT | Object UNSIGNED_INT of type Datatype |
| SIGNED_SHORT | Object SIGNED_SHORT of type Datatype |
| SIGNED_INT | Object SIGNED_INT of type Datatype |
| SIGNED_LONG | Object SIGNED_LONG of type Datatype |
| SIGNED_LONG_LONG | Object SIGNED_LONG_LONG of type Datatype |
| BOOL | Object BOOL of type Datatype |
| SINT8_T | Object SINT8_T of type Datatype |
| SINT16_T | Object SINT16_T of type Datatype |
| SINT32_T | Object SINT32_T of type Datatype |
| SINT64_T | Object SINT64_T of type Datatype |
| F_BOOL | Object F_BOOL of type Datatype |
| F_INT | Object F_INT of type Datatype |
| F_FLOAT | Object F_FLOAT of type Datatype |
| F_DOUBLE | Object F_DOUBLE of type Datatype |
| F_COMPLEX | Object F_COMPLEX of type Datatype |
| F_FLOAT_COMPLEX | Object F_FLOAT_COMPLEX of type Datatype |
| F_DOUBLE_COMPLEX | Object F_DOUBLE_COMPLEX of type Datatype |
| REQUEST_NULL | Object REQUEST_NULL of type Request |
| MESSAGE_NULL | Object MESSAGE_NULL of type Message |
| MESSAGE_NO_PROC | Object MESSAGE_NO_PROC of type Message |
| OP_NULL | Object OP_NULL of type Op |
| MAX | Object MAX of type Op |
| MIN | Object MIN of type Op |
| SUM | Object SUM of type Op |
| PROD | Object PROD of type Op |
| LAND | Object LAND of type Op |
| BAND | Object BAND of type Op |
| LOR | Object LOR of type Op |
| BOR | Object BOR of type Op |
| LXOR | Object LXOR of type Op |
| BXOR | Object BXOR of type Op |
| MAXLOC | Object MAXLOC of type Op |
| MINLOC | Object MINLOC of type Op |
| REPLACE | Object REPLACE of type Op |
| NO_OP | Object NO_OP of type Op |
| GROUP_NULL | Object GROUP_NULL of type Group |
| GROUP_EMPTY | Object GROUP_EMPTY of type Group |
| INFO_NULL | Object INFO_NULL of type Info |
| INFO_ENV | Object INFO_ENV of type Info |
| ERRHANDLER_NULL | Object ERRHANDLER_NULL of type Errhandler |
| ERRORS_RETURN | Object ERRORS_RETURN of type Errhandler |
| ERRORS_ARE_FATAL | Object ERRORS_ARE_FATAL of type Errhandler |
| COMM_NULL | Object COMM_NULL of type Comm |
| COMM_SELF | Object COMM_SELF of type Intracomm |
| COMM_WORLD | Object COMM_WORLD of type Intracomm |
| WIN_NULL | Object WIN_NULL of type Win |
| FILE_NULL | Object FILE_NULL of type File |
| pickle | Object pickle of type Pickle |
Added in version 4.0.0.
This module provides type aliases used to add type hints to the various functions and methods within the MPI module.
SEE ALSO:
Types Summary
| SupportsBuffer | Python buffer protocol. |
| SupportsDLPack | DLPack data interchange protocol. |
| SupportsCAI | CUDA Array Interface (CAI) protocol. |
| Buffer | Buffer-like object. |
| Bottom | Start of the address range. |
| InPlace | In-place buffer argument. |
| Aint | Address-sized integral type. |
| Count | Integral type for counts. |
| Displ | Integral type for displacements. |
| Offset | Integral type for offsets. |
| TypeSpec | Datatype specification. |
| BufSpec | Buffer specification. |
| BufSpecB | Buffer specification (block). |
| BufSpecV | Buffer specification (vector). |
| BufSpecW | Buffer specification (generalized). |
| TargetSpec | Target specification. |
Types Documentation
SEE ALSO:
SEE ALSO:
SEE ALSO:
alias of SupportsBuffer | SupportsDLPack | SupportsCAI
alias of BottomType | None
alias of InPlaceType | None
alias of numbers.Integral
alias of numbers.Integral
alias of numbers.Integral
alias of numbers.Integral
alias of Datatype | str
alias of SupportsBuffer | SupportsDLPack | SupportsCAI | Tuple[SupportsBuffer | SupportsDLPack | SupportsCAI, Integral] | Tuple[SupportsBuffer | SupportsDLPack | SupportsCAI, Datatype | str] | Tuple[SupportsBuffer | SupportsDLPack | SupportsCAI, Integral, Datatype | str] | Tuple[BottomType | None, Integral, Datatype] | List[Any]
alias of SupportsBuffer | SupportsDLPack | SupportsCAI | Tuple[SupportsBuffer | SupportsDLPack | SupportsCAI, Integral] | Tuple[SupportsBuffer | SupportsDLPack | SupportsCAI, Datatype | str] | Tuple[SupportsBuffer | SupportsDLPack | SupportsCAI, Integral, Datatype | str] | List[Any]
alias of SupportsBuffer | SupportsDLPack | SupportsCAI | Tuple[SupportsBuffer | SupportsDLPack | SupportsCAI, Sequence[Integral]] | Tuple[SupportsBuffer | SupportsDLPack | SupportsCAI, Tuple[Sequence[Integral], Sequence[Integral]]] | Tuple[SupportsBuffer | SupportsDLPack | SupportsCAI, Datatype | str] | Tuple[SupportsBuffer | SupportsDLPack | SupportsCAI, Sequence[Integral], Datatype | str] | Tuple[SupportsBuffer | SupportsDLPack | SupportsCAI, Tuple[Sequence[Integral], Sequence[Integral]], Datatype | str] | Tuple[SupportsBuffer | SupportsDLPack | SupportsCAI, Sequence[Integral], Sequence[Integral], Datatype | str] | Tuple[BottomType | None, Tuple[Sequence[Integral], Sequence[Integral]], Datatype] | Tuple[BottomType | None, Sequence[Integral], Sequence[Integral], Datatype] | List[Any]
alias of Tuple[SupportsBuffer | SupportsDLPack | SupportsCAI, Sequence[Datatype]] | Tuple[SupportsBuffer | SupportsDLPack | SupportsCAI, Tuple[Sequence[Integral], Sequence[Integral]], Sequence[Datatype]] | Tuple[SupportsBuffer | SupportsDLPack | SupportsCAI, Sequence[Integral], Sequence[Integral], Sequence[Datatype]] | Tuple[BottomType | None, Tuple[Sequence[Integral], Sequence[Integral]], Sequence[Datatype]] | Tuple[BottomType | None, Sequence[Integral], Sequence[Integral], Sequence[Datatype]] | List[Any]
alias of Integral | Tuple | Tuple[Integral] | Tuple[Integral, Integral] | Tuple[Integral, Integral, Datatype | str] | List[Any]
Added in version 3.0.0.
This package provides a high-level interface for asynchronously executing callables on a pool of worker processes using MPI for inter-process communication.
The mpi4py.futures package is based on concurrent.futures from the Python standard library. More precisely, mpi4py.futures provides the MPIPoolExecutor class as a concrete implementation of the abstract class Executor. The submit() interface schedules a callable to be executed asynchronously and returns a Future object representing the execution of the callable. Future instances can be queried for the call result or exception. Sets of Future instances can be passed to the wait() and as_completed() functions.
SEE ALSO:
The MPIPoolExecutor class uses a pool of MPI processes to execute calls asynchronously. By performing computations in separate processes, it allows to side-step the global interpreter lock but also means that only picklable objects can be executed and returned. The __main__ module must be importable by worker processes, thus MPIPoolExecutor instances may not work in the interactive interpreter.
MPIPoolExecutor takes advantage of the dynamic process management features introduced in the MPI-2 standard. In particular, the MPI.Intracomm.Spawn method of MPI.COMM_SELF is used in the master (or parent) process to spawn new worker (or child) processes running a Python interpreter. The master process uses a separate thread (one for each MPIPoolExecutor instance) to communicate back and forth with the workers. The worker processes serve the execution of tasks in the main (and only) thread until they are signaled for completion.
NOTE:
WARNING:
initializer is an optional callable that is called at the start of each worker process before executing any tasks; initargs is a tuple of arguments passed to the initializer. If initializer raises an exception, all pending tasks and any attempt to submit new tasks to the pool will raise a BrokenExecutor exception.
Other parameters:
executor = MPIPoolExecutor(max_workers=1) future = executor.submit(pow, 321, 1234) print(future.result())
executor = MPIPoolExecutor(max_workers=3) for result in executor.map(pow, [2]*32, range(32)):
print(result)
executor = MPIPoolExecutor(max_workers=3) iterable = ((2, n) for n in range(32)) for result in executor.starmap(pow, iterable):
print(result)
If wait is True then this method will not return until all the pending futures are done executing and the resources associated with the executor have been freed. If wait is False then this method will return immediately and the resources associated with the executor will be freed when all pending futures are done executing. Regardless of the value of wait, the entire Python program will not exit until all pending futures are done executing.
If cancel_futures is True, this method will cancel all pending futures that the executor has not started running. Any futures that are completed or running won’t be cancelled, regardless of the value of cancel_futures.
You can avoid having to call this method explicitly if you use the with statement, which will shutdown the executor instance (waiting as if shutdown() were called with wait set to True).
import time with MPIPoolExecutor(max_workers=1) as executor:
future = executor.submit(time.sleep, 2) assert future.done()
Added in version 3.1.0.
Added in version 4.0.0.
Added in version 4.0.0.
NOTE:
WARNING:
Legacy MPI-1 implementations (as well as some vendor MPI-2 implementations) do not support the dynamic process management features introduced in the MPI-2 standard. Additionally, job schedulers and batch systems in supercomputing facilities may pose additional complications to applications using the MPI_Comm_spawn() routine.
With these issues in mind, mpi4py.futures supports an additional, more traditional, SPMD-like usage pattern requiring MPI-1 calls only. Python applications are started the usual way, e.g., using the mpiexec command. Python code should make a collective call to the MPICommExecutor context manager to partition the set of MPI processes within a MPI communicator in one master processes and many workers processes. The master process gets access to an MPIPoolExecutor instance to submit tasks. Meanwhile, the worker process follow a different execution path and team-up to execute the tasks submitted from the master.
Besides alleviating the lack of dynamic process management features in legacy MPI-1 or partial MPI-2 implementations, the MPICommExecutor context manager may be useful in classic MPI-based Python applications willing to take advantage of the simple, task-based, master/worker approach available in the mpi4py.futures package.
from mpi4py import MPI from mpi4py.futures import MPICommExecutor with MPICommExecutor(MPI.COMM_WORLD, root=0) as executor:
if executor is not None:
future = executor.submit(abs, -42)
assert future.result() == 42
answer = set(executor.map(abs, [-42, 42]))
assert answer == {42}
WARNING:
Recalling the issues related to the lack of support for dynamic process management features in MPI implementations, mpi4py.futures supports an alternative usage pattern where Python code (either from scripts, modules, or zip files) is run under command line control of the mpi4py.futures package by passing -m mpi4py.futures to the python executable. The mpi4py.futures invocation should be passed a pyfile path to a script (or a zipfile/directory containing a __main__.py file). Additionally, mpi4py.futures accepts -m mod to execute a module named mod, -c cmd to execute a command string cmd, or even - to read commands from standard input (sys.stdin). Summarizing, mpi4py.futures can be invoked in the following ways:
Before starting the main script execution, mpi4py.futures splits MPI.COMM_WORLD in one master (the process with rank 0 in MPI.COMM_WORLD) and numprocs - 1 workers and connects them through an MPI intercommunicator. Afterwards, the master process proceeds with the execution of the user script code, which eventually creates MPIPoolExecutor instances to submit tasks. Meanwhile, the worker processes follow a different execution path to serve the master. Upon successful termination of the main script at the master, the entire MPI execution environment exists gracefully. In case of any unhandled exception in the main script, the master process calls MPI.COMM_WORLD.Abort(1) to prevent deadlocks and force termination of entire MPI execution environment.
WARNING:
SEE ALSO:
The mpi4py.futures package favors an embarrassingly parallel execution model involving a series of sequential tasks independent of each other and executed asynchronously. Albeit unnatural, MPIPoolExecutor can still be used for handling workloads involving parallel tasks, where worker processes communicate and coordinate each other via MPI.
Executing parallel tasks with mpi4py.futures requires following some rules, cf. highlighted lines in example cpi.py :
The mpi4py.futures package provides additional utilities for handling Future instances.
The following julia.py script computes the Julia set and dumps an image to disk in binary PGM format. The code starts by importing MPIPoolExecutor from the mpi4py.futures package. Next, some global constants and functions implement the computation of the Julia set. The computations are protected with the standard if __name__ == '__main__': ... idiom. The image is computed by whole scanlines submitting all these tasks at once using the map method. The result iterator yields scanlines in-order as the tasks complete. Finally, each scanline is dumped to disk.
julia.py
from mpi4py.futures import MPIPoolExecutor x0, x1, w = -2.0, +2.0, 640*2 y0, y1, h = -1.5, +1.5, 480*2 dx = (x1 - x0) / w dy = (y1 - y0) / h c = complex(0, 0.65) def julia(x, y):
z = complex(x, y)
n = 255
while abs(z) < 3 and n > 1:
z = z**2 + c
n -= 1
return n def julia_line(k):
line = bytearray(w)
y = y1 - k * dy
for j in range(w):
x = x0 + j * dx
line[j] = julia(x, y)
return line if __name__ == '__main__':
with MPIPoolExecutor() as executor:
image = executor.map(julia_line, range(h))
with open('julia.pgm', 'wb') as f:
f.write(b'P5 %d %d %d\n' % (w, h, 255))
for line in image:
f.write(line)
The recommended way to execute the script is by using the mpiexec command specifying one MPI process (master) and (optional but recommended) the desired MPI universe size, which determines the number of additional dynamically spawned processes (workers). The MPI universe size is provided either by a batch system or set by the user via command-line arguments to mpiexec or environment variables. Below we provide examples for MPICH and Open MPI implementations [1]. In all of these examples, the mpiexec command launches a single master process running the Python interpreter and executing the main script. When required, mpi4py.futures spawns the pool of 16 worker processes. The master submits tasks to the workers and waits for the results. The workers receive incoming tasks, execute them, and send back the results to the master.
When using MPICH implementation or its derivatives based on the Hydra process manager, users can set the MPI universe size via the -usize argument to mpiexec:
$ mpiexec -n 1 -usize 17 python julia.py
or, alternatively, by setting the MPIEXEC_UNIVERSE_SIZE environment variable:
$ env MPIEXEC_UNIVERSE_SIZE=17 mpiexec -n 1 python julia.py
In the Open MPI implementation, the MPI universe size can be set via the -host argument to mpiexec:
$ mpiexec -n 1 -host localhost:17 python julia.py
Another way to specify the number of workers is to use the mpi4py.futures-specific environment variable MPI4PY_FUTURES_MAX_WORKERS:
$ env MPI4PY_FUTURES_MAX_WORKERS=16 mpiexec -n 1 python julia.py
Note that in this case, the MPI universe size is ignored.
Alternatively, users may decide to execute the script in a more traditional way, that is, all the MPI processes are started at once. The user script is run under command-line control of mpi4py.futures passing the -m flag to the python executable:
$ mpiexec -n 17 python -m mpi4py.futures julia.py
As explained previously, the 17 processes are partitioned in one master and 16 workers. The master process executes the main script while the workers execute the tasks submitted by the master.
The number \pi can be approximated via numerical integration with the simple midpoint rule, that is:
\pi = \int_{0}^{1} \frac{4}{1+x^2} \,dx \approx
\frac{1}{n} \sum_{i=1}^{n} \frac{4}{1 + \left[\frac{1}{n}
\left(i-\frac{1}{2}\right) \right]^2} .
The following cpi.py script computes such approximations using mpi4py.futures with a parallel task involving a collective reduction operation. Highlighted lines correspond to the rules discussed in Parallel tasks.
cpi.py
import math import sys from mpi4py.futures import MPIPoolExecutor, wait from mpi4py.futures import get_comm_workers def compute_pi(n):
# Access intracommunicator and synchronize
comm = get_comm_workers()
comm.Barrier()
rank = comm.Get_rank()
size = comm.Get_size()
# Local computation
h = 1.0 / n
s = 0.0
for i in range(rank + 1, n + 1, size):
x = h * (i - 0.5)
s += 4.0 / (1.0 + x**2)
pi_partial = s * h
# Parallel reduce-to-all
pi = comm.allreduce(pi_partial)
# All workers return the same value
return pi if __name__ == '__main__':
n = int(sys.argv[1]) if len(sys.argv) > 1 else 256
with MPIPoolExecutor() as executor:
# Submit exactly one callable per worker
P = executor.num_workers
fs = [executor.submit(compute_pi, n) for _ in range(P)]
# Wait for all workers to finish
wait(fs)
# Get result from the first future object.
# In this particular example, due to using reduce-to-all,
# all the other future objects hold the same result value.
pi = fs[0].result()
print(
f"pi: {pi:.16f}, error: {abs(pi - math.pi):.3e}",
f"({n:d} intervals, {P:d} workers)",
)
To run in modern MPI-2 mode:
$ env MPI4PY_FUTURES_MAX_WORKERS=4 mpiexec -n 1 python cpi.py 128 pi: 3.1415977398528137, error: 5.086e-06 (128 intervals, 4 workers) $ env MPI4PY_FUTURES_MAX_WORKERS=8 mpiexec -n 1 python cpi.py 512 pi: 3.1415929714812316, error: 3.179e-07 (512 intervals, 8 workers)
To run in legacy MPI-1 mode:
$ mpiexec -n 5 python -m mpi4py.futures cpi.py 128 pi: 3.1415977398528137, error: 5.086e-06 (128 intervals, 4 workers) $ mpiexec -n 9 python -m mpi4py.futures cpi.py 512 pi: 3.1415929714812316, error: 3.179e-07 (512 intervals, 8 workers)
If mpi4py.futures been significant to a project that leads to an academic publication, please acknowledge our work by citing the following article [mpi4py-futures]:
Added in version 3.1.0.
The mpi4py.util package collects miscellaneous utilities within the intersection of Python and MPI.
Added in version 3.1.0.
The mpi4py.util.dtlib module provides converter routines between NumPy and MPI datatypes.
Added 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 and collective communication methods using pickle protocol 5. Handling out-of-band buffers necessarily involves 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:
python -m pip install pickle5
Custom request class for nonblocking communications.
NOTE:
Custom message class for matching probes.
NOTE:
Base communicator wrapper class.
WARNING:
Added in version 3.1.0.
Added in version 4.0.0.
Added in version 4.0.0.
Added in version 4.0.0.
Added in version 4.0.0.
Intracommunicator wrapper class.
Intercommunicator wrapper class.
test-pkl5-1.py
import numpy as np from mpi4py import MPI from mpi4py.util import pkl5 comm = pkl5.Intracomm(MPI.COMM_WORLD) # comm wrapper size = comm.Get_size() rank = comm.Get_rank() dst = (rank + 1) % size src = (rank - 1) % size sobj = np.full(1024**3, rank, dtype='i4') # > 4 GiB sreq = comm.isend(sobj, dst, tag=42) robj = comm.recv (None, src, tag=42) sreq.Free() assert np.min(robj) == src assert np.max(robj) == src
test-pkl5-2.py
import numpy as np from mpi4py import MPI from mpi4py.util import pkl5 comm = pkl5.Intracomm(MPI.COMM_WORLD) # comm wrapper size = comm.Get_size() rank = comm.Get_rank() dst = (rank + 1) % size src = (rank - 1) % size sobj = np.full(1024**3, rank, dtype='i4') # > 4 GiB sreq = comm.isend(sobj, dst, tag=42) status = MPI.Status() rmsg = comm.mprobe(status=status) assert status.Get_source() == src assert status.Get_tag() == 42 rreq = rmsg.irecv() robj = rreq.wait() sreq.Free() assert np.max(robj) == src assert np.min(robj) == src
Added in version 4.0.0.
SEE ALSO:
NOTE:
NOTE:
WARNING:
Equivalent to func(*args, **kwds).
Equivalent to list(map(func, iterable)).
Block until all results are ready and return them in a list.
The iterable is choped into a number of chunks which are submitted as separate tasks. The (approximate) size of these chunks can be specified by setting chunksize to a positive integer.
Consider using imap() or imap_unordered() with explicit chunksize for better efficiency.
Equivalent to map(func, iterable).
Equivalent to list(itertools.starmap(func, iterable)).
Block until all results are ready and return them in a list.
The iterable is choped into a number of chunks which are submitted as separate tasks. The (approximate) size of these chunks can be specified by setting chunksize to a positive integer.
Consider using istarmap() or istarmap_unordered() with explicit chunksize for better efficiency.
Equivalent to itertools.starmap(func, iterable).
Pool using threads as workers.
If timeout is not None and the result does not arrive within timeout seconds then raise TimeoutError.
If the remote call raised an exception then that exception will be reraised.
If the result is not ready then raise ValueError.
Result type of apply_async().
Result type of map_async() and starmap_async().
Added in version 4.0.0.
The mpi4py.util.sync module provides parallel synchronization utilities.
Context manager for sequential execution within a group of MPI processes.
The implementation is based in MPI-1 point-to-point communication. A process with rank i waits in a blocking receive until the previous process rank i-1 finish executing and signals the next rank i with a send.
Produce consecutive values within a group of MPI processes. The counter interface is close to that of itertools.count.
The implementation is based in MPI-3 one-sided operations. A root process (typically rank 0) holds the counter, and its value is queried and incremented with an atomic RMA fetch-and-add operation.
Establish a critical section or mutual exclusion among MPI processes.
The mutex interface is close to that of threading.Lock and threading.RLock, allowing the use of either recursive or non-recursive mutual exclusion. However, a mutex should be used within a group of MPI processes, not threads.
In non-recursive mode, the semantics of Mutex are somewhat different than these of threading.Lock:
This mutex implementation uses the scalable and fair spinlock algorithm from [mcs-paper] and took inspiration from the MPI-3 RMA implementation of [uam-book].
A condition variable allows one or more MPI processes to wait until they are notified by another processes.
The condition variable interface is close to that of threading.Condition, allowing the use of either recursive or non-recursive mutual exclusion. However, the condition variable should be used within a group of MPI processes, not threads.
This condition variable implementation uses a MPI-3 RMA-based scalable and fair circular queue algorithm to track the set of waiting processes.
A semaphore object manages an internal counter which is decremented by each acquire() call and incremented by each release() call. The internal counter never reaches a value below zero; when acquire() finds that it is zero, it blocks and waits until some other process calls release().
The semaphore interface is close to that of threading.Semaphore and threading.BoundedSemaphore, allowing the use of either bounded (default) or unbounded semaphores. With a bounded semaphore, the internal counter never exceeds its initial value; otherwise release() raises ValueError.
This semaphore implementation uses a global Counter and a Condition variable to handle waiting and and notification.
test-sync-1.py
from mpi4py import MPI from mpi4py.util.sync import Counter, Sequential comm = MPI.COMM_WORLD counter = Counter(comm) with Sequential(comm):
value = next(counter) counter.free() assert comm.rank == value
test-sync-2.py
from mpi4py import MPI from mpi4py.util.sync import Counter, Mutex comm = MPI.COMM_WORLD mutex = Mutex(comm) counter = Counter(comm) with mutex:
value = next(counter) counter.free() mutex.free() assert (
list(range(comm.size)) ==
sorted(comm.allgather(value)) )
Added in version 3.0.0.
At import time, mpi4py initializes the MPI execution environment calling MPI_Init_thread() and installs an exit hook to automatically call MPI_Finalize() just before the Python process terminates. Additionally, mpi4py overrides the default ERRORS_ARE_FATAL error handler in favor of ERRORS_RETURN, which allows translating MPI errors in Python exceptions. These departures from standard MPI behavior may be controversial, but are quite convenient within the highly dynamic Python programming environment. Third-party code using mpi4py can just from mpi4py import MPI and perform MPI calls without the tedious initialization/finalization handling. MPI errors, once translated automatically to Python exceptions, can be dealt with the common try…except…finally clauses; unhandled MPI exceptions will print a traceback which helps in locating problems in source code.
Unfortunately, the interplay of automatic MPI finalization and unhandled exceptions may lead to deadlocks. In unattended runs, these deadlocks will drain the battery of your laptop, or burn precious allocation hours in your supercomputing facility.
Consider the following snippet of Python code. Assume this code is stored in a standard Python script file and run with mpiexec in two or more processes.
deadlock.py
from mpi4py import MPI assert MPI.COMM_WORLD.Get_size() > 1 rank = MPI.COMM_WORLD.Get_rank() if rank == 0:
1/0
MPI.COMM_WORLD.send(None, dest=1, tag=42) elif rank == 1:
MPI.COMM_WORLD.recv(source=0, tag=42)
Process 0 raises ZeroDivisionError exception before performing a send call to process 1. As the exception is not handled, the Python interpreter running in process 0 will proceed to exit with non-zero status. However, as mpi4py installed a finalizer hook to call MPI_Finalize() before exit, process 0 will block waiting for other processes to also enter the MPI_Finalize() call. Meanwhile, process 1 will block waiting for a message to arrive from process 0, thus never reaching to MPI_Finalize(). The whole MPI execution environment is irremediably in a deadlock state.
To alleviate this issue, mpi4py offers a simple, alternative command line execution mechanism based on using the -m flag and implemented with the runpy module. To use this features, Python code should be run passing -m mpi4py in the command line invoking the Python interpreter. In case of unhandled exceptions, the finalizer hook will call MPI_Abort() on the MPI_COMM_WORLD communicator, thus effectively aborting the MPI execution environment.
WARNING:
The use of -m mpi4py to execute Python code on the command line resembles that of the Python interpreter.
SEE ALSO:
Added in version 3.0.0.
| mpi4py.MPI | Message Passing Interface. |
Message Passing Interface.
Classes
| BottomType | Type of BOTTOM. |
| BufferAutomaticType | Type of BUFFER_AUTOMATIC. |
| Cartcomm | Cartesian topology intracommunicator. |
| Comm | Communication context. |
| Datatype | Datatype object. |
| Distgraphcomm | Distributed graph topology intracommunicator. |
| Errhandler | Error handler. |
| File | File I/O context. |
| Graphcomm | General graph topology intracommunicator. |
| Grequest | Generalized request handler. |
| Group | Group of processes. |
| InPlaceType | Type of IN_PLACE. |
| Info | Info object. |
| Intercomm | Intercommunicator. |
| Intracomm | Intracommunicator. |
| Message | Matched message. |
| Op | Reduction operation. |
| Pickle | Pickle/unpickle Python objects. |
| Prequest | Persistent request handler. |
| Request | Request handler. |
| Session | Session context. |
| Status | Status object. |
| Topocomm | Topology intracommunicator. |
| Win | Remote memory access context. |
| buffer | Buffer. |
| memory | alias of buffer |
Type of BUFFER_AUTOMATIC.
Cartesian topology intracommunicator.
Methods Summary
| Get_cart_rank(coords) | Translate logical coordinates to ranks. |
| Get_coords(rank) | Translate ranks to logical coordinates. |
| Get_dim() | Return number of dimensions. |
| Get_topo() | Return information on the cartesian topology. |
| Shift(direction, disp) | Return a process ranks for data shifting with Sendrecv. |
| Sub(remain_dims) | Return a lower-dimensional Cartesian topology. |
Attributes Summary
| coords | Coordinates. |
| dim | Number of dimensions. |
| dims | Dimensions. |
| ndim | Number of dimensions. |
| periods | Periodicity. |
| topo | Topology information. |
Methods Documentation
Attributes Documentation
Communication context.
Methods Summary
| Abort([errorcode]) | Terminate the MPI execution environment. |
| Ack_failed([num_to_ack]) | Acknowledge failures on a communicator. |
| Agree(flag) | Blocking agreement. |
| Allgather(sendbuf, recvbuf) | Gather to All. |
| Allgather_init(sendbuf, recvbuf[, info]) | Persistent Gather to All. |
| Allgatherv(sendbuf, recvbuf) | Gather to All Vector. |
| Allgatherv_init(sendbuf, recvbuf[, info]) | Persistent Gather to All Vector. |
| Allreduce(sendbuf, recvbuf[, op]) | Reduce to All. |
| Allreduce_init(sendbuf, recvbuf[, op, info]) | Persistent Reduce to All. |
| Alltoall(sendbuf, recvbuf) | All to All Scatter/Gather. |
| Alltoall_init(sendbuf, recvbuf[, info]) | Persistent All to All Scatter/Gather. |
| Alltoallv(sendbuf, recvbuf) | All to All Scatter/Gather Vector. |
| Alltoallv_init(sendbuf, recvbuf[, info]) | Persistent All to All Scatter/Gather Vector. |
| Alltoallw(sendbuf, recvbuf) | All to All Scatter/Gather General. |
| Alltoallw_init(sendbuf, recvbuf[, info]) | Persistent All to All Scatter/Gather General. |
| Attach_buffer(buf) | Attach a user-provided buffer for sending in buffered mode. |
| Barrier() | Barrier synchronization. |
| Barrier_init([info]) | Persistent Barrier. |
| Bcast(buf[, root]) | Broadcast data from one process to all other processes. |
| Bcast_init(buf[, root, info]) | Persistent Broadcast. |
| Bsend(buf, dest[, tag]) | Blocking send in buffered mode. |
| Bsend_init(buf, dest[, tag]) | Persistent request for a send in buffered mode. |
| Call_errhandler(errorcode) | Call the error handler installed on a communicator. |
| Clone() | Clone an existing communicator. |
| Compare(comm) | Compare two communicators. |
| Create(group) | Create communicator from group. |
| Create_errhandler(errhandler_fn) | Create a new error handler for communicators. |
| Create_keyval([copy_fn, delete_fn, nopython]) | Create a new attribute key for communicators. |
| Delete_attr(keyval) | Delete attribute value associated with a key. |
| Detach_buffer() | Remove an existing attached buffer. |
| Disconnect() | Disconnect from a communicator. |
| Dup([info]) | Duplicate a communicator. |
| Dup_with_info(info) | Duplicate a communicator with hints. |
| Flush_buffer() | Block until all buffered messages have been transmitted. |
| Free() | Free a communicator. |
| Free_keyval(keyval) | Free an attribute key for communicators. |
| Gather(sendbuf, recvbuf[, root]) | Gather data to one process from all other processes. |
| Gather_init(sendbuf, recvbuf[, root, info]) | Persistent Gather. |
| Gatherv(sendbuf, recvbuf[, root]) | Gather Vector. |
| Gatherv_init(sendbuf, recvbuf[, root, info]) | Persistent Gather Vector. |
| Get_attr(keyval) | Retrieve attribute value by key. |
| Get_errhandler() | Get the error handler for a communicator. |
| Get_failed() | Extract the group of failed processes. |
| Get_group() | Access the group associated with a communicator. |
| Get_info() | Return the current hints for a communicator. |
| Get_name() | Get the print name for this communicator. |
| Get_parent() | Return the parent intercommunicator for this process. |
| Get_rank() | Return the rank of this process in a communicator. |
| Get_size() | Return the number of processes in a communicator. |
| Get_topology() | Return the type of topology (if any) associated with a communicator. |
| Iagree(flag) | Nonblocking agreement. |
| Iallgather(sendbuf, recvbuf) | Nonblocking Gather to All. |
| Iallgatherv(sendbuf, recvbuf) | Nonblocking Gather to All Vector. |
| Iallreduce(sendbuf, recvbuf[, op]) | Nonblocking Reduce to All. |
| Ialltoall(sendbuf, recvbuf) | Nonblocking All to All Scatter/Gather. |
| Ialltoallv(sendbuf, recvbuf) | Nonblocking All to All Scatter/Gather Vector. |
| Ialltoallw(sendbuf, recvbuf) | Nonblocking All to All Scatter/Gather General. |
| Ibarrier() | Nonblocking Barrier. |
| Ibcast(buf[, root]) | Nonblocking Broadcast. |
| Ibsend(buf, dest[, tag]) | Nonblocking send in buffered mode. |
| Idup([info]) | Nonblocking duplicate a communicator. |
| Idup_with_info(info) | Nonblocking duplicate a communicator with hints. |
| Iflush_buffer() | Nonblocking flush for buffered messages. |
| Igather(sendbuf, recvbuf[, root]) | Nonblocking Gather. |
| Igatherv(sendbuf, recvbuf[, root]) | Nonblocking Gather Vector. |
| Improbe([source, tag, status]) | Nonblocking test for a matched message. |
| Iprobe([source, tag, status]) | Nonblocking test for a message. |
| Irecv(buf[, source, tag]) | Nonblocking receive. |
| Ireduce(sendbuf, recvbuf[, op, root]) | Nonblocking Reduce to Root. |
| Ireduce_scatter(sendbuf, recvbuf[, ...]) | Nonblocking Reduce-Scatter (vector version). |
| Ireduce_scatter_block(sendbuf, recvbuf[, op]) | Nonblocking Reduce-Scatter Block (regular, non-vector version). |
| Irsend(buf, dest[, tag]) | Nonblocking send in ready mode. |
| Is_inter() | Return whether the communicator is an intercommunicator. |
| Is_intra() | Return whether the communicator is an intracommunicator. |
| Is_revoked() | Indicate whether the communicator has been revoked. |
| Iscatter(sendbuf, recvbuf[, root]) | Nonblocking Scatter. |
| Iscatterv(sendbuf, recvbuf[, root]) | Nonblocking Scatter Vector. |
| Isend(buf, dest[, tag]) | Nonblocking send. |
| Isendrecv(sendbuf, dest[, sendtag, recvbuf, ...]) | Nonblocking send and receive. |
| Isendrecv_replace(buf, dest[, sendtag, ...]) | Send and receive a message. |
| Ishrink() | Nonblocking shrink a communicator to remove all failed processes. |
| Issend(buf, dest[, tag]) | Nonblocking send in synchronous mode. |
| Join(fd) | Interconnect two processes connected by a socket. |
| Mprobe([source, tag, status]) | Blocking test for a matched message. |
| Precv_init(buf, partitions[, source, tag, info]) | Create request for a partitioned recv operation. |
| Probe([source, tag, status]) | Blocking test for a message. |
| Psend_init(buf, partitions, dest[, tag, info]) | Create request for a partitioned send operation. |
| Recv(buf[, source, tag, status]) | Blocking receive. |
| Recv_init(buf[, source, tag]) | Create a persistent request for a receive. |
| Reduce(sendbuf, recvbuf[, op, root]) | Reduce to Root. |
| Reduce_init(sendbuf, recvbuf[, op, root, info]) | Persistent Reduce to Root. |
| Reduce_scatter(sendbuf, recvbuf[, ...]) | Reduce-Scatter (vector version). |
| Reduce_scatter_block(sendbuf, recvbuf[, op]) | Reduce-Scatter Block (regular, non-vector version). |
| Reduce_scatter_block_init(sendbuf, recvbuf) | Persistent Reduce-Scatter Block (regular, non-vector version). |
| Reduce_scatter_init(sendbuf, recvbuf[, ...]) | Persistent Reduce-Scatter (vector version). |
| Revoke() | Revoke a communicator. |
| Rsend(buf, dest[, tag]) | Blocking send in ready mode. |
| Rsend_init(buf, dest[, tag]) | Persistent request for a send in ready mode. |
| Scatter(sendbuf, recvbuf[, root]) | Scatter data from one process to all other processes. |
| Scatter_init(sendbuf, recvbuf[, root, info]) | Persistent Scatter. |
| Scatterv(sendbuf, recvbuf[, root]) | Scatter Vector. |
| Scatterv_init(sendbuf, recvbuf[, root, info]) | Persistent Scatter Vector. |
| Send(buf, dest[, tag]) | Blocking send. |
| Send_init(buf, dest[, tag]) | Create a persistent request for a standard send. |
| Sendrecv(sendbuf, dest[, sendtag, recvbuf, ...]) | Send and receive a message. |
| Sendrecv_replace(buf, dest[, sendtag, ...]) | Send and receive a message. |
| Set_attr(keyval, attrval) | Store attribute value associated with a key. |
| Set_errhandler(errhandler) | Set the error handler for a communicator. |
| Set_info(info) | Set new values for the hints associated with a communicator. |
| Set_name(name) | Set the print name for this communicator. |
| Shrink() | Shrink a communicator to remove all failed processes. |
| Split([color, key]) | Split communicator by color and key. |
| Split_type(split_type[, key, info]) | Split communicator by split type. |
| Ssend(buf, dest[, tag]) | Blocking send in synchronous mode. |
| Ssend_init(buf, dest[, tag]) | Persistent request for a send in synchronous mode. |
| allgather(sendobj) | Gather to All. |
| allreduce(sendobj[, op]) | Reduce to All. |
| alltoall(sendobj) | All to All Scatter/Gather. |
| barrier() | Barrier synchronization. |
| bcast(obj[, root]) | Broadcast. |
| bsend(obj, dest[, tag]) | Send in buffered mode. |
| f2py(arg) | |
| free() | Call Free if not null or predefined. |
| fromhandle(handle) | Create object from MPI handle. |
| gather(sendobj[, root]) | Gather. |
| ibsend(obj, dest[, tag]) | Nonblocking send in buffered mode. |
| improbe([source, tag, status]) | Nonblocking test for a matched message. |
| iprobe([source, tag, status]) | Nonblocking test for a message. |
| irecv([buf, source, tag]) | Nonblocking receive. |
| isend(obj, dest[, tag]) | Nonblocking send. |
| issend(obj, dest[, tag]) | Nonblocking send in synchronous mode. |
| mprobe([source, tag, status]) | Blocking test for a matched message. |
| probe([source, tag, status]) | Blocking test for a message. |
| py2f() | |
| recv([buf, source, tag, status]) | Receive. |
| reduce(sendobj[, op, root]) | Reduce to Root. |
| scatter(sendobj[, root]) | Scatter. |
| send(obj, dest[, tag]) | Send in standard mode. |
| sendrecv(sendobj, dest[, sendtag, recvbuf, ...]) | Send and Receive. |
| ssend(obj, dest[, tag]) | Send in synchronous mode. |
Attributes Summary
| group | Group. |
| handle | MPI handle. |
| info | Info hints. |
| is_inter | Is intercommunicator. |
| is_intra | Is intracommunicator. |
| is_topo | Is a topology. |
| name | Print name. |
| rank | Rank of this process. |
| size | Number of processes. |
| topology | Topology type. |
Methods Documentation
WARNING:
Gather data from all processes and broadcast the combined data to all other processes.
Gather data from all processes and send it to all other processes providing different amounts of data and displacements.
Send data to all processes and recv data from all processes.
Send data to all processes and recv data from all processes providing different amounts of data and displacements.
Send/recv data to/from all processes allowing the specification of different counts, displacements, and datatypes for each dest/source.
Gather data to one process from all other processes providing different amounts of data and displacements.
NOTE:
CAUTION:
NOTE:
NOTE:
Scatter data from one process to all other processes providing different amounts of data and displacements.
NOTE:
NOTE:
CAUTION:
NOTE:
CAUTION:
Attributes Documentation
Datatype object.
Methods Summary
| Commit() | Commit the datatype. |
| Create_contiguous(count) | Create a contiguous datatype. |
| Create_darray(size, rank, gsizes, distribs, ...) | Create a datatype for a distributed array on Cartesian process grids. |
| Create_f90_complex(p, r) | Return a bounded complex datatype. |
| Create_f90_integer(r) | Return a bounded integer datatype. |
| Create_f90_real(p, r) | Return a bounded real datatype. |
| Create_hindexed(blocklengths, displacements) | Create an indexed datatype. |
| Create_hindexed_block(blocklength, displacements) | Create an indexed datatype with constant-sized blocks. |
| Create_hvector(count, blocklength, stride) | Create a vector (strided) datatype with stride in bytes. |
| Create_indexed(blocklengths, displacements) | Create an indexed datatype. |
| Create_indexed_block(blocklength, displacements) | Create an indexed datatype with constant-sized blocks. |
| Create_keyval([copy_fn, delete_fn, nopython]) | Create a new attribute key for datatypes. |
| Create_resized(lb, extent) | Create a datatype with a new lower bound and extent. |
| Create_struct(blocklengths, displacements, ...) | Create a general composite (struct) datatype. |
| Create_subarray(sizes, subsizes, starts[, order]) | Create a datatype for a subarray of a multidimensional array. |
| Create_vector(count, blocklength, stride) | Create a vector (strided) datatype. |
| Delete_attr(keyval) | Delete attribute value associated with a key. |
| Dup() | Duplicate a datatype. |
| Free() | Free the datatype. |
| Free_keyval(keyval) | Free an attribute key for datatypes. |
| Get_attr(keyval) | Retrieve attribute value by key. |
| Get_contents() | Return the input arguments used to create a datatype. |
| Get_envelope() | Return the number of input arguments used to create a datatype. |
| Get_extent() | Return lower bound and extent of datatype. |
| Get_name() | Get the print name for this datatype. |
| Get_size() | Return the number of bytes occupied by entries in the datatype. |
| Get_true_extent() | Return the true lower bound and extent of a datatype. |
| Get_value_index(value, index) | Return a predefined pair datatype. |
| Match_size(typeclass, size) | Find a datatype matching a specified size in bytes. |
| Pack(inbuf, outbuf, position, comm) | Pack into contiguous memory according to datatype. |
| Pack_external(datarep, inbuf, outbuf, position) | Pack into contiguous memory according to datatype. |
| Pack_external_size(datarep, count) | Determine the amount of space needed to pack a message. |
| Pack_size(count, comm) | Determine the amount of space needed to pack a message. |
| Set_attr(keyval, attrval) | Store attribute value associated with a key. |
| Set_name(name) | Set the print name for this datatype. |
| Unpack(inbuf, position, outbuf, comm) | Unpack from contiguous memory according to datatype. |
| Unpack_external(datarep, inbuf, position, outbuf) | Unpack from contiguous memory according to datatype. |
| decode() | Convenience method for decoding a datatype. |
| f2py(arg) | |
| free() | Call Free if not null or predefined. |
| fromcode(code) | Get predefined MPI datatype from character code or type string. |
| fromhandle(handle) | Create object from MPI handle. |
| py2f() | |
| tocode() | Get character code or type string from predefined MPI datatype. |
Attributes Summary
| combiner | Combiner. |
| contents | Contents. |
| envelope | Envelope. |
| extent | Extent. |
| handle | MPI handle. |
| is_named | Is a named datatype. |
| is_predefined | Is a predefined datatype. |
| lb | Lower bound. |
| name | Print name. |
| size | Size (in bytes). |
| true_extent | True extent. |
| true_lb | True lower bound. |
| true_ub | True upper bound. |
| typechar | Character code. |
| typestr | Type string. |
| ub | Upper bound. |
Methods Documentation
NOTE:
NOTE:
NOTE:
Uses the portable data representation external32.
Uses the portable data representation external32.
NOTE:
NOTE:
Uses the portable data representation external32.
Attributes Documentation
Distributed graph topology intracommunicator.
Methods Summary
| Get_dist_neighbors() | Return adjacency information for a distributed graph topology. |
| Get_dist_neighbors_count() | Return adjacency information for a distributed graph topology. |
Methods Documentation
Error handler.
Methods Summary
| Free() | Free an error handler. |
| f2py(arg) | |
| free() | Call Free if not null. |
| fromhandle(handle) | Create object from MPI handle. |
| py2f() |
Attributes Summary
| handle | MPI handle. |
Methods Documentation
Attributes Documentation
File I/O context.
Methods Summary
| Call_errhandler(errorcode) | Call the error handler installed on a file. |
| Close() | Close a file. |
| Create_errhandler(errhandler_fn) | Create a new error handler for files. |
| Delete(filename[, info]) | Delete a file. |
| Get_amode() | Return the file access mode. |
| Get_atomicity() | Return the atomicity mode. |
| Get_byte_offset(offset) | Return the absolute byte position in the file. |
| Get_errhandler() | Get the error handler for a file. |
| Get_group() | Access the group of processes that opened the file. |
| Get_info() | Return the current hints for a file. |
| Get_position() | Return the current position of the individual file pointer. |
| Get_position_shared() | Return the current position of the shared file pointer. |
| Get_size() | Return the file size. |
| Get_type_extent(datatype) | Return the extent of datatype in the file. |
| Get_view() | Return the file view. |
| Iread(buf) | Nonblocking read using individual file pointer. |
| Iread_all(buf) | Nonblocking collective read using individual file pointer. |
| Iread_at(offset, buf) | Nonblocking read using explicit offset. |
| Iread_at_all(offset, buf) | Nonblocking collective read using explicit offset. |
| Iread_shared(buf) | Nonblocking read using shared file pointer. |
| Iwrite(buf) | Nonblocking write using individual file pointer. |
| Iwrite_all(buf) | Nonblocking collective write using individual file pointer. |
| Iwrite_at(offset, buf) | Nonblocking write using explicit offset. |
| Iwrite_at_all(offset, buf) | Nonblocking collective write using explicit offset. |
| Iwrite_shared(buf) | Nonblocking write using shared file pointer. |
| Open(comm, filename[, amode, info]) | Open a file. |
| Preallocate(size) | Preallocate storage space for a file. |
| Read(buf[, status]) | Read using individual file pointer. |
| Read_all(buf[, status]) | Collective read using individual file pointer. |
| Read_all_begin(buf) | Start a split collective read using individual file pointer. |
| Read_all_end(buf[, status]) | Complete a split collective read using individual file pointer. |
| Read_at(offset, buf[, status]) | Read using explicit offset. |
| Read_at_all(offset, buf[, status]) | Collective read using explicit offset. |
| Read_at_all_begin(offset, buf) | Start a split collective read using explicit offset. |
| Read_at_all_end(buf[, status]) | Complete a split collective read using explicit offset. |
| Read_ordered(buf[, status]) | Collective read using shared file pointer. |
| Read_ordered_begin(buf) | Start a split collective read using shared file pointer. |
| Read_ordered_end(buf[, status]) | Complete a split collective read using shared file pointer. |
| Read_shared(buf[, status]) | Read using shared file pointer. |
| Seek(offset[, whence]) | Update the individual file pointer. |
| Seek_shared(offset[, whence]) | Update the shared file pointer. |
| Set_atomicity(flag) | Set the atomicity mode. |
| Set_errhandler(errhandler) | Set the error handler for a file. |
| Set_info(info) | Set new values for the hints associated with a file. |
| Set_size(size) | Set the file size. |
| Set_view([disp, etype, filetype, datarep, info]) | Set the file view. |
| Sync() | Causes all previous writes to be transferred to the storage device. |
| Write(buf[, status]) | Write using individual file pointer. |
| Write_all(buf[, status]) | Collective write using individual file pointer. |
| Write_all_begin(buf) | Start a split collective write using individual file pointer. |
| Write_all_end(buf[, status]) | Complete a split collective write using individual file pointer. |
| Write_at(offset, buf[, status]) | Write using explicit offset. |
| Write_at_all(offset, buf[, status]) | Collective write using explicit offset. |
| Write_at_all_begin(offset, buf) | Start a split collective write using explicit offset. |
| Write_at_all_end(buf[, status]) | Complete a split collective write using explicit offset. |
| Write_ordered(buf[, status]) | Collective write using shared file pointer. |
| Write_ordered_begin(buf) | Start a split collective write using shared file pointer. |
| Write_ordered_end(buf[, status]) | Complete a split collective write using shared file pointer. |
| Write_shared(buf[, status]) | Write using shared file pointer. |
| f2py(arg) | |
| free() | Call Close if not null. |
| fromhandle(handle) | Create object from MPI handle. |
| py2f() |
Attributes Summary
| amode | Access mode. |
| atomicity | Atomicity mode. |
| group | Group. |
| group_rank | Group rank. |
| group_size | Group size. |
| handle | MPI handle. |
| info | Info hints. |
| size | Size (in bytes). |
Methods Documentation
NOTE:
NOTE:
NOTE:
Attributes Documentation
General graph topology intracommunicator.
Methods Summary
| Get_dims() | Return the number of nodes and edges. |
| Get_neighbors(rank) | Return list of neighbors of a process. |
| Get_neighbors_count(rank) | Return number of neighbors of a process. |
| Get_topo() | Return index and edges. |
Attributes Summary
| dims | Number of nodes and edges. |
| edges | Edges. |
| index | Index. |
| nedges | Number of edges. |
| neighbors | Neighbors. |
| nneighbors | Number of neighbors. |
| nnodes | Number of nodes. |
| topo | Topology information. |
Methods Documentation
Attributes Documentation
Generalized request handler.
Methods Summary
| Complete() | Notify that a user-defined request is complete. |
| Start([query_fn, free_fn, cancel_fn, args, ...]) | Create and return a user-defined request. |
| complete([obj]) | Notify that a user-defined request is complete. |
Methods Documentation
Group of processes.
Methods Summary
| Compare(group) | Compare two groups. |
| Create_from_session_pset(session, pset_name) | Create a new group from session and process set. |
| Difference(group1, group2) | Create a new group from the difference of two existing groups. |
| Dup() | Duplicate a group. |
| Excl(ranks) | Create a new group by excluding listed members. |
| Free() | Free a group. |
| Get_rank() | Return the rank of this process in a group. |
| Get_size() | Return the number of processes in a group. |
| Incl(ranks) | Create a new group by including listed members. |
| Intersection(group1, group2) | Create a new group from the intersection of two existing groups. |
| Range_excl(ranks) | Create a new group by excluding ranges of members. |
| Range_incl(ranks) | Create a new group by including ranges of members. |
| Translate_ranks([ranks, group]) | Translate ranks in a group to those in another group. |
| Union(group1, group2) | Create a new group from the union of two existing groups. |
| f2py(arg) | |
| free() | Call Free if not null or predefined. |
| fromhandle(handle) | Create object from MPI handle. |
| py2f() |
Attributes Summary
| handle | MPI handle. |
| rank | Rank of this process. |
| size | Number of processes. |
Methods Documentation
Attributes Documentation
Info object.
Methods Summary
| Create([items]) | Create a new info object. |
| Create_env([args]) | Create a new environment info object. |
| Delete(key) | Remove a (key, value) pair from info. |
| Dup() | Duplicate an existing info object. |
| Free() | Free an info object. |
| Get(key) | Retrieve the value associated with a key. |
| Get_nkeys() | Return the number of currently defined keys in info. |
| Get_nthkey(n) | Return the n-th defined key in info. |
| Set(key, value) | Store a value associated with a key. |
| clear() | Clear contents. |
| copy() | Copy contents. |
| f2py(arg) | |
| free() | Call Free if not null or predefined. |
| fromhandle(handle) | Create object from MPI handle. |
| get(key[, default]) | Retrieve value by key. |
| items() | Return list of items. |
| keys() | Return list of keys. |
| pop(key, *default) | Pop value by key. |
| popitem() | Pop first item. |
| py2f() | |
| update([items]) | Update contents. |
| values() | Return list of values. |
Attributes Summary
| handle | MPI handle. |
Methods Documentation
Attributes Documentation
Intercommunicator.
Methods Summary
| Create_from_groups(local_group, ...[, ...]) | Create communicator from group. |
| Get_remote_group() | Access the remote group associated with the inter-communicator. |
| Get_remote_size() | Intercommunicator remote size. |
| Merge([high]) | Merge intercommunicator into an intracommunicator. |
Attributes Summary
| remote_group | Remote group. |
| remote_size | Number of remote processes. |
Methods Documentation
Attributes Documentation
Intracommunicator.
Methods Summary
| Accept(port_name[, info, root]) | Accept a request to form a new intercommunicator. |
| Cart_map(dims[, periods]) | Determine optimal process placement on a Cartesian topology. |
| Connect(port_name[, info, root]) | Make a request to form a new intercommunicator. |
| Create_cart(dims[, periods, reorder]) | Create cartesian communicator. |
| Create_dist_graph(sources, degrees, destinations) | Create distributed graph communicator. |
| Create_dist_graph_adjacent(sources, destinations) | Create distributed graph communicator. |
| Create_from_group(group[, stringtag, info, ...]) | Create communicator from group. |
| Create_graph(index, edges[, reorder]) | Create graph communicator. |
| Create_group(group[, tag]) | Create communicator from group. |
| Create_intercomm(local_leader, peer_comm, ...) | Create intercommunicator. |
| Exscan(sendbuf, recvbuf[, op]) | Exclusive Scan. |
| Exscan_init(sendbuf, recvbuf[, op, info]) | Persistent Exclusive Scan. |
| Graph_map(index, edges) | Determine optimal process placement on a graph topology. |
| Iexscan(sendbuf, recvbuf[, op]) | Inclusive Scan. |
| Iscan(sendbuf, recvbuf[, op]) | Inclusive Scan. |
| Scan(sendbuf, recvbuf[, op]) | Inclusive Scan. |
| Scan_init(sendbuf, recvbuf[, op, info]) | Persistent Inclusive Scan. |
| Spawn(command[, args, maxprocs, info, root, ...]) | Spawn instances of a single MPI application. |
| Spawn_multiple(command[, args, maxprocs, ...]) | Spawn instances of multiple MPI applications. |
| exscan(sendobj[, op]) | Exclusive Scan. |
| scan(sendobj[, op]) | Inclusive Scan. |
Methods Documentation
Matched message.
Methods Summary
| Iprobe(comm[, source, tag, status]) | Nonblocking test for a matched message. |
| Irecv(buf) | Nonblocking receive of matched message. |
| Probe(comm[, source, tag, status]) | Blocking test for a matched message. |
| Recv(buf[, status]) | Blocking receive of matched message. |
| f2py(arg) | |
| free() | Do nothing. |
| fromhandle(handle) | Create object from MPI handle. |
| iprobe(comm[, source, tag, status]) | Nonblocking test for a matched message. |
| irecv() | Nonblocking receive of matched message. |
| probe(comm[, source, tag, status]) | Blocking test for a matched message. |
| py2f() | |
| recv([status]) | Blocking receive of matched message. |
Attributes Summary
| handle | MPI handle. |
Methods Documentation
Attributes Documentation
Reduction operation.
Methods Summary
| Create(function[, commute]) | Create a user-defined reduction operation. |
| Free() | Free a user-defined reduction operation. |
| Is_commutative() | Query reduction operations for their commutativity. |
| Reduce_local(inbuf, inoutbuf) | Apply a reduction operation to local data. |
| f2py(arg) | |
| free() | Call Free if not null or predefined. |
| fromhandle(handle) | Create object from MPI handle. |
| py2f() |
Attributes Summary
| handle | MPI handle. |
| is_commutative | Is a commutative operation. |
| is_predefined | Is a predefined operation. |
Methods Documentation
Attributes Documentation
Pickle/unpickle Python objects.
Methods Summary
| dumps(obj) | Serialize object to pickle data stream. |
| dumps_oob(obj) | Serialize object to pickle data stream and out-of-band buffers. |
| loads(data) | Deserialize object from pickle data stream. |
| loads_oob(data, buffers) | Deserialize object from pickle data stream and out-of-band buffers. |
Attributes Summary
| PROTOCOL | Protocol version. |
| THRESHOLD | Out-of-band threshold. |
Methods Documentation
Attributes Documentation
Persistent request handler.
Methods Summary
| Parrived(partition) | Test partial completion of a partitioned receive operation. |
| Pready(partition) | Mark a given partition as ready. |
| Pready_list(partitions) | Mark a sequence of partitions as ready. |
| Pready_range(partition_low, partition_high) | Mark a range of partitions as ready. |
| Start() | Initiate a communication with a persistent request. |
| Startall(requests) | Start a collection of persistent requests. |
Methods Documentation
Request handler.
Methods Summary
| Cancel() | Cancel a request. |
| Free() | Free a communication request. |
| Get_status([status]) | Non-destructive test for the completion of a request. |
| Get_status_all(requests[, statuses]) | Non-destructive test for the completion of all requests. |
| Get_status_any(requests[, status]) | Non-destructive test for the completion of any requests. |
| Get_status_some(requests[, statuses]) | Non-destructive test for completion of some requests. |
| Test([status]) | Test for the completion of a non-blocking operation. |
| Testall(requests[, statuses]) | Test for completion of all previously initiated requests. |
| Testany(requests[, status]) | Test for completion of any previously initiated request. |
| Testsome(requests[, statuses]) | Test for completion of some previously initiated requests. |
| Wait([status]) | Wait for a non-blocking operation to complete. |
| Waitall(requests[, statuses]) | Wait for all previously initiated requests to complete. |
| Waitany(requests[, status]) | Wait for any previously initiated request to complete. |
| Waitsome(requests[, statuses]) | Wait for some previously initiated requests to complete. |
| cancel() | Cancel a request. |
| f2py(arg) | |
| free() | Call Free if not null. |
| fromhandle(handle) | Create object from MPI handle. |
| get_status([status]) | Non-destructive test for the completion of a request. |
| get_status_all(requests[, statuses]) | Non-destructive test for the completion of all requests. |
| get_status_any(requests[, status]) | Non-destructive test for the completion of any requests. |
| get_status_some(requests[, statuses]) | Non-destructive test for completion of some requests. |
| py2f() | |
| test([status]) | Test for the completion of a non-blocking operation. |
| testall(requests[, statuses]) | Test for completion of all previously initiated requests. |
| testany(requests[, status]) | Test for completion of any previously initiated request. |
| testsome(requests[, statuses]) | Test for completion of some previously initiated requests. |
| wait([status]) | Wait for a non-blocking operation to complete. |
| waitall(requests[, statuses]) | Wait for all previously initiated requests to complete. |
| waitany(requests[, status]) | Wait for any previously initiated request to complete. |
| waitsome(requests[, statuses]) | Wait for some previously initiated requests to complete. |
Attributes Summary
| handle | MPI handle. |
Methods Documentation
Attributes Documentation
Session context.
Methods Summary
| Attach_buffer(buf) | Attach a user-provided buffer for sending in buffered mode. |
| Call_errhandler(errorcode) | Call the error handler installed on a session. |
| Create_errhandler(errhandler_fn) | Create a new error handler for sessions. |
| Create_group(pset_name) | Create a new group from session and process set. |
| Detach_buffer() | Remove an existing attached buffer. |
| Finalize() | Finalize a session. |
| Flush_buffer() | Block until all buffered messages have been transmitted. |
| Get_errhandler() | Get the error handler for a session. |
| Get_info() | Return the current hints for a session. |
| Get_nth_pset(n[, info]) | Name of the n-th process set. |
| Get_num_psets([info]) | Number of available process sets. |
| Get_pset_info(pset_name) | Return the current hints for a session and process set. |
| Iflush_buffer() | Nonblocking flush for buffered messages. |
| Init([info, errhandler]) | Create a new session. |
| Set_errhandler(errhandler) | Set the error handler for a session. |
| f2py(arg) | |
| free() | Call Finalize if not null. |
| fromhandle(handle) | Create object from MPI handle. |
| py2f() |
Attributes Summary
| handle | MPI handle. |
Methods Documentation
Attributes Documentation
Status object.
Methods Summary
| Get_count([datatype]) | Get the number of top level elements. |
| Get_elements(datatype) | Get the number of basic elements in a datatype. |
| Get_error() | Get message error. |
| Get_source() | Get message source. |
| Get_tag() | Get message tag. |
| Is_cancelled() | Test to see if a request was cancelled. |
| Set_cancelled(flag) | Set the cancelled state associated with a status. |
| Set_elements(datatype, count) | Set the number of elements in a status. |
| Set_error(error) | Set message error. |
| Set_source(source) | Set message source. |
| Set_tag(tag) | Set message tag. |
| f2py(arg) | |
| py2f() |
Attributes Summary
| cancelled | Cancelled state. |
| count | Byte count. |
| error | Message error. |
| source | Message source. |
| tag | Message tag. |
Methods Documentation
NOTE:
NOTE:
Attributes Documentation
Topology intracommunicator.
Methods Summary
| Ineighbor_allgather(sendbuf, recvbuf) | Nonblocking Neighbor Gather to All. |
| Ineighbor_allgatherv(sendbuf, recvbuf) | Nonblocking Neighbor Gather to All Vector. |
| Ineighbor_alltoall(sendbuf, recvbuf) | Nonblocking Neighbor All to All. |
| Ineighbor_alltoallv(sendbuf, recvbuf) | Nonblocking Neighbor All to All Vector. |
| Ineighbor_alltoallw(sendbuf, recvbuf) | Nonblocking Neighbor All to All General. |
| Neighbor_allgather(sendbuf, recvbuf) | Neighbor Gather to All. |
| Neighbor_allgather_init(sendbuf, recvbuf[, info]) | Persistent Neighbor Gather to All. |
| Neighbor_allgatherv(sendbuf, recvbuf) | Neighbor Gather to All Vector. |
| Neighbor_allgatherv_init(sendbuf, recvbuf[, ...]) | Persistent Neighbor Gather to All Vector. |
| Neighbor_alltoall(sendbuf, recvbuf) | Neighbor All to All. |
| Neighbor_alltoall_init(sendbuf, recvbuf[, info]) | Persistent Neighbor All to All. |
| Neighbor_alltoallv(sendbuf, recvbuf) | Neighbor All to All Vector. |
| Neighbor_alltoallv_init(sendbuf, recvbuf[, info]) | Persistent Neighbor All to All Vector. |
| Neighbor_alltoallw(sendbuf, recvbuf) | Neighbor All to All General. |
| Neighbor_alltoallw_init(sendbuf, recvbuf[, info]) | Persistent Neighbor All to All General. |
| neighbor_allgather(sendobj) | Neighbor Gather to All. |
| neighbor_alltoall(sendobj) | Neighbor All to All. |
Attributes Summary
| degrees | Number of incoming and outgoing neighbors. |
| indegree | Number of incoming neighbors. |
| inedges | Incoming neighbors. |
| inoutedges | Incoming and outgoing neighbors. |
| outdegree | Number of outgoing neighbors. |
| outedges | Outgoing neighbors. |
Methods Documentation
Attributes Documentation
Remote memory access context.
Methods Summary
| Accumulate(origin, target_rank[, target, op]) | Accumulate data into the target process. |
| Allocate(size[, disp_unit, info, comm]) | Create an window object for one-sided communication. |
| Allocate_shared(size[, disp_unit, info, comm]) | Create an window object for one-sided communication. |
| Attach(memory) | Attach a local memory region. |
| Call_errhandler(errorcode) | Call the error handler installed on a window. |
| Compare_and_swap(origin, compare, result, ...) | Perform one-sided atomic compare-and-swap. |
| Complete() | Complete an RMA operation begun after an Start. |
| Create(memory[, disp_unit, info, comm]) | Create an window object for one-sided communication. |
| Create_dynamic([info, comm]) | Create an window object for one-sided communication. |
| Create_errhandler(errhandler_fn) | Create a new error handler for windows. |
| Create_keyval([copy_fn, delete_fn, nopython]) | Create a new attribute key for windows. |
| Delete_attr(keyval) | Delete attribute value associated with a key. |
| Detach(memory) | Detach a local memory region. |
| Fence([assertion]) | Perform an MPI fence synchronization on a window. |
| Fetch_and_op(origin, result, target_rank[, ...]) | Perform one-sided read-modify-write. |
| Flush(rank) | Complete all outstanding RMA operations at a target. |
| Flush_all() | Complete all outstanding RMA operations at all targets. |
| Flush_local(rank) | Complete locally all outstanding RMA operations at a target. |
| Flush_local_all() | Complete locally all outstanding RMA operations at all targets. |
| Free() | Free a window. |
| Free_keyval(keyval) | Free an attribute key for windows. |
| Get(origin, target_rank[, target]) | Get data from a memory window on a remote process. |
| Get_accumulate(origin, result, target_rank) | Fetch-and-accumulate data into the target process. |
| Get_attr(keyval) | Retrieve attribute value by key. |
| Get_errhandler() | Get the error handler for a window. |
| Get_group() | Access the group of processes that created the window. |
| Get_info() | Return the current hints for a window. |
| Get_name() | Get the print name for this window. |
| Lock(rank[, lock_type, assertion]) | Begin an RMA access epoch at the target process. |
| Lock_all([assertion]) | Begin an RMA access epoch at all processes. |
| Post(group[, assertion]) | Start an RMA exposure epoch. |
| Put(origin, target_rank[, target]) | Put data into a memory window on a remote process. |
| Raccumulate(origin, target_rank[, target, op]) | Fetch-and-accumulate data into the target process. |
| Rget(origin, target_rank[, target]) | Get data from a memory window on a remote process. |
| Rget_accumulate(origin, result, target_rank) | Accumulate data into the target process using remote memory access. |
| Rput(origin, target_rank[, target]) | Put data into a memory window on a remote process. |
| Set_attr(keyval, attrval) | Store attribute value associated with a key. |
| Set_errhandler(errhandler) | Set the error handler for a window. |
| Set_info(info) | Set new values for the hints associated with a window. |
| Set_name(name) | Set the print name for this window. |
| Shared_query(rank) | Query the process-local address for remote memory segments. |
| Start(group[, assertion]) | Start an RMA access epoch for MPI. |
| Sync() | Synchronize public and private copies of the window. |
| Test() | Test whether an RMA exposure epoch has completed. |
| Unlock(rank) | Complete an RMA access epoch at the target process. |
| Unlock_all() | Complete an RMA access epoch at all processes. |
| Wait() | Complete an RMA exposure epoch begun with Post. |
| f2py(arg) | |
| free() | Call Free if not null. |
| fromhandle(handle) | Create object from MPI handle. |
| py2f() | |
| tomemory() | Return window memory buffer. |
Attributes Summary
| attrs | Attributes. |
| flavor | Create flavor. |
| group | Group. |
| group_rank | Group rank. |
| group_size | Group size. |
| handle | MPI handle. |
| info | Info hints. |
| model | Memory model. |
| name | Print name. |
Methods Documentation
Attributes Documentation
Buffer.
Methods Summary
| allocate(nbytes[, clear]) | Buffer allocation. |
| cast(format[, shape]) | Cast to a memoryview with new format or shape. |
| fromaddress(address, nbytes[, readonly]) | Buffer from address and size in bytes. |
| frombuffer(obj[, readonly]) | Buffer from buffer-like object. |
| release() | Release the underlying buffer exposed by the buffer object. |
| tobytes([order]) | Return the data in the buffer as a byte string. |
| toreadonly() | Return a readonly version of the buffer object. |
Attributes Summary
| address | Buffer address. |
| format | Format of each element. |
| itemsize | Size (in bytes) of each element. |
| nbytes | Buffer size (in bytes). |
| obj | Object exposing buffer. |
| readonly | Buffer is read-only. |
Methods Documentation
Attributes Documentation
Exceptions
| Exception | Exception class. |
Exception class.
Methods Summary
| Get_error_class() | Error class. |
| Get_error_code() | Error code. |
| Get_error_string() | Error string. |
Attributes Summary
| error_class | Error class. |
| error_code | Error code. |
| error_string | Error string. |
Methods Documentation
Attributes Documentation
Functions
| Add_error_class() | Add an error class to the known error classes. |
| Add_error_code(errorclass) | Add an error code to an error class. |
| Add_error_string(errorcode, string) | Associate an error string with an error class or error code. |
| Aint_add(base, disp) | Return the sum of base address and displacement. |
| Aint_diff(addr1, addr2) | Return the difference between absolute addresses. |
| Alloc_mem(size[, info]) | Allocate memory for message passing and remote memory access. |
| Attach_buffer(buf) | Attach a user-provided buffer for sending in buffered mode. |
| Close_port(port_name) | Close a port. |
| Compute_dims(nnodes, dims) | Return a balanced distribution of processes per coordinate direction. |
| Detach_buffer() | Remove an existing attached buffer. |
| Finalize() | Terminate the MPI execution environment. |
| Flush_buffer() | Block until all buffered messages have been transmitted. |
| Free_mem(mem) | Free memory allocated with Alloc_mem. |
| Get_address(location) | Get the address of a location in memory. |
| Get_error_class(errorcode) | Convert an error code into an error class. |
| Get_error_string(errorcode) | Return the error string for a given error class or error code. |
| Get_hw_resource_info() | Obtain information about the hardware platform of the calling processor. |
| Get_library_version() | Obtain the version string of the MPI library. |
| Get_processor_name() | Obtain the name of the calling processor. |
| Get_version() | Obtain the version number of the MPI standard. |
| Iflush_buffer() | Nonblocking flush for buffered messages. |
| Init() | Initialize the MPI execution environment. |
| Init_thread([required]) | Initialize the MPI execution environment. |
| Is_finalized() | Indicate whether Finalize has completed. |
| Is_initialized() | Indicate whether Init has been called. |
| Is_thread_main() | Indicate whether this thread called Init or Init_thread. |
| Lookup_name(service_name[, info]) | Lookup a port name given a service name. |
| Open_port([info]) | Return an address used to connect group of processes. |
| Pcontrol(level) | Control profiling. |
| Publish_name(service_name, port_name[, info]) | Publish a service name. |
| Query_thread() | Return the level of thread support provided by the MPI library. |
| Register_datarep(datarep, read_fn, write_fn, ...) | Register user-defined data representations. |
| Remove_error_class(errorclass) | Remove an error class from the known error classes. |
| Remove_error_code(errorcode) | Remove an error code from the known error codes. |
| Remove_error_string(errorcode) | Remove error string association from error class or error code. |
| Unpublish_name(service_name, port_name[, info]) | Unpublish a service name. |
| Wtick() | Return the resolution of Wtime. |
| Wtime() | Return an elapsed time on the calling processor. |
| get_vendor() | Information about the underlying MPI implementation. |
Attributes
| UNDEFINED | Constant UNDEFINED of type int |
| ANY_SOURCE | Constant ANY_SOURCE of type int |
| ANY_TAG | Constant ANY_TAG of type int |
| PROC_NULL | Constant PROC_NULL of type int |
| ROOT | Constant ROOT of type int |
| BOTTOM | Constant BOTTOM of type BottomType |
| IN_PLACE | Constant IN_PLACE of type InPlaceType |
| KEYVAL_INVALID | Constant KEYVAL_INVALID of type int |
| TAG_UB | Constant TAG_UB of type int |
| IO | Constant IO of type int |
| WTIME_IS_GLOBAL | Constant WTIME_IS_GLOBAL of type int |
| UNIVERSE_SIZE | Constant UNIVERSE_SIZE of type int |
| APPNUM | Constant APPNUM of type int |
| LASTUSEDCODE | Constant LASTUSEDCODE of type int |
| WIN_BASE | Constant WIN_BASE of type int |
| WIN_SIZE | Constant WIN_SIZE of type int |
| WIN_DISP_UNIT | Constant WIN_DISP_UNIT of type int |
| WIN_CREATE_FLAVOR | Constant WIN_CREATE_FLAVOR of type int |
| WIN_FLAVOR | Constant WIN_FLAVOR of type int |
| WIN_MODEL | Constant WIN_MODEL of type int |
| SUCCESS | Constant SUCCESS of type int |
| ERR_LASTCODE | Constant ERR_LASTCODE of type int |
| ERR_TYPE | Constant ERR_TYPE of type int |
| ERR_REQUEST | Constant ERR_REQUEST of type int |
| ERR_OP | Constant ERR_OP of type int |
| ERR_GROUP | Constant ERR_GROUP of type int |
| ERR_INFO | Constant ERR_INFO of type int |
| ERR_ERRHANDLER | Constant ERR_ERRHANDLER of type int |
| ERR_SESSION | Constant ERR_SESSION of type int |
| ERR_COMM | Constant ERR_COMM of type int |
| ERR_WIN | Constant ERR_WIN of type int |
| ERR_FILE | Constant ERR_FILE of type int |
| ERR_BUFFER | Constant ERR_BUFFER of type int |
| ERR_COUNT | Constant ERR_COUNT of type int |
| ERR_TAG | Constant ERR_TAG of type int |
| ERR_RANK | Constant ERR_RANK of type int |
| ERR_ROOT | Constant ERR_ROOT of type int |
| ERR_TRUNCATE | Constant ERR_TRUNCATE of type int |
| ERR_IN_STATUS | Constant ERR_IN_STATUS of type int |
| ERR_PENDING | Constant ERR_PENDING of type int |
| ERR_TOPOLOGY | Constant ERR_TOPOLOGY of type int |
| ERR_DIMS | Constant ERR_DIMS of type int |
| ERR_ARG | Constant ERR_ARG of type int |
| ERR_OTHER | Constant ERR_OTHER of type int |
| ERR_UNKNOWN | Constant ERR_UNKNOWN of type int |
| ERR_INTERN | Constant ERR_INTERN of type int |
| ERR_KEYVAL | Constant ERR_KEYVAL of type int |
| ERR_NO_MEM | Constant ERR_NO_MEM of type int |
| ERR_INFO_KEY | Constant ERR_INFO_KEY of type int |
| ERR_INFO_VALUE | Constant ERR_INFO_VALUE of type int |
| ERR_INFO_NOKEY | Constant ERR_INFO_NOKEY of type int |
| ERR_SPAWN | Constant ERR_SPAWN of type int |
| ERR_PORT | Constant ERR_PORT of type int |
| ERR_SERVICE | Constant ERR_SERVICE of type int |
| ERR_NAME | Constant ERR_NAME of type int |
| ERR_PROC_ABORTED | Constant ERR_PROC_ABORTED of type int |
| ERR_BASE | Constant ERR_BASE of type int |
| ERR_SIZE | Constant ERR_SIZE of type int |
| ERR_DISP | Constant ERR_DISP of type int |
| ERR_ASSERT | Constant ERR_ASSERT of type int |
| ERR_LOCKTYPE | Constant ERR_LOCKTYPE of type int |
| ERR_RMA_CONFLICT | Constant ERR_RMA_CONFLICT of type int |
| ERR_RMA_SYNC | Constant ERR_RMA_SYNC of type int |
| ERR_RMA_RANGE | Constant ERR_RMA_RANGE of type int |
| ERR_RMA_ATTACH | Constant ERR_RMA_ATTACH of type int |
| ERR_RMA_SHARED | Constant ERR_RMA_SHARED of type int |
| ERR_RMA_FLAVOR | Constant ERR_RMA_FLAVOR of type int |
| ERR_BAD_FILE | Constant ERR_BAD_FILE of type int |
| ERR_NO_SUCH_FILE | Constant ERR_NO_SUCH_FILE of type int |
| ERR_FILE_EXISTS | Constant ERR_FILE_EXISTS of type int |
| ERR_FILE_IN_USE | Constant ERR_FILE_IN_USE of type int |
| ERR_AMODE | Constant ERR_AMODE of type int |
| ERR_ACCESS | Constant ERR_ACCESS of type int |
| ERR_READ_ONLY | Constant ERR_READ_ONLY of type int |
| ERR_NO_SPACE | Constant ERR_NO_SPACE of type int |
| ERR_QUOTA | Constant ERR_QUOTA of type int |
| ERR_NOT_SAME | Constant ERR_NOT_SAME of type int |
| ERR_IO | Constant ERR_IO of type int |
| ERR_UNSUPPORTED_OPERATION | Constant ERR_UNSUPPORTED_OPERATION of type int |
| ERR_UNSUPPORTED_DATAREP | Constant ERR_UNSUPPORTED_DATAREP of type int |
| ERR_CONVERSION | Constant ERR_CONVERSION of type int |
| ERR_DUP_DATAREP | Constant ERR_DUP_DATAREP of type int |
| ERR_VALUE_TOO_LARGE | Constant ERR_VALUE_TOO_LARGE of type int |
| ERR_REVOKED | Constant ERR_REVOKED of type int |
| ERR_PROC_FAILED | Constant ERR_PROC_FAILED of type int |
| ERR_PROC_FAILED_PENDING | Constant ERR_PROC_FAILED_PENDING of type int |
| ORDER_C | Constant ORDER_C of type int |
| ORDER_FORTRAN | Constant ORDER_FORTRAN of type int |
| ORDER_F | Constant ORDER_F of type int |
| TYPECLASS_INTEGER | Constant TYPECLASS_INTEGER of type int |
| TYPECLASS_REAL | Constant TYPECLASS_REAL of type int |
| TYPECLASS_COMPLEX | Constant TYPECLASS_COMPLEX of type int |
| DISTRIBUTE_NONE | Constant DISTRIBUTE_NONE of type int |
| DISTRIBUTE_BLOCK | Constant DISTRIBUTE_BLOCK of type int |
| DISTRIBUTE_CYCLIC | Constant DISTRIBUTE_CYCLIC of type int |
| DISTRIBUTE_DFLT_DARG | Constant DISTRIBUTE_DFLT_DARG of type int |
| COMBINER_NAMED | Constant COMBINER_NAMED of type int |
| COMBINER_DUP | Constant COMBINER_DUP of type int |
| COMBINER_CONTIGUOUS | Constant COMBINER_CONTIGUOUS of type int |
| COMBINER_VECTOR | Constant COMBINER_VECTOR of type int |
| COMBINER_HVECTOR | Constant COMBINER_HVECTOR of type int |
| COMBINER_INDEXED | Constant COMBINER_INDEXED of type int |
| COMBINER_HINDEXED | Constant COMBINER_HINDEXED of type int |
| COMBINER_INDEXED_BLOCK | Constant COMBINER_INDEXED_BLOCK of type int |
| COMBINER_HINDEXED_BLOCK | Constant COMBINER_HINDEXED_BLOCK of type int |
| COMBINER_STRUCT | Constant COMBINER_STRUCT of type int |
| COMBINER_SUBARRAY | Constant COMBINER_SUBARRAY of type int |
| COMBINER_DARRAY | Constant COMBINER_DARRAY of type int |
| COMBINER_RESIZED | Constant COMBINER_RESIZED of type int |
| COMBINER_VALUE_INDEX | Constant COMBINER_VALUE_INDEX of type int |
| COMBINER_F90_INTEGER | Constant COMBINER_F90_INTEGER of type int |
| COMBINER_F90_REAL | Constant COMBINER_F90_REAL of type int |
| COMBINER_F90_COMPLEX | Constant COMBINER_F90_COMPLEX of type int |
| F_SOURCE | Constant F_SOURCE of type int |
| F_TAG | Constant F_TAG of type int |
| F_ERROR | Constant F_ERROR of type int |
| F_STATUS_SIZE | Constant F_STATUS_SIZE of type int |
| IDENT | Constant IDENT of type int |
| CONGRUENT | Constant CONGRUENT of type int |
| SIMILAR | Constant SIMILAR of type int |
| UNEQUAL | Constant UNEQUAL of type int |
| CART | Constant CART of type int |
| GRAPH | Constant GRAPH of type int |
| DIST_GRAPH | Constant DIST_GRAPH of type int |
| UNWEIGHTED | Constant UNWEIGHTED of type int |
| WEIGHTS_EMPTY | Constant WEIGHTS_EMPTY of type int |
| COMM_TYPE_SHARED | Constant COMM_TYPE_SHARED of type int |
| COMM_TYPE_HW_GUIDED | Constant COMM_TYPE_HW_GUIDED of type int |
| COMM_TYPE_HW_UNGUIDED | Constant COMM_TYPE_HW_UNGUIDED of type int |
| COMM_TYPE_RESOURCE_GUIDED | Constant COMM_TYPE_RESOURCE_GUIDED of type int |
| BSEND_OVERHEAD | Constant BSEND_OVERHEAD of type int |
| BUFFER_AUTOMATIC | Constant BUFFER_AUTOMATIC of type BufferAutomaticType |
| WIN_FLAVOR_CREATE | Constant WIN_FLAVOR_CREATE of type int |
| WIN_FLAVOR_ALLOCATE | Constant WIN_FLAVOR_ALLOCATE of type int |
| WIN_FLAVOR_DYNAMIC | Constant WIN_FLAVOR_DYNAMIC of type int |
| WIN_FLAVOR_SHARED | Constant WIN_FLAVOR_SHARED of type int |
| WIN_SEPARATE | Constant WIN_SEPARATE of type int |
| WIN_UNIFIED | Constant WIN_UNIFIED of type int |
| MODE_NOCHECK | Constant MODE_NOCHECK of type int |
| MODE_NOSTORE | Constant MODE_NOSTORE of type int |
| MODE_NOPUT | Constant MODE_NOPUT of type int |
| MODE_NOPRECEDE | Constant MODE_NOPRECEDE of type int |
| MODE_NOSUCCEED | Constant MODE_NOSUCCEED of type int |
| LOCK_EXCLUSIVE | Constant LOCK_EXCLUSIVE of type int |
| LOCK_SHARED | Constant LOCK_SHARED of type int |
| MODE_RDONLY | Constant MODE_RDONLY of type int |
| MODE_WRONLY | Constant MODE_WRONLY of type int |
| MODE_RDWR | Constant MODE_RDWR of type int |
| MODE_CREATE | Constant MODE_CREATE of type int |
| MODE_EXCL | Constant MODE_EXCL of type int |
| MODE_DELETE_ON_CLOSE | Constant MODE_DELETE_ON_CLOSE of type int |
| MODE_UNIQUE_OPEN | Constant MODE_UNIQUE_OPEN of type int |
| MODE_SEQUENTIAL | Constant MODE_SEQUENTIAL of type int |
| MODE_APPEND | Constant MODE_APPEND of type int |
| SEEK_SET | Constant SEEK_SET of type int |
| SEEK_CUR | Constant SEEK_CUR of type int |
| SEEK_END | Constant SEEK_END of type int |
| DISPLACEMENT_CURRENT | Constant DISPLACEMENT_CURRENT of type int |
| DISP_CUR | Constant DISP_CUR of type int |
| THREAD_SINGLE | Constant THREAD_SINGLE of type int |
| THREAD_FUNNELED | Constant THREAD_FUNNELED of type int |
| THREAD_SERIALIZED | Constant THREAD_SERIALIZED of type int |
| THREAD_MULTIPLE | Constant THREAD_MULTIPLE of type int |
| VERSION | Constant VERSION of type int |
| SUBVERSION | Constant SUBVERSION of type int |
| MAX_PROCESSOR_NAME | Constant MAX_PROCESSOR_NAME of type int |
| MAX_ERROR_STRING | Constant MAX_ERROR_STRING of type int |
| MAX_PORT_NAME | Constant MAX_PORT_NAME of type int |
| MAX_INFO_KEY | Constant MAX_INFO_KEY of type int |
| MAX_INFO_VAL | Constant MAX_INFO_VAL of type int |
| MAX_OBJECT_NAME | Constant MAX_OBJECT_NAME of type int |
| MAX_DATAREP_STRING | Constant MAX_DATAREP_STRING of type int |
| MAX_LIBRARY_VERSION_STRING | Constant MAX_LIBRARY_VERSION_STRING of type int |
| MAX_PSET_NAME_LEN | Constant MAX_PSET_NAME_LEN of type int |
| MAX_STRINGTAG_LEN | Constant MAX_STRINGTAG_LEN of type int |
| DATATYPE_NULL | Object DATATYPE_NULL of type Datatype |
| PACKED | Object PACKED of type Datatype |
| BYTE | Object BYTE of type Datatype |
| AINT | Object AINT of type Datatype |
| OFFSET | Object OFFSET of type Datatype |
| COUNT | Object COUNT of type Datatype |
| CHAR | Object CHAR of type Datatype |
| WCHAR | Object WCHAR of type Datatype |
| SIGNED_CHAR | Object SIGNED_CHAR of type Datatype |
| SHORT | Object SHORT of type Datatype |
| INT | Object INT of type Datatype |
| LONG | Object LONG of type Datatype |
| LONG_LONG | Object LONG_LONG of type Datatype |
| UNSIGNED_CHAR | Object UNSIGNED_CHAR of type Datatype |
| UNSIGNED_SHORT | Object UNSIGNED_SHORT of type Datatype |
| UNSIGNED | Object UNSIGNED of type Datatype |
| UNSIGNED_LONG | Object UNSIGNED_LONG of type Datatype |
| UNSIGNED_LONG_LONG | Object UNSIGNED_LONG_LONG of type Datatype |
| FLOAT | Object FLOAT of type Datatype |
| DOUBLE | Object DOUBLE of type Datatype |
| LONG_DOUBLE | Object LONG_DOUBLE of type Datatype |
| C_BOOL | Object C_BOOL of type Datatype |
| INT8_T | Object INT8_T of type Datatype |
| INT16_T | Object INT16_T of type Datatype |
| INT32_T | Object INT32_T of type Datatype |
| INT64_T | Object INT64_T of type Datatype |
| UINT8_T | Object UINT8_T of type Datatype |
| UINT16_T | Object UINT16_T of type Datatype |
| UINT32_T | Object UINT32_T of type Datatype |
| UINT64_T | Object UINT64_T of type Datatype |
| C_COMPLEX | Object C_COMPLEX of type Datatype |
| C_FLOAT_COMPLEX | Object C_FLOAT_COMPLEX of type Datatype |
| C_DOUBLE_COMPLEX | Object C_DOUBLE_COMPLEX of type Datatype |
| C_LONG_DOUBLE_COMPLEX | Object C_LONG_DOUBLE_COMPLEX of type Datatype |
| CXX_BOOL | Object CXX_BOOL of type Datatype |
| CXX_FLOAT_COMPLEX | Object CXX_FLOAT_COMPLEX of type Datatype |
| CXX_DOUBLE_COMPLEX | Object CXX_DOUBLE_COMPLEX of type Datatype |
| CXX_LONG_DOUBLE_COMPLEX | Object CXX_LONG_DOUBLE_COMPLEX of type Datatype |
| SHORT_INT | Object SHORT_INT of type Datatype |
| INT_INT | Object INT_INT of type Datatype |
| TWOINT | Object TWOINT of type Datatype |
| LONG_INT | Object LONG_INT of type Datatype |
| FLOAT_INT | Object FLOAT_INT of type Datatype |
| DOUBLE_INT | Object DOUBLE_INT of type Datatype |
| LONG_DOUBLE_INT | Object LONG_DOUBLE_INT of type Datatype |
| CHARACTER | Object CHARACTER of type Datatype |
| LOGICAL | Object LOGICAL of type Datatype |
| INTEGER | Object INTEGER of type Datatype |
| REAL | Object REAL of type Datatype |
| DOUBLE_PRECISION | Object DOUBLE_PRECISION of type Datatype |
| COMPLEX | Object COMPLEX of type Datatype |
| DOUBLE_COMPLEX | Object DOUBLE_COMPLEX of type Datatype |
| LOGICAL1 | Object LOGICAL1 of type Datatype |
| LOGICAL2 | Object LOGICAL2 of type Datatype |
| LOGICAL4 | Object LOGICAL4 of type Datatype |
| LOGICAL8 | Object LOGICAL8 of type Datatype |
| INTEGER1 | Object INTEGER1 of type Datatype |
| INTEGER2 | Object INTEGER2 of type Datatype |
| INTEGER4 | Object INTEGER4 of type Datatype |
| INTEGER8 | Object INTEGER8 of type Datatype |
| INTEGER16 | Object INTEGER16 of type Datatype |
| REAL2 | Object REAL2 of type Datatype |
| REAL4 | Object REAL4 of type Datatype |
| REAL8 | Object REAL8 of type Datatype |
| REAL16 | Object REAL16 of type Datatype |
| COMPLEX4 | Object COMPLEX4 of type Datatype |
| COMPLEX8 | Object COMPLEX8 of type Datatype |
| COMPLEX16 | Object COMPLEX16 of type Datatype |
| COMPLEX32 | Object COMPLEX32 of type Datatype |
| UNSIGNED_INT | Object UNSIGNED_INT of type Datatype |
| SIGNED_SHORT | Object SIGNED_SHORT of type Datatype |
| SIGNED_INT | Object SIGNED_INT of type Datatype |
| SIGNED_LONG | Object SIGNED_LONG of type Datatype |
| SIGNED_LONG_LONG | Object SIGNED_LONG_LONG of type Datatype |
| BOOL | Object BOOL of type Datatype |
| SINT8_T | Object SINT8_T of type Datatype |
| SINT16_T | Object SINT16_T of type Datatype |
| SINT32_T | Object SINT32_T of type Datatype |
| SINT64_T | Object SINT64_T of type Datatype |
| F_BOOL | Object F_BOOL of type Datatype |
| F_INT | Object F_INT of type Datatype |
| F_FLOAT | Object F_FLOAT of type Datatype |
| F_DOUBLE | Object F_DOUBLE of type Datatype |
| F_COMPLEX | Object F_COMPLEX of type Datatype |
| F_FLOAT_COMPLEX | Object F_FLOAT_COMPLEX of type Datatype |
| F_DOUBLE_COMPLEX | Object F_DOUBLE_COMPLEX of type Datatype |
| REQUEST_NULL | Object REQUEST_NULL of type Request |
| MESSAGE_NULL | Object MESSAGE_NULL of type Message |
| MESSAGE_NO_PROC | Object MESSAGE_NO_PROC of type Message |
| OP_NULL | Object OP_NULL of type Op |
| MAX | Object MAX of type Op |
| MIN | Object MIN of type Op |
| SUM | Object SUM of type Op |
| PROD | Object PROD of type Op |
| LAND | Object LAND of type Op |
| BAND | Object BAND of type Op |
| LOR | Object LOR of type Op |
| BOR | Object BOR of type Op |
| LXOR | Object LXOR of type Op |
| BXOR | Object BXOR of type Op |
| MAXLOC | Object MAXLOC of type Op |
| MINLOC | Object MINLOC of type Op |
| REPLACE | Object REPLACE of type Op |
| NO_OP | Object NO_OP of type Op |
| GROUP_NULL | Object GROUP_NULL of type Group |
| GROUP_EMPTY | Object GROUP_EMPTY of type Group |
| INFO_NULL | Object INFO_NULL of type Info |
| INFO_ENV | Object INFO_ENV of type Info |
| ERRHANDLER_NULL | Object ERRHANDLER_NULL of type Errhandler |
| ERRORS_RETURN | Object ERRORS_RETURN of type Errhandler |
| ERRORS_ABORT | Object ERRORS_ABORT of type Errhandler |
| ERRORS_ARE_FATAL | Object ERRORS_ARE_FATAL of type Errhandler |
| SESSION_NULL | Object SESSION_NULL of type Session |
| COMM_NULL | Object COMM_NULL of type Comm |
| COMM_SELF | Object COMM_SELF of type Intracomm |
| COMM_WORLD | Object COMM_WORLD of type Intracomm |
| WIN_NULL | Object WIN_NULL of type Win |
| FILE_NULL | Object FILE_NULL of type File |
| pickle | Object pickle of type Pickle |
If MPI for Python been significant to a project that leads to an academic publication, please acknowledge that fact by citing the project.
mpi4py supports three different build backends: setuptools (default), scikit-build-core (CMake-based), and meson-python (Meson-based). The build backend can be selected by setting the MPI4PY_BUILD_BACKEND environment variable.
Request a build backend for building mpi4py from sources.
TIP:
When using the default setuptools build backend, mpi4py relies on the legacy Python distutils framework to build C extension modules. The following environment variables affect the build configuration.
The following environment variables are aliases for the ones described above. Having shorter names, they are convenient for occasional use in the command line. Its usage is not recommended in automation scenarios like packaging recipes, deployment scripts, and container image creation.
TIP:
When using the scikit-build-core build backend, mpi4py delegates all of MPI build configuration to CMake’s FindMPI module. Besides the obvious advantage of cross-platform support, this delegation to CMake may be convenient in build environments exposing vendor software stacks via intricate module systems. Note however that mpi4py will not be able to look for MPI routines available beyond the MPI standard version the MPI implementation advertises to support (via the MPI_VERSION and MPI_SUBVERSION macro constants in the mpi.h header file), any missing MPI constant or symbol will prevent a successful build.
TIP:
When using the meson-python build backend, mpi4py delegates build tasks to the Meson build system.
WARNING:
You can install the latest mpi4py release from its source distribution at PyPI using pip:
$ python -m pip install mpi4py
You can also install the in-development version with:
$ python -m pip install git+https://github.com/mpi4py/mpi4py
or:
$ python -m pip install https://github.com/mpi4py/mpi4py/tarball/master
NOTE:
WARNING:
$ python -m pip cache remove mpi4py
or ask pip to disable the cache:
$ python -m pip install --no-cache-dir mpi4py
The conda-forge community provides ready-to-use binary packages from an ever growing collection of software libraries built around the multi-platform conda package manager. Four MPI implementations are available on conda-forge: Open MPI (Linux and macOS), MPICH (Linux and macOS), Intel MPI (Linux and Windows) and Microsoft MPI (Windows). You can install mpi4py and your preferred MPI implementation using the conda package manager:
$ conda install -c conda-forge mpi4py mpich
$ conda install -c conda-forge mpi4py openmpi
$ conda install -c conda-forge mpi4py impi_rt
$ conda install -c conda-forge mpi4py msmpi
MPICH and many of its derivatives are ABI-compatible. You can provide the package specification mpich=X.Y.*=external_* (where X and Y are the major and minor version numbers) to request the conda package manager to use system-provided MPICH (or derivative) libraries. Similarly, you can provide the package specification openmpi=X.Y.*=external_* to use system-provided Open MPI libraries.
The openmpi package on conda-forge has built-in CUDA support, but it is disabled by default. To enable it, follow the instruction outlined during conda install. Additionally, UCX support is also available once the ucx package is installed.
WARNING:
On Fedora Linux systems (as well as RHEL and their derivatives using the EPEL software repository), you can install binary packages with the system package manager:
$ sudo dnf install python3-mpi4py-mpich
$ sudo dnf install python3-mpi4py-openmpi
Please remember to load the correct MPI module for your chosen MPI implementation:
$ module load mpi/mpich-$(arch) $ python -c "from mpi4py import MPI"
$ module load mpi/openmpi-$(arch) $ python -c "from mpi4py import MPI"
On Ubuntu Linux and Debian Linux systems, binary packages are available for installation using the system package manager:
$ sudo apt install python3-mpi4py
Note that on Ubuntu/Debian systems, the mpi4py package uses Open MPI. To use MPICH, install the libmpich-dev and python3-dev packages (and any other required development tools). Afterwards, install mpi4py from sources using pip.
macOS users can install mpi4py using the Homebrew package manager:
$ brew install mpi4py
Note that the Homebrew mpi4py package uses Open MPI. Alternatively, install the mpich package and next install mpi4py from sources using pip.
Windows users can install mpi4py from binary wheels hosted on the Python Package Index (PyPI) using pip:
$ python -m pip install mpi4py
The Windows wheels available on PyPI are specially crafted to work with either the Intel MPI or the Microsoft MPI runtime, therefore requiring a separate installation of any one of these packages.
Intel MPI is under active development and supports recent version of the MPI standard. Intel MPI can be installed with pip (see the impi-rt package on PyPI), being therefore straightforward to get it up and running within a Python environment. Intel MPI can also be installed system-wide as part of the Intel HPC Toolkit for Windows or via standalone online/offline installers.
You need to have the following software properly installed to develop MPI for Python:
Optionally, consider installing the following packages:
TIP:
MPI for Python uses setuptools-based build system that relies on the setup.py file. Some setuptools commands (e.g., build) accept additional options:
If you use a MPI implementation providing a mpicc C compiler wrapper (e.g., MPICH or Open MPI), it will be used for compilation and linking. This is the preferred and easiest way to build MPI for Python.
If mpicc is found in the executable search path (PATH environment variable), simply run the build command:
$ python setup.py build
If mpicc is not in your search path or the compiler wrapper has a different name, you can run the build command specifying its location, either via the --mpicc command option or using the MPICC environment variable:
$ python setup.py build --mpicc=/path/to/mpicc $ env MPICC=/path/to/mpicc python setup.py build
Alternatively, you can provide all the relevant information about your MPI implementation by editing the mpi.cfg file located in the top level source directory. You can use the default section [mpi] or add a new custom section, for example [vendor_mpi] (see the examples provided in the mpi.cfg file as a starting point to write your own section):
[mpi] include_dirs = /usr/local/mpi/include libraries = mpi library_dirs = /usr/local/mpi/lib runtime_library_dirs = /usr/local/mpi/lib [vendor_mpi] include_dirs = /opt/mpi/include ... libraries = mpi ... library_dirs = /opt/mpi/lib ... runtime_library_dirs = /opt/mpi/lib ... ...
and then run the build command specifying you custom configuration section:
$ python setup.py build --mpi=vendor_mpi $ env MPICFG=vendor_mpi python setup.py build
MPI for Python can be installed in editable mode:
$ python -m pip install --editable .
After modifying Cython sources, an in-place rebuild is needed:
$ python setup.py build --inplace
To quickly test the installation:
$ mpiexec -n 5 python -m mpi4py.bench helloworld Hello, World! I am process 0 of 5 on localhost. Hello, World! I am process 1 of 5 on localhost. Hello, World! I am process 2 of 5 on localhost. Hello, World! I am process 3 of 5 on localhost. Hello, World! I am process 4 of 5 on localhost. $ mpiexec -n 5 python -m mpi4py.bench ringtest -l 10 -n 1048576 time for 10 loops = 0.00361614 seconds (5 processes, 1048576 bytes)
If you installed from a git clone or the source distribution, issuing at the command line:
$ mpiexec -n 5 python demo/helloworld.py
will launch a five-process run of the Python interpreter and run the demo script demo/helloworld.py from the source distribution.
You can also run all the unittest scripts:
$ mpiexec -n 5 python test/main.py
or, if you have the pytest unit testing framework installed:
$ mpiexec -n 5 pytest
This section defines Rules of Play for companies and outside developers that engage with the mpi4py project. It covers:
After reading this section, companies and developers will know what kinds of behavior the mpi4py developers and contributors would like to see, and which we consider troublesome, bothersome, and unacceptable.
This document is a close adaptation of NumPy NEP 36.
Occasionally, we learn of modified mpi4py versions and binary distributions circulated by outsiders. These patched versions can cause problems to mpi4py users (see, e.g., mpi4py/mpi4py#508). When issues like these arise, our developers waste time identifying the problematic release, locating alterations, and determining an appropriate course of action.
In addition, packages on the Python Packaging Index are sometimes named such that users assume they are sanctioned or maintained by the mpi4py developers. We wish to reduce the number of such incidents.
This document aims to define a minimal set of rules that, when followed, will be considered good-faith efforts in line with the expectations of the mpi4py developers and contributors.
Our hope is that companies and outside developers who feel they need to modify mpi4py will first consider contributing to the project, or use alternative mechanisms for patching and extending mpi4py.
When in doubt, please talk to us first. We may suggest an alternative; at minimum, we’ll be informed and we may even grant an exception if deemed appropriate.
At time of writing, there are only a handful of mpi4py-named packages developed by the mpi4py project, including mpi4py and mpi4py-fft. We ask that outside packages not include the phrase mpi4py, i.e., avoid names such as mycompany-mpi4py or mpi4py-mycompany.
To be clear, this rule only applies to modules (package names); it is perfectly acceptable to have a submodule of your own package named mycompany.mpi4py.
We ask companies and outside developers to not publish binary mpi4py wheels in the main Python Package Index (https://pypi.org/) under names such mpi4py-mpich, mpi4py-openmpi, or mpi4py-vendor_mpi.
The usual approaches to build binary Python wheels involve the embedding of dependent shared libraries. While such an approach may seem convenient and often is, in the particular case of MPI and mpi4py it is ultimately harmful to end users. Embedding the MPI shared libraries would prevent the use of external, system-provided MPI installations with hardware-specific optimizations and site-specific tweaks.
The MPI Forum is currently discussing the standardization of a proposal for an Application Binary Interface (ABI) for MPI, see [mpi-abi-paper] and [mpi-abi-issue]. Such standardization will allow for any binary dependent on the MPI library to be used with multiple MPI backends. Once this proposal becomes part of the MPI standard, the mpi4py project will consider publishing on PyPI binary wheels capable of using any backend MPI implementation supporting the new MPI ABI specification. In the mean time, mpi4py is currently distributing experimental MPI and mpi4py binary wheels on https://anaconda.org/mpi4py.
Modified versions of mpi4py make it very difficult for the developers to address bug reports, since we typically do not know which parts of mpi4py have been modified.
If you have to break this rule (and we implore you not to!), then make it clear in the __version__ tag that you have modified mpi4py, e.g.:
>>> print(mpi4py.__version__) '4.0.0+mycompany.13`
We understand that minor patches are often required to make a library work inside of a package ecosystem. This is totally acceptable, but we ask that no substantive changes are made.
If you absolutely have to break the previous rule, please do not add additional functions to the namespace, or modify the API of existing functions. Having additional functions exposed in distributed versions is confusing for users and developers alike.
Copyright (c) 2025, Lisandro Dalcin
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
WARNING:
WARNING:
WARNING:
WARNING:
WARNING:
WARNING:
WARNING:
This is the fist release of the all-new, Cython-based, implementation of MPI for Python. Unfortunately, this implementation is not backward-compatible with the previous one. The list below summarizes the more important changes that can impact user codes.
MPI.COMM_WORLD[0].Send(...) MPI.COMM_WORLD[0].Recv(...) MPI.COMM_WORLD[0].Bcast(...)
have to be replaced by:
MPI.COMM_WORLD.Send(..., dest=0) MPI.COMM_WORLD.Recv(..., source=0) MPI.COMM_WORLD.Bcast(..., root=0)
tag_ub = MPI.COMM_WORLD.Get_attr(MPI.TAG_UB)
Lisandro Dalcin
2025, Lisandro Dalcin
| March 27, 2025 | 4.0 |