title: MPI Send Recv deadlock
body: <p>I write programs using MPI and I have an access to two different clusters. I am not good in system administration, so I can not tell anything about software, OS, compilers which are used there. But, on one machine I have an deadlock using such code:</p>
  
  <pre><code>#include "mpi.h"
  #include &lt;iostream&gt;
  
  int main(int argc, char **argv) {
  
    int rank, numprocs;
    MPI_Status status;
  
    MPI_Init(&amp;argc, &amp;argv);
    MPI_Comm_rank(MPI_COMM_WORLD, &amp;rank);
    MPI_Comm_size(MPI_COMM_WORLD, &amp;numprocs);
  
    int x = rank;
  
    if (rank == 0) {
        for (int i=0; i&lt;numprocs; ++i)
            MPI_Send(&amp;x, 1, MPI_INT, i, 100500, MPI_COMM_WORLD);
    }
    MPI_Recv(&amp;x, 1, MPI_INT, 0, 100500, MPI_COMM_WORLD, &amp;status);
  
    MPI_Finalize();
    return 0;
  }
  </code></pre>
  
  <p>The error message is related:</p>
  
  <pre><code>Fatal error in MPI_Send: Other MPI error, error stack:
  MPI_Send(184): MPI_Send(buf=0x7fffffffceb0, count=1, MPI_INT, dest=0, tag=100500, MPI_COMM_WORLD) failed
  MPID_Send(54): DEADLOCK: attempting to send a message to the local process without a prior matching receive
  </code></pre>
  
  <p>Why is that so? I can't understand, why does it happen on one machine, but doesn't happen on another?</p>