开发者

how to handle a situation in mpi where the number of messages to receive is unknown

I have an MPI program where each node sends some values to some other nodes. The senders know whic开发者_运维知识库h nodes to send the data but the receivers dont know 1)how much data is expected at their end and 2)which ranks are going to send to it.

I can use MPI_ANY_SOURCE for the second part of the above problem but I dont have a clue to how does the receiver know how much it has to receive. i.e. how many times should i be calling the receive function in MPI at the receiver node.


The great advantage of the one-sided communications stuff in MPI2 is that you don't need to coordinate sends with recieves, so that would definately be one approach. On the other hand, you still need to know how much data might come your way when creating the window for others to MPI_Put. So that's potentially a problem.

But coordinating point-to-point messages is possible, too. Since it sounds like all the senders know how many messages they'll be sending and to whom, you could combine all that information. Eg, say there were 4 processors, and process 1 had to send one message to each of processes 0 and 2. It could have an integer array toSend:

toSend[] = {1,0,1,0}

and so could each of the other processors. Then you could do an MPI_Allreduce(...., MPI_SUM,...) of these arrays, and now every processor would know the total number of messages to recieve; they could then post that many non-blocking recieves from MPI_ANY_SOURCE.

If the amount of data per message isn't known either, that's a little trickier; but you could do the same thing with the amount of data; create appropropriate buffer space; you could then do MPI_Bsend()s and the recievers could do MPI_Probes and MPI_Recv's.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜