I am new to MPI using Python and I have some problems here. This is my code:
from mpi4py import MPI
comm = MPI.COMM_WORLD
rank = comm.Get_rank()
if rank == 0:
a = 1
comm.bcast(a, root=0)
s = comm.reduce(a, op=MPI.SUM)
print 'From process 0, sum =', s
elif rank == 1:
b = 2
comm.bcast(b, root=1)
x = comm.reduce(b, op=MPI.SUM)
print 'From process 1, sum =', x
I want to print: From process PROCESS_NUMBER, sum = 3
Process 0 prints correctly, but process 1 prints No.
I do not understand why. Can anyone help me?
source
share