title: Is MPI_Reduce blocking (or a natural barrier)?
body: <p>I have the code snippet below in C++ which basically calculates the pi using classic monte carlo technic.</p>
  
  <pre><code>    srand48((unsigned)time(0) + my_rank);
  
      for(int i = 0 ; i &lt; part_points; i++)
      {
              double x = drand48();
  
              double y = drand48();
  
              if( (pow(x,2)+pow(y,2)) &lt; 1){ ++count; }
      }
  
      MPI_Reduce(&amp;count, &amp;total_hits, 1, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD);
  
      MPI_Barrier(MPI_COMM_WORLD);
  
      if(my_rank == root)
      {
              pi = 4*(total_hits/(double)total_points);
  
              cout &lt;&lt; "Calculated pi: "  &lt;&lt;  pi &lt;&lt; " in " &lt;&lt; end_time-start_time &lt;&lt;  endl;
      }
  </code></pre>
  
  <p>I am just wondering if the MPI_Barrier call is necessary. Does MPI_Reduce make sure that the body of the if statement won't be executed before the reduce operation is completely finished ? Hope I was clear. Thanks</p>