References:

Initializing and finalizing a program:

The first difference of mpi4py (compared to standard mpi) is that it automatically initializes and terminates the MPI Execution Environment. However, if you wish, you can disable this feature and perform this operation manually, as follows:

import mpi4py

mpi4py.rc.initialize = False;
mpi4py.rc.finalize = False;

from mpi4py import MPI

MPI.Init();

# MPI code ...

MPI.Finalize();

The code that uses automatic operations looks like this:

from mpi4py import MPI

# MPI code ...

Communicators:

There are three predefined communicators instances:

Routines usage:

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).

The mpi4py routines are methods of communicator objects, so there is no need to pass the communicator as a parameter. However, it is possible to call the routines statically (MPI.Comm). In these cases, you will need to pass the communicator.

Note: “Pickling” is the process whereby a Python object hierarchy is converted into a byte stream, and “unpickling” is the inverse operation, whereby a byte stream (from a binary file or bytes-like object) is converted back into an object hierarchy.

Communication of generic Python objects: