In c in "mpi.h", i think it will be something like
MPI_Request mpireq[2];
MPI_Status mpistat;
int temp, index, flag;
MPI_Irecv(temp, 1, MPI_INT, MPI_ANY_SOURCE, 0, MPI_COMM_WORLD, &mpireq[0]);
MPI_Irecv(temp, 1, MPI_INT, MPI_ANY_SOURCE, 1, MPI_COMM_WORLD, &mpireq[1]);
MPI_Testany(2, mpireq, &index, &flag, &mpistat);
but i think Testany is a non-blocking so i don't know how to use flag and index i propose something like but i don't if this is going to work.
if(flag){
printf("someone came\n");
if (index == 0){do something}
else{do something else}
} else
printf("No one is here yet");
I tried something like this and it seems to work
MPI_Irecv
MPI_Irecv
MPI_Testany
while(!flag)
MPI_Testany();
if(flag)
capture Irecv that comes first;