I am trying to write a MPI program on Python to calculate the average of the neighbors value.
My algorithm is as follows
Initialize value with the neighbors you have. Then Compute the average of your neighbors value and subtract from new value.
I have written the following program
from mpi4py import MPI
import sys
comm = MPI.COMM_WORLD
size = comm.Get_size()
rank = comm.Get_rank()
myvalue=2
sum=0
neighb=1
nvalue=0
if rank == 0 or rank == size-1:
myvalue=1
neighb=myvalue
if rank < size-1:
msg = myvalue
comm.send(msg, dest=rank+1)
sys.stdout.write("rank send %d: %s" % (rank, myvalue))
comm.recv(nvalue,source=rank+1)
sum+=nvalue
sys.stdout.write("rank RECV %d: %s" % (rank, nvalue))
if rank > 0:
comm.recv(nvalue,rank-1)
sum+=nvalue
sys.stdout.write("rank RECV %d: %s" % (rank, nvalue))
comm.send(myvalue,rank-1)
sys.stdout.write("rank send %d: %s" % (rank, myvalue))
avg =sum/neighb
myvalue-=avg
But the program is not working it gets stuck, the following window appears when i try to run it on console using below command,
mpiexec -n 4 python p2p_linnear.py -m mpi4py