mpi4py

TheMPI for Python package.

TheMessage Passing Interface (MPI) is a standardized and portablemessage-passing system designed to function on a wide variety ofparallel computers. The MPI standard defines the syntax and semanticsof library routines and allows users to write portable programs in themain scientific programming languages (Fortran, C, or C++). Since itsrelease, the MPI specification has become the leading standard formessage-passing libraries for parallel computers.

MPI for Python provides MPI bindings for the Python programminglanguage, allowing any Python program to exploit multiple processors.This package build on the MPI specification and provides an objectoriented interface which closely follows MPI-2 C++ bindings.

Runtime configuration options

mpi4py.rc

This object has attributes exposing runtime configuration options thatbecome effective at import time of theMPI module.

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 forirecv()

errors

Error handling policy

Attributes Documentation

mpi4py.rc.initialize

Automatic MPI initialization at import.

Type:

bool

Default:

True

mpi4py.rc.threads

Request initialization with thread support.

Type:

bool

Default:

True

mpi4py.rc.thread_level

Level of thread support to request.

Type:

str

Default:

"multiple"

Choices:

"multiple","serialized","funneled","single"

mpi4py.rc.finalize

Automatic MPI finalization at exit.

If set toNone, the value ofmpi4py.rc.initialize is used.

Type:

None orbool

Default:

None

mpi4py.rc.fast_reduce

Use tree-based reductions for objects.

Type:

bool

Default:

True

mpi4py.rc.recv_mprobe

Use matched probes to receive objects.

Type:

bool

Default:

True

mpi4py.rc.irecv_bufsz

Default buffer size in bytes forirecv().

Type:

int

Default:

32768

Added in version 4.0.0.

mpi4py.rc.errors

Error handling policy.

Type:

str

Default:

"exception"

Choices:

"exception","default","abort","fatal"

Example

MPI for Python features automatic initialization and finalization of the MPIexecution environment. By using thempi4py.rc object, MPI initialization andfinalization can be handled programmatically:

importmpi4pympi4py.rc.initialize=False# do not initialize MPI automaticallympi4py.rc.finalize=False# do not finalize MPI automaticallyfrommpi4pyimportMPI# import the 'MPI' moduleMPI.Init()# manual initialization of the MPI environment...# your finest code here ...MPI.Finalize()# manual finalization of the MPI environment

Environment variables

The following environment variables override the corresponding attributes ofthempi4py.rc andMPI.pickle objects at import time of theMPI module.

Note

For variables of boolean type, accepted values are0 and1(interpreted asFalse andTrue, respectively), and stringsspecifying aYAML boolean value (case-insensitive).

MPI4PY_RC_INITIALIZE
Type:

bool

Default:

True

Whether to automatically initialize MPI at import time of thempi4py.MPI module.

Added in version 4.0.0.

MPI4PY_RC_FINALIZE
Type:

None |bool

Default:

None

Choices:

None,True,False

Whether to automatically finalize MPI at exit time of the Python process.

Added in version 4.0.0.

MPI4PY_RC_THREADS
Type:

bool

Default:

True

Whether to initialize MPI with thread support.

Added in version 3.1.0.

MPI4PY_RC_THREAD_LEVEL
Default:

"multiple"

Choices:

"single","funneled","serialized","multiple"

The level of required thread support.

Added in version 3.1.0.

MPI4PY_RC_FAST_REDUCE
Type:

bool

Default:

True

Whether to use tree-based reductions for objects.

Added in version 3.1.0.

MPI4PY_RC_RECV_MPROBE
Type:

bool

Default:

True

Whether to use matched probes to receive objects.

MPI4PY_RC_IRECV_BUFSZ
Type:

int

Default:

32768

Default buffer size in bytes forirecv().

Added in version 4.0.0.

MPI4PY_RC_ERRORS
Default:

"exception"

Choices:

"exception","default","abort","fatal"

Controls default MPI error handling policy.

Added in version 3.1.0.

MPI4PY_PICKLE_PROTOCOL
Type:

int

Default:

pickle.HIGHEST_PROTOCOL

Controls the default pickle protocol to use when communicating Pythonobjects.

See also

PROTOCOL attribute of theMPI.pickle object within theMPI module.

Added in version 3.1.0.

MPI4PY_PICKLE_THRESHOLD
Type:

int

Default:

262144

Controls the default buffer size threshold for switching from in-band toout-of-band buffer handling when using pickle protocol version 5 or higher.

See also

THRESHOLD attribute of theMPI.pickle object within theMPI module.

Added in version 3.1.2.

Miscellaneous functions

mpi4py.profile(name,*,path=None)

Support for the MPI profiling interface.

Parameters:
  • name (str) – Name of the profiler library to load.

  • path (sequence ofstr,optional) – Additional paths to search for the profiler.

Return type:

None

mpi4py.get_include()

Return the directory in the package that contains header files.

Extension modules that need to compile against mpi4py should usethis function to locate the appropriate include directory. UsingPython distutils (or perhaps NumPy distutils):

importmpi4pyExtension('extension_name',...include_dirs=[...,mpi4py.get_include()])
Return type:

str

mpi4py.get_config()

Return a dictionary with information about MPI.

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 anmpisection within a UTF-8 encoded INI-style configuration filempi.cfg located at the top-level package directory.The configuration file is read and parsed using theconfigparser module.

Return type:

dict[str,str]