References:
It works the same way as standard MPI.
def barrier() -> None #Python objects
#or
def Barrier() -> None #Buffer-like objects
Program without barrier:
from mpi4py import MPI
communicator = MPI.COMM_WORLD
size = communicator.size
rank = communicator.Get_rank()
print(rank)
Output:
As you can see, the output order is unpredictable.
Program with barrier:
from mpi4py import MPI
communicator = MPI.COMM_WORLD
size = communicator.size
rank = communicator.Get_rank()
for ind in range(size):
if(ind == rank): print(rank)
communicator.barrier();
Output:
Using a barrier it is possible to ensure that the output is in order.
Firstly lets see the basic communication, using Python objects.