Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MPI_Recv: Receiving a different size than the one Sent

Tags:

c

mpi

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.

like image 343
hizki Avatar asked Nov 15 '22 03:11

hizki


1 Answers

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.

like image 171
Jonathan Dursi Avatar answered Dec 20 '22 10:12

Jonathan Dursi