title: MPI basic example doesn't work
body: <p>I am trying to understand what was meant by the example below:</p>
  
  <pre><code>#include "mpi.h"
  #include &lt;stdio.h&gt;
  
  int main(int argc, char *argv[]) {
    int numtasks, rank, dest, source, rc, count, tag = 1;
    char inmsg, outmsg = 'x';
    MPI_Status Stat;
  
    MPI_Init(&amp;argc, &amp;argv);
    MPI_Comm_size(MPI_COMM_WORLD, &amp;numtasks);
    MPI_Comm_rank(MPI_COMM_WORLD, &amp;rank);
  
    if (rank == 0) {
      dest = 1;
      source = 1;
      rc = MPI_Send(&amp;outmsg, 1, MPI_CHAR, dest, tag, MPI_COMM_WORLD);
      rc = MPI_Recv(&amp;inmsg, 1, MPI_CHAR, source, tag, MPI_COMM_WORLD, &amp;Stat);
    } else if (rank == 1) {
      dest = 0;
      source = 0;
      rc = MPI_Recv(&amp;inmsg, 1, MPI_CHAR, source, tag, MPI_COMM_WORLD, &amp;Stat);
      rc = MPI_Send(&amp;outmsg, 1, MPI_CHAR, dest, tag, MPI_COMM_WORLD);
    }
  
    rc = MPI_Get_count(&amp;Stat, MPI_CHAR, &amp;count);
    printf("Task %d: Received %d char(s) from task %d with tag %d \n",
           rank, count, Stat.MPI_SOURCE, Stat.MPI_TAG);
  
    MPI_Finalize();
  }
  </code></pre>
  
  <p>Essentially copied from here: <a href="https://computing.llnl.gov/tutorials/mpi/" rel="nofollow">https://computing.llnl.gov/tutorials/mpi/</a></p>
  
  <p>Compiled like this:</p>
  
  <pre><code>$ mpicc -o ./mpi_test ./mpi_test.c
  </code></pre>
  
  <p>Run like this:</p>
  
  <pre><code>$ ./mpi_test 
  </code></pre>
  
  <p>Gives this error:</p>
  
  <pre><code>Fatal error in MPI_Send: Invalid rank, error stack:
  MPI_Send(171): MPI_Send(buf=0x7fff787b4d93, count=1, MPI_CHAR, dest=1, tag=1, MPI_COMM_WORLD) failed
  MPI_Send(97).: Invalid rank has value 1 but must be nonnegative and less than 1
  </code></pre>
  
  <p>To be honest, I don't understand why the example should have worked in the first place. Can you please enlighten me? Is the example wrong, or is the error expected? Perhaps my setup is wrong?</p>
  
  <p>PS. Compiled with gcc 4.7 on Fedora 18 amd64</p>