Merge remote-tracking branch 'origin/release-4-6'
[alexxy/gromacs.git] / src / gromacs / mdlib / domdec.c
index 5ed15d190d711e31900b2edff53a850774fefc36..97f66bde0722c0974d9f66476e13472ccc9c7308 100644 (file)
@@ -5208,34 +5208,28 @@ static void dd_print_load_verbose(gmx_domdec_t *dd)
 }
 
 #ifdef GMX_MPI
-static void make_load_communicator(gmx_domdec_t *dd,MPI_Group g_all,
-                                   int dim_ind,ivec loc)
+static void make_load_communicator(gmx_domdec_t *dd, int dim_ind,ivec loc)
 {
-    MPI_Group g_row = MPI_GROUP_EMPTY;
     MPI_Comm  c_row;
-    int  dim,i,*rank;
+    int  dim, i, rank;
     ivec loc_c;
     gmx_domdec_root_t *root;
     gmx_bool bPartOfGroup = FALSE;
     
     dim = dd->dim[dim_ind];
     copy_ivec(loc,loc_c);
-    snew(rank,dd->nc[dim]);
     for(i=0; i<dd->nc[dim]; i++)
     {
         loc_c[dim] = i;
-        rank[i] = dd_index(dd->nc,loc_c);
-        if (rank[i] == dd->rank)
+        rank = dd_index(dd->nc,loc_c);
+        if (rank == dd->rank)
         {
             /* This process is part of the group */
             bPartOfGroup = TRUE;
         }
     }
-    if (bPartOfGroup)
-    {
-        MPI_Group_incl(g_all,dd->nc[dim],rank,&g_row);
-    }
-    MPI_Comm_create(dd->mpi_comm_all,g_row,&c_row);
+    MPI_Comm_split(dd->mpi_comm_all, bPartOfGroup?0:MPI_UNDEFINED, dd->rank,
+                   &c_row);
     if (bPartOfGroup)
     {
         dd->comm->mpi_comm_load[dim_ind] = c_row;
@@ -5269,32 +5263,28 @@ static void make_load_communicator(gmx_domdec_t *dd,MPI_Group g_all,
             snew(dd->comm->load[dim_ind].load,dd->nc[dim]*DD_NLOAD_MAX);
         }
     }
-    sfree(rank);
 }
 #endif
 
 static void make_load_communicators(gmx_domdec_t *dd)
 {
 #ifdef GMX_MPI
-  MPI_Group g_all;
   int  dim0,dim1,i,j;
   ivec loc;
 
   if (debug)
     fprintf(debug,"Making load communicators\n");
 
-  MPI_Comm_group(dd->mpi_comm_all,&g_all);
-  
   snew(dd->comm->load,dd->ndim);
   snew(dd->comm->mpi_comm_load,dd->ndim);
   
   clear_ivec(loc);
-  make_load_communicator(dd,g_all,0,loc);
+  make_load_communicator(dd,0,loc);
   if (dd->ndim > 1) {
     dim0 = dd->dim[0];
     for(i=0; i<dd->nc[dim0]; i++) {
       loc[dim0] = i;
-      make_load_communicator(dd,g_all,1,loc);
+      make_load_communicator(dd,1,loc);
     }
   }
   if (dd->ndim > 2) {
@@ -5304,13 +5294,11 @@ static void make_load_communicators(gmx_domdec_t *dd)
       dim1 = dd->dim[1];
       for(j=0; j<dd->nc[dim1]; j++) {
          loc[dim1] = j;
-         make_load_communicator(dd,g_all,2,loc);
+         make_load_communicator(dd,2,loc);
       }
     }
   }
 
-  MPI_Group_free(&g_all);
-
   if (debug)
     fprintf(debug,"Finished making load communicators\n");
 #endif