Is there a library call that would allow for sending/receiving of variable sized messages using MPI?
A work around would be to send the data size in the first message and follow it with the actual payload, but I was wondering if there was a convention for combining these two separate messages.
The count provided to MPI_Recv is only an upper bound. MPI_Get_count can be used to find the exact number of items received.
Kind of like sockets I guess.
You could also use
MPI_Probe
orMPI_Iprobe
instead of posting a receive withMPI_Recv
orMPI_Irecv
. Probe/Iprobe can have performance disadvantages if used incorrectly, but they are one common approach to dealing with variable-sized messages. Also, be careful in a multithreaded environment because Probe/Iprobe are not safe in some multithreaded contexts. See Hoefler et al. for a thorough discussion of these problems and a sketch of the fix (Mprobe) likely to be included in MPI-3.