title: MPI_Send and MPI_Recv not matching C
body: <p>I am trying to implement a workpool here. I am supposed to send 100 differnt to numbers in total to slave processes. Each slave process then returns something to master process and another different number is sent to the slave by the master. This continues until all the 100 iterations are over.</p>
  
  <p>My program gets kind of stuck in an infinite loop which I think is due to incorrect mapping of MPI_Send and MPI_Recv. I can't figure out what I am doing wrong. I have spent quite a few hours looking into this but to no avail. I am new to MPI and programming in general. The code is given below:</p>
  
  <pre><code>if(rank == 0) {
          int i,iteration = 0, a=0,inside=0,temp=0;
          for(i = 1; i &lt; slaves; i++) {
          MPI_Send(&amp;iteration,1,MPI_INT,i,0,MPI_COMM_WORLD);
          MPI_Send(&amp;a,1,MPI_INT,i,1,MPI_COMM_WORLD);
          iteration++;
      }
      while(iteration &lt; 100+slaves){
          MPI_Recv(&amp;temp,1,MPI_INT,MPI_ANY_SOURCE,0, MPI_COMM_WORLD, &amp;status);
          if(iteration &lt; 100) {
              MPI_Send(&amp;iteration,1,MPI_INT,status.MPI_SOURCE,0,MPI_COMM_WORLD);
              MPI_Send(&amp;a,1,MPI_INT,status.MPI_SOURCE,1,MPI_COMM_WORLD);
          }
          iteration++;
          inside = inside + temp;
      }
  }
  else {
      int iteration=0,count=0;
      if(iteration &lt; 100) {
          MPI_Recv(&amp;iteration,1,MPI_INT,0,0,MPI_COMM_WORLD,&amp;status);
          MPI_Recv(&amp;count,1,MPI_INT,0,1,MPI_COMM_WORLD,&amp;status);
          MPI_Send(&amp;count,1,MPI_INT,0,0,MPI_COMM_WORLD);
      }
  }
  </code></pre>