I noticed a strange thing with MPI_Send and MPI_Recv buffer size which I can't understand. The documentation says that the count
argument of these functions describes a number of elements of datatype
type:
int MPI_Send(void *buf, int count, MPI_Datatype datatype, int dest,
int tag, MPI_Comm comm);
count [in] number of elements in send buffer (nonnegative integer)
int MPI_Recv(void *buf, int count, MPI_Datatype datatype, int source,
int tag, MPI_Comm comm, MPI_Status *status);
count [in] maximum number of elements in receive buffer (integer)
Suppose we have 2 processes, the first (root) process allocates an array of n integers and fills it with some data
int* temp = (int*) malloc(n * sizeof(int));
for (int i = 0; i < n; i++) temp[i] = ...;
then sends it to the second process with rank = 1.
MPI_Send(temp, n, MPI_INT, 1, 0, MPI_COMM_WORLD);
The second process receives this array of n integers.
MPI_Recv(temp, n, MPI_INT, 0, 0, MPI_COMM_WORLD, MPI_STATUS_INGNORE);
But after MPI_Recv the temp
array appeared truncated. When I changed count
argument from n
to n * sizeof(int)
, I received a correct array. But n * sizeof(int)
describes buffer size in bytes, not in elements as documentation says. Is it a common behavior or a simple misunderstanding? P.S. I use MPICH2 x86 as MPI implementation and 32-bit VS08 on Windows 7.