title: How can I check receive message in MPI
body: <p>I am trying to write MPI Send/Receive code but I have a problem. I want to check receive message. If I have a message from any source, read this. Otherwise, continue code.</p>
  
  <pre><code>MPI_Comm_size(MPI_COMM_WORLD,&amp;p);
  MPI_Comm_rank(MPI_COMM_WORLD,&amp;id);
  MPI_Status status;
  int source,ask,request,answer,tag=10;
  for(i=first; i&lt;last; i++){
      if(there is a message for my id){
          MPI_Recv(&amp;request,1,MPI_INT,MPI_ANY_SOURCE,tag,MPI_COMM_WORLD,&amp;status);
          answer = request*request;
          source = status.MPI_SOURCE;
          MPI_Send(&amp;answer,1,MPI_INT,source,tag+1,MPI_COMM_WORLD);
      }
      square=i*i;
      if(last &lt; square){
      MPI_Send(&amp;square,1,MPI_INT,id-1,tag,MPI_COMM_WORLD);
      MPI_Recv(&amp;square,1,MPI_INT,id-1,tag+1,MPI_COMM_WORLD,&amp;status);
      }
      local[i]=square;
  }
  </code></pre>
  
  <p>If I can't check receive message with if statement, Can I check with timeout or wait expression?
  *I know this code trivial but I hope it can help us. </p>
  
  <p>Thanks</p>