Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>One solution is to use MPI_IProbe() to test if a message is waiting.</p> <ul> <li><p>On this line, use a pointer instead of "12"</p> <pre><code>MPI_Isend(12, 1, MPI_INT, 0, 100, MPI_COMM_WORLD, &amp;request); </code></pre></li> <li><p>Add flag=0 here : </p> <pre><code>while(flag!=0) { // something done that at some point changes flag } </code></pre></li> </ul> <p>Here goes the code :</p> <pre><code>#include "mpi.h" #include "stdio.h" int main(int argc, char *argv[]) { int numprocs, rank; MPI_Request request; 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); if(rank == 0) // the searching process { int i; for (i=0; i &lt; 4000000; i++) { // do some stuff here; does not matter what //printf("I am still running!\n"); int flag; MPI_Iprobe(MPI_ANY_SOURCE,100,MPI_COMM_WORLD,&amp;flag,&amp;status); if(flag!=0){ int value; MPI_Recv(&amp;value, 1, MPI_INT, status.MPI_SOURCE, status.MPI_TAG, MPI_COMM_WORLD, &amp;status); printf("I (0) received %d \n",value); } /* see if any message has been transmitted to me at this point without blocking the process; if at this time it happens to be transmitted, do something and than continue with for iternations; or just continue with for iterations and maybe next time will have a message which sends me to do something */ } } else { int i; for(i=0;i&lt;42;i++){ int flag = 1; while(flag!=0) { // something done that at some point changes flag flag=0; } int bla=1000*rank+i; // send a message to process with rank 0 and don't get stuck here MPI_Isend(&amp;bla, 1, MPI_INT, 0, 100, MPI_COMM_WORLD, &amp;request); // some other stuff done printf("I (%d) do something\n",rank); // wait for message to be transmitted MPI_Wait(&amp;request, &amp;status); } } MPI_Finalize(); return 0; } </code></pre> <p>Bye,</p> <p>Francis</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload