References:

Just like standard MPI, all the collective routines are blocking by default, but each one has a non-blocking version that, similar to the point-to-point communication, begins with an 'I'. Only the blocking routines will be shown here.

Broadcast (Comm.bcast | Comm.Bcast):

It works exactly like standard MPI, every process has to call the routine.

Functions prototypes:

def bcast(
    obj: Any, #Data to send (**None** if process is receiving)
    root: int = 0 #Root rank
) -> Any #Returns the data.

def Bcast(
    buf: BufSpec, #Buffer data
    root: int = 0 #Root rank
) -> None #The data is received through the Buffer data.

Usage examples:

Python object example:

from mpi4py import MPI

comm = MPI.COMM_WORLD
rank = comm.Get_rank()

data = None
if(rank == 0): data = {'name': 'John Doe', 'age': 21}
  
data = comm.bcast(data, root=0) #Unnecessary to specify root rank

if(rank != 0):
  print('Rank ' + str(rank) + ' data: ', end="")
  print(data)

Output:

Untitled

Buffer-like object example:

from mpi4py import MPI
import numpy

comm = MPI.COMM_WORLD
rank = comm.Get_rank()

data = None
if(rank == 0): data = numpy.arange(10, dtype='i')
else: data = numpy.empty(10, dtype='i')
  
comm.Bcast([data, MPI.INT], root=0) #Unnecessary to specify root rank

if(rank != 0):
  print('Rank ' + str(rank) + ' data: ', end="")
  print(data)

Output:

Untitled

Scatter (Comm.scatter | Comm.Scatter):

It works exactly like standard MPI, every process has to call the routine.