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