title: How to use MPI_Reduce to Sum different values from Different groups of processors independently
body: <p>I am trying to divide my processors into groups then add the summation of each group 
  independently ... but I couldn't find the result correctly until now.
  a simple example is as follows:</p>
  
  <pre><code>int main(int argc, char** argv) 
  {
      int size, rank,i=0,localsum1=0,globalsum1=0,localsum2=0,globalsum2=0;
  
      MPI_Init(&amp;argc,&amp;argv);
      MPI_Comm_size(MPI_COMM_WORLD,&amp;size);
      MPI_Comm_rank(MPI_COMM_WORLD,&amp;rank);
  
      if(rank==0)
      {
      }
      else if(rank==1)
      {
          localsum1 += 5;
          MPI_Reduce(&amp;localsum1,&amp;globalsum1,2,MPI_INT,MPI_SUM,0,MPI_COMM_WORLD);
      }
      else if(rank==2)
      {
          localsum2 += 10;
          MPI_Reduce(&amp;localsum2,&amp;globalsum2,2,MPI_INT,MPI_SUM,0,MPI_COMM_WORLD);
      }
  
      if(rank==0)
      {
          printf("globalsum1 = %d \n",globalsum1);
          printf("globalsum2 = %d \n",globalsum2);
      }
      MPI_Finalize();
  
      return (EXIT_SUCCESS);
  }
  </code></pre>
  
  <p>I can't figure out what is missing here ... can anyone help?</p>