For example, I have a root process which sends some computations to be completed by worker processes. But because I have limited (4
) processes I have to share the workload to all of them so I send multiple times. The workaround that I have found is this:
int me = MPI.COMM_WORLD.Rank();
if(me == 0) {
sendToWorkers(); //Sends more than once to workers.
}
else {
while(true) {//wait indefinitely, accept data received from root process and work on it.
MPI.COMM_WORLD.Recv(Buf, 0, Buf.length, MPI.INT, 0, 0);
doTask(Buf);
}
}
Now the problem arises that I want to send data that has completed processing back to the root process but I can't do another while(true);
. I am sure there must be a much more elegant way to accomplish this.
EDIT 1: The reason why I want to send to root process is because it is cleaner. However, alternatively I can just print computed solutions from the worker processes but the output is all mangled up due to interleaving. Declaring the print
method to be synchronized
doesn't work.