title: MPI Sendrecv with MPI_ANY_SOURCE
body: <p>Is it possible to do an MPI_Sendrecv exchange where one side does not know the rank of the other? If not, what is the best way to do that (my next guess would just be a pair of sends and recvs)?</p>
  
  <p>For example in C if I want to exchange integers between rank 0 and some other rank would this type of thing work?:</p>
  
  <pre><code>MPI_Status stat;
  if(rank){
    int someval = 0;
    MPI_Sendrecv(&amp;someval, 1, MPI_INT, 0, 1, &amp;recvbuf, 1, MPI_INT, 0, MPI_ANY_TAG, MPI_COMM_WORLD, &amp;stat);
  }else{
    int someotherval = 1;
    MPI_Sendrecv(&amp;someotherval, 1, MPI_INT, MPI_ANY_SOURCE, someotherval, &amp;recvbuf, 1, MPI_INT, MPI_ANY_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD, &amp;stat);
  }
  </code></pre>
  
  <p>EDIT:
  Looks like it is not possible. I whipped up the following as a sort of wrapper to add the functionality that I need.</p>
  
  <pre><code>void slave_sendrecv(const void *sendbuf, int sendcount, MPI_Datatype sendtype,
      int dest, int sendtag, void *recvbuf, int recvcount,
      MPI_Datatype recvtype, int source, int recvtag, MPI_Status *status){
  
      MPI_Send(sendbuf, sendcount, sendtype, dest, sendtag, MPI_COMM_WORLD);
      MPI_Recv(recvbuf, recvcount, recvtype, source, recvtag, MPI_COMM_WORLD, status);
  }
  
  void anon_sendrecv(const void *sendbuf, int sendcount, MPI_Datatype sendtype,
      int sendtag, void *recvbuf, int recvcount,
      MPI_Datatype recvtype, int recvtag, MPI_Status *status){
  
      int anon_rank;
      MPI_Recv(recvbuf, recvcount, recvtype, MPI_ANY_SOURCE, recvtag, MPI_COMM_WORLD, status);
      anon_rank = status -&gt; MPI_SOURCE;
      MPI_Send(sendbuf, sendcount, sendtype, anon_rank, sendtag, MPI_COMM_WORLD);
  }
  </code></pre>
  
  <p>EDIT 2: Based on Patrick's answer it looks like the slave_sendrecv function above is not needed, you can just use regular MPI_Sendrecv on the end that knows who it's sending to.</p>