Merge branch 'release-4-6' into master
[alexxy/gromacs.git] / src / gromacs / mdlib / domdec.c
index f7b0479d706785a4525e3a8eb535be78b43bf6de..a713fafc3d8f1e3464d9925d3cb28d063e115777 100644 (file)
@@ -2437,6 +2437,8 @@ static void set_zones_ncg_home(gmx_domdec_t *dd)
     {
         zones->cg_range[i] = dd->ncg_home;
     }
+    /* zone_ncg1[0] should always be equal to ncg_home */
+    dd->comm->zone_ncg1[0] = dd->ncg_home;
 }
 
 static void rebuild_cgindex(gmx_domdec_t *dd,
@@ -9159,7 +9161,7 @@ void dd_partition_system(FILE                *fplog,
     t_block           *cgs_gl;
     gmx_large_int_t    step_pcoupl;
     rvec               cell_ns_x0, cell_ns_x1;
-    int                i, j, n, cg0 = 0, ncg_home_old = -1, ncg_moved, nat_f_novirsum;
+    int                i, j, n, ncgindex_set, ncg_home_old = -1, ncg_moved, nat_f_novirsum;
     gmx_bool           bBoxChanged, bNStGlobalComm, bDoDLB, bCheckDLB, bTurnOnDLB, bLogLoad;
     gmx_bool           bRedist, bSortCG, bResortAll;
     ivec               ncells_old = {0, 0, 0}, ncells_new = {0, 0, 0}, np;
@@ -9294,6 +9296,7 @@ void dd_partition_system(FILE                *fplog,
     {
         /* Clear the old state */
         clear_dd_indices(dd, 0, 0);
+        ncgindex_set = 0;
 
         set_ddbox(dd, bMasterState, cr, ir, state_global->box,
                   TRUE, cgs_gl, state_global->x, &ddbox);
@@ -9318,8 +9321,6 @@ void dd_partition_system(FILE                *fplog,
         inc_nrnb(nrnb, eNR_CGCM, dd->nat_home);
 
         dd_set_cginfo(dd->index_gl, 0, dd->ncg_home, fr, comm->bLocalCG);
-
-        cg0 = 0;
     }
     else if (state_local->ddp_count != dd->ddp_count)
     {
@@ -9339,6 +9340,7 @@ void dd_partition_system(FILE                *fplog,
         /* Build the new indices */
         rebuild_cgindex(dd, cgs_gl->index, state_local);
         make_dd_indices(dd, cgs_gl->index, 0);
+        ncgindex_set = dd->ncg_home;
 
         if (fr->cutoff_scheme == ecutsGROUP)
         {
@@ -9362,6 +9364,7 @@ void dd_partition_system(FILE                *fplog,
 
         /* Clear the non-home indices */
         clear_dd_indices(dd, dd->ncg_home, dd->nat_home);
+        ncgindex_set = 0;
 
         /* Avoid global communication for dim's without pbc and -gcom */
         if (!bNStGlobalComm)
@@ -9407,7 +9410,7 @@ void dd_partition_system(FILE                *fplog,
 
         dd_redistribute_cg(fplog, step, dd, ddbox.tric_dir,
                            state_local, f, fr, mdatoms,
-                           !bSortCG, nrnb, &cg0, &ncg_moved);
+                           !bSortCG, nrnb, &ncgindex_set, &ncg_moved);
 
         wallcycle_sub_stop(wcycle, ewcsDD_REDIST);
     }
@@ -9504,8 +9507,8 @@ void dd_partition_system(FILE                *fplog,
         dd_sort_state(dd, ir->ePBC, fr->cg_cm, fr, state_local,
                       bResortAll ? -1 : ncg_home_old);
         /* Rebuild all the indices */
-        cg0 = 0;
         ga2la_clear(dd->ga2la);
+        ncgindex_set = 0;
 
         wallcycle_sub_stop(wcycle, ewcsDD_GRID);
     }
@@ -9516,7 +9519,7 @@ void dd_partition_system(FILE                *fplog,
     setup_dd_communication(dd, state_local->box, &ddbox, fr, state_local, f);
 
     /* Set the indices */
-    make_dd_indices(dd, cgs_gl->index, cg0);
+    make_dd_indices(dd, cgs_gl->index, ncgindex_set);
 
     /* Set the charge group boundaries for neighbor searching */
     set_cg_boundaries(&comm->zones);