0
votes

Refer to the following gather code:

from mpi4py import MPI

comm = MPI.COMM.WORLD
size = comm.Get_size()
rank = comm.Get_rank()
stat = MPI.Status()

message = (rank)**2
print "Before Gather ",rank, message

message = comm.gather(message, root=0)

if rank == 0:
        print "After Gather ",rank,message

How can I use the comm.barrier() function to ensure the “After” step always comes after all the “Before” steps?

If I put comm.barrier() before if condition, the results would just be in any order.

I've tried flush and it doesn't work.

Should I specify the send buffer and receive buffer using Gather?

Or, should I try gather everything to one process, then scatter, then gather again?

Any advice is more than welcome and appreciated.

1

1 Answers

0
votes

Basically, you cannot.

stdout from each MPI tasks are gathered and then printed by mpirun, and there is no mechanism that enforces any kind of global order.

The only guarantee is that Before Gather 0 ... will always be printed before After Gather 0 ...