-2

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");
  • What is `flag` ? What is *something* ? does *something* have side effects? Also: your automatic variables are uninitialised. – wildplasser Dec 18 '21 at 00:29
  • There is no global order in MPI, so even if I do not know what you have in mind by "the first irecv that will arrive" you are probably getting it wrong. `MPI_Testany()` is non blocking, are you looking for the blocking version (`MPI_Waitany()`)? `flag` is true if a message has been received, and then `index` is the index in the requests array (in `mpireq` here) that has matched. – Gilles Gouaillardet Dec 18 '21 at 02:52
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Dec 25 '21 at 20:58

1 Answers1

0

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;