title: Is creating MPI_Groups at runtime possible?
body: <p>I am trying to create MPI groups based on the number <em>k</em> so in each group we have equal number of processes and the last group takes whatever remains as well. So for example if we have 5 processes and <em>k = 2</em>, we are going to have group_1 = {0,1} and group_2 = {2,3,4}
  The problem is when I start to run my code, it seems that what ever I generate the last overwrites all the previous groups which I have created. I don't know if it's a C++ error or an MPI one. Here is the code:</p>
  <pre><code>        MPI_Group world_group;
          MPI_Comm_group(MPI_COMM_WORLD , &amp;world_group);
      
          int num_groups = k;
          int num_members = numtasks / num_groups;
          int rm_members = numtasks % num_groups;
      
          MPI_Group* groups = new MPI_Group[num_groups]();//Creating MPI groups dynamically
          
          int group_ranks_size[num_groups] = {};
          for(size_t i = 0 ; i &lt; ( num_groups - 1) ; ++i)
              group_ranks_size[i] = num_members;
          group_ranks_size[num_groups - 1] = num_members + rm_members;
          
          int** group_ranks = new int*[num_groups];
          for(size_t i = 0 ; i &lt; num_groups ; ++i){
              group_ranks[i] = new int[group_ranks_size[i]]();
          }
      
          int id_counter = 0;
          for(size_t i = 0 ; i &lt; num_groups ; ++i){
              for(size_t j = 0 ; j &lt; group_ranks_size[i] ; ++j){
                  group_ranks[i][j] = id_counter;
                  id_counter++;
              }
          }
      
          //Printing to check
          if(rank == 0){
              for(size_t i = 0 ; i &lt; k ; ++i)
                  cout&lt;&lt;group_ranks_size[i]&lt;&lt;endl;
      
              for(size_t i = 0 ; i &lt; num_groups ; ++i){
                  for(size_t j = 0 ; j &lt; group_ranks_size[i] ; ++j){
                      cout&lt;&lt;group_ranks[i][j]&lt;&lt;&quot;,&quot;;
                  }
                  cout&lt;&lt;endl;
              }
          }   
          //***
          
          for(size_t i = 0 ; i &lt; num_groups ; ++i){
      
              MPI_Group_incl(world_group , group_ranks_size[i] , group_ranks[i] , (groups+i));
      
          }
      
          // Get my rank in the small group
          int my_small_group_rank;
          for(size_t i = 0 ; i &lt; num_groups ; ++i){
              MPI_Group_rank(groups[i], &amp;my_small_group_rank);
          }
      
      
          if(my_small_group_rank != MPI_UNDEFINED)
          {
              printf(&quot;I am process %d in world group and %d in small group.\n&quot;, rank, my_small_group_rank);
          }
          else
          {
              printf(&quot;I am process %d in world group but I am not part of the small group.\n&quot;, rank);
          }
  
  </code></pre>