I am interested in implementing a sort of event driven dispatch queue using MPI (message passing interface). The basic problem I want to solve is this: I have a master process which inserts jobs into a global queue, and each available slave process retrieves the next job in the queue if there is one.
From what I've read about MPI, it seems like sending and receiving processes must be in agreement about when they send and receive. As in, suppose one process sends a message but the other process does not know it needs to receive, or vice versa, then everything deadlocks. Is there any way to make every process a bit more independent?
You can do that as follows:
Declare one master-node (0), that is going to distribute the tasks. In this node the pseudocode is:
int sendTo
for task in tasks:
MPI_Recv(...sendTo, MPI_INT, MPI_ANY_SOURCE,...)
MPI_Send(job,... receiver: sendTo)
for node in nodes:
MPI_Recv(...sendTo, MPI_INT, MPI_ANY_SOURCE,...)
MPI_SEND(job_null,...,receiver: sendTo)
In the slave nodes the code would be:
while (true)
MPI_Send(myNodenum to 0, MPI_INT)
MPI_Recv(job from 0)
if (job == job_null)
break
else
execute job
I think this should work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With