title: MPI_Send/MPI_Recv: count of elements or buffer size?
body: <p>I noticed a strange thing with MPI_Send and MPI_Recv buffer size which I can't understand. The documentation says that the <code>count</code> argument of these functions describes <strong>a number of elements</strong> of <code>datatype</code> type: </p>
  
  <pre><code>int MPI_Send(void *buf, int count, MPI_Datatype datatype, int dest, 
               int tag, MPI_Comm comm);
  </code></pre>
  
  <blockquote>
    <p>count [in] number of elements in send buffer (nonnegative integer)</p>
  </blockquote>
  
  <pre><code>int MPI_Recv(void *buf, int count, MPI_Datatype datatype, int source, 
               int tag, MPI_Comm comm,  MPI_Status *status);
  </code></pre>
  
  <blockquote>
    <p>count [in] maximum number of elements in receive buffer (integer)</p>
  </blockquote>
  
  <p>Suppose we have 2 processes, the first (root) process allocates an array of <strong>n</strong> integers and fills it with some data </p>
  
  <pre><code>int* temp = (int*) malloc(n * sizeof(int));
  for (int i = 0; i &lt; n; i++) temp[i] = ...;
  </code></pre>
  
  <p>then sends it to the second process with rank = 1.</p>
  
  <pre><code>MPI_Send(temp, n, MPI_INT, 1, 0, MPI_COMM_WORLD);
  </code></pre>
  
  <p>The second process receives this array of <strong>n</strong> integers.</p>
  
  <pre><code>MPI_Recv(temp, n, MPI_INT, 0, 0, MPI_COMM_WORLD, MPI_STATUS_INGNORE);
  </code></pre>
  
  <p>But after MPI_Recv the <code>temp</code> array appeared truncated. When I changed <code>count</code> argument from <code>n</code> to <code>n * sizeof(int)</code>, I received a correct array. But <code>n * sizeof(int)</code> 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.</p>