6
votes

I want to send a message to one of the ranks receiving a message with a specific tag. If there is any rank received the message and the message is consumed. In MPI_Recv() we can receive a message using MPI_ANY_SOURCE/MPI_ANY_TAG but the MPI_Send() can't do this. How can I send an message with unknown destination? The MPI_Bcast() can't do it because after receiving, I have to reply to the source process. Thanks.

3
If the receiver knows what data it needs, you could use one-sided MPI operations, namely MPI_Get.Greg Inozemtsev
This question would be really well-received on scicomp.stackexchange.comAron Ahmadia

3 Answers

6
votes

What I would do is have the worker processes signal to the master that they're ready to receive. The master would keep track of which ranks are ready, pick one (lowest rank first, random, round robin, however you like), send to it, and clear its "ready" flag.

1
votes

Do you just want to send a message it to a random rank?

 MPI_Comm_size(MPI_COMM_WORLD, &size);
 sendto = rand() % size;
 MPI_Send(buffer, count, MPI_CHAR, sendto, 0, MPI_COMM_WORLD);
1
votes

The short answer is: You cannot do this in MPI.

The slightly longer answer is: You probably do not want to do this. I am guessing that you are trying to set up some sort of work-stealing. As suszterpatt suggested, you could use one-sided communication to 'grab' the work from the sending process, but you will need to use locks, and this will not scale well to many processes unless there is some idea of a local process group (i.e., you cannot have 1,000 processes all work-stealing from one process, you will need to decompose things).