My question is rather simple, the MPI_Scatter function definition is:
#include <mpi.h>
void MPI::Comm::Scatter(const void* sendbuf, int sendcount,
const MPI::Datatype& sendtype, void* recvbuf,
int recvcount, const MPI::Datatype& recvtype,
int root) const
Are ‘sendcount’ and ‘sendtype’ redundant?
In which case it can happen: sendcount!=recvcount?
Edit:
Maybe some clarification is needed about the question. I understand that maybe the reason is that, for the root the data is some ‘struct X’ and for the receivers is some ‘struct Y’ that somehow it also makes sense (it all fits ‘Ok’).
If that’s the case… I don’t get why is needed to say again that the total size of the expected data to receive, is the same of the sended data size. If it’s just a matter of casting the view of the data, I’d only do the cast. In fact, the buffer is a (void *).
MPI allows for both datatypes on the sending and on the receiving end to be different as long as they are constructed from the same basic datatypes. Thare are many cases where this comes handy, e.g. scattering rows of a matrix from the root process into columns in the other processes. Sending and receiving rows is straightforward in C and C++ as the memory layout of the matrices is row-major. Sending and receiving columns requres that a special strided vector type is constructed first. Usually this type is constructed for a specified number of rows and columns and then one has to supply a count of
1when receiving the data.There are also many other cases when
sendcountandrecvcountmight differ. Mind also thatrecvcountdoes not specify the size of the message to be received but rather the capacity of the receive buffer and that capacity may be way larger than the size of the message.