title: MPI gather/reduce operation confusion?
body: <p>In the <a href="http://www.boost.org/doc/libs/1_50_0/doc/html/mpi/tutorial.html" rel="nofollow">boost tutorial</a> there are examples of gather and reduce operations. The code for gather is as follows:</p>
  
  <pre><code>#include &lt;boost/mpi.hpp&gt;
  #include &lt;iostream&gt;
  #include &lt;vector&gt;
  #include &lt;cstdlib&gt;
  namespace mpi = boost::mpi;
  
  int main(int argc, char* argv[])
  {
    mpi::environment env(argc, argv);
    mpi::communicator world;
  
    std::srand(time(0) + world.rank());
    int my_number = std::rand();
    if (world.rank() == 0) {
      std::vector&lt;int&gt; all_numbers;
      gather(world, my_number, all_numbers, 0);
      for (int proc = 0; proc &lt; world.size(); ++proc)
        std::cout &lt;&lt; "Process #" &lt;&lt; proc &lt;&lt; " thought of "
                  &lt;&lt; all_numbers[proc] &lt;&lt; std::endl;
    } else {
      gather(world, my_number, 0);
    }
  
    return 0;
  }
  </code></pre>
  
  <p>And the example for reduce is as follows:</p>
  
  <pre><code>#include &lt;boost/mpi.hpp&gt;
  #include &lt;iostream&gt;
  #include &lt;cstdlib&gt;
  namespace mpi = boost::mpi;
  
  int main(int argc, char* argv[])
  {
    mpi::environment env(argc, argv);
    mpi::communicator world;
  
    std::srand(time(0) + world.rank());
    int my_number = std::rand();
  
    if (world.rank() == 0) {
      int minimum;
      reduce(world, my_number, minimum, mpi::minimum&lt;int&gt;(), 0);
      std::cout &lt;&lt; "The minimum value is " &lt;&lt; minimum &lt;&lt; std::endl;
    } else {
      reduce(world, my_number, mpi::minimum&lt;int&gt;(), 0);
    }
  
    return 0;
  }
  </code></pre>
  
  <p>In both of these examples we have an if/else conditional as follows:</p>
  
  <pre><code>if(world.rank() == 0){
    //gather or reduce operation
    //Output
  }else{
    //gather or reduce operation
  }
  </code></pre>
  
  <p>What I fail to understand here is the difference between the collective operation in the if vs. whats in the else? There's a difference in the number of parameters but I don't quite understand how the logic works out.</p>
  
  <p>Thanks</p>