maxwong
maxwong

Reputation: 63

How to send a message without a specific destination in MPI?

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.

Upvotes: 6

Views: 5904

Answers (3)

Aron Ahmadia
Aron Ahmadia

Reputation: 2405

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).

Upvotes: 1

suszterpatt
suszterpatt

Reputation: 8273

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.

Upvotes: 6

eduffy
eduffy

Reputation: 40224

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);

Upvotes: 1

Related Questions