I am new to distributed parallel programming. In the following code the process 0 gets stuck on MPI.Recv method execution..
if (me != 0) {
if (finalTour != null) {
Node[] nodes = new Node[5];
nodes[0] = finalTour;
MPI.COMM_WORLD.Send(nodes, 0, 5, MPI.OBJECT, 0, 0);
}
}
if (me == 0) {
for (int i = 1; i < processes; i++) {
Node[] nodes = new Node[5];
MPI.COMM_WORLD.Recv(nodes, 0, 5, MPI.OBJECT, MPI.ANY_SOURCE, MPI.ANY_TAG);
if (nodes[0] != null) {
if (finalTour != null) {
if (finalTour.cost > nodes[0].cost) {
finalTour = nodes[0];
}
minCostPath = finalTour;
} else {
finalTour = nodes[0];
minCostPath = finalTour;
}
}
}
}
MPI.Finalize();
if (minCostPath != null) {
print(size, minCostPath);
}
When I debugged this snippet, I observed the following:
1. Sometimes the Recv method is executed before the corresponding send method does. Could this pose a problem?
2. All the processes except 0 send a message to process 0 and execute their MPI.Finalize() method, while process 0 is waiting on a Recv. Could the problem be because of this?