title: How actually MPI_Waitall works
body: <p>Does <a href="https://computing.llnl.gov/tutorials/mpi/" rel="nofollow">this example</a> contradict <a href="http://www.open-mpi.org/doc/v1.4/man3/MPI_Waitall.3.php" rel="nofollow">the manual</a>? The manual states that both the array of requests and the array of statuses must be of the same size. To be more precise, both arrays should be at least as long as it indicated by the <em>count</em> argument. Yet in the below example status array size is 2, not 4. Also, the example contradicts this statement from the manual </p>
  
  <blockquote>
    <p>The error-free execution of MPI_Waitall(count, array_of_requests,
    array_of_statuses) has the same effect as the execution of
    MPI_Wait(&amp;array_of_request[i], &amp;array_of_statuses[i]), for
    i=0,...,count-1, in some arbitrary order.</p>
  </blockquote>
  
  <pre><code>#include "mpi.h"
  #include &lt;stdio.h&gt;
  
  int main(argc,argv)
  int argc;
  char *argv[];  {
  int numtasks, rank, next, prev, buf[2], tag1=1, tag2=2;
  MPI_Request reqs[4];
  MPI_Status stats[2];
  
  MPI_Init(&amp;argc,&amp;argv);
  MPI_Comm_size(MPI_COMM_WORLD, &amp;numtasks);
  MPI_Comm_rank(MPI_COMM_WORLD, &amp;rank);
  
  prev = rank-1;
  next = rank+1;
  if (rank == 0)  prev = numtasks - 1;
  if (rank == (numtasks - 1))  next = 0;
  
  MPI_Irecv(&amp;buf[0], 1, MPI_INT, prev, tag1, MPI_COMM_WORLD, &amp;reqs[0]);
  MPI_Irecv(&amp;buf[1], 1, MPI_INT, next, tag2, MPI_COMM_WORLD, &amp;reqs[1]);
  
  MPI_Isend(&amp;rank, 1, MPI_INT, prev, tag2, MPI_COMM_WORLD, &amp;reqs[2]);
  MPI_Isend(&amp;rank, 1, MPI_INT, next, tag1, MPI_COMM_WORLD, &amp;reqs[3]);
  
        {  do some work  }
  
  MPI_Waitall(4, reqs, stats);
  
  MPI_Finalize();
  }
  </code></pre>
  
  <p>P.S. Definition of main looks strange. The return value is missing. Is it prehistoric C or typo?</p>