While implementing a parallel algorithm in Python 3.7.0 using MPI4PY 3.0.0 on MSMPI on Windows 10, I was having problems with the Gatherv not gathering everything... When cheking printing of various bits it seemed to be executing things in the wrong order.
I wrote a bit of code that duplicates the problem :
from mpi4py import MPI
from time import sleep
import random
comm = MPI.COMM_WORLD
rank = comm.Get_rank()
if rank == 0:
sleep(2)
print("head finished sleeping")
comm.Barrier()
sleep(random.uniform(0, 2))
print(rank, 'finished sleeping ')
comm.Barrier()
if rank == 0:
print("All done!")
If I understand comm.Barrier()
correctly this should produce
head finished sleeping
2 finished sleeping
0 finished sleeping
3 finished sleeping
1 finished sleeping
4 finished sleeping
All done!
with the middle bits in some order, right? But when I actually run mpiexec -n 5 python .\blocking_test.py
I get as follows:
2 finished sleeping
1 finished sleeping
3 finished sleeping
head finished sleeping
0 finished sleeping
All done!
4 finished sleeping
Do I misunderstand the usage of comm.Barrier()
, or is there something wrong with my environment?