开发者

MPI_Recv: Receiving a different size than the one Sent

I am writing a program to check shortest path using the MPI library. There are two scenarios:

Either I found a better path, in 开发者_开发技巧with case the first slot of the buffer will state resultBuff[0] = 1 and I will need to go over the rest of the contents of the buffer to get the better path.

The other case is resultBuff[0] = 0, and I won't excpect any values in the other cells of the buffer.

Is it possible for me to use separate MPI_Isend calls:

In case I found a better path and stored it in resultBuff[1] to resultBuff[10]:

MPI_Isend((void*)sendBuff, 11, MPI_INT, 0, 1, MPI_COMM_WORLD, &request);

In case didn't found a better path:

MPI_Isend((void*)sendBuff, 1, MPI_INT, 0, 1, MPI_COMM_WORLD, &request);

And in both cases I'll use

MPI_Recv( (void*)resultBuff, 11, MPI_INT, MPI_ANY_SOURCE, 1, MPI_COMM_WORLD, &status);

to receive the result.

Will this work?

If it does, would I save communication costs if don't send a better path?

Note: resultBuff is of size 11.


Yes, you can do this. From the MPI standard and man pages for MPI_Recv, "the count argument indicates the maximum length of a message; the actual number can be determined with MPI_Get_count" which you call using the status object you got back from MPI_Recv().

As to saving communication costs, it probably won't -- such short messages are dominated by the latency of sending the message rather than the bandwidth.


You don't need to send a message to say "I found nothing": the lack of a message can convey that information just as well. The receiver(s) can just periodically call MPI_Test, and examine the status object to see whether a new message was received or not.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜