fixed DD internal state corruption with energy minimization
authorBerk Hess <hess@kth.se>
Mon, 3 Jun 2013 18:56:19 +0000 (20:56 +0200)
committerGerrit Code Review <gerrit@gerrit.gromacs.org>
Wed, 5 Jun 2013 13:58:19 +0000 (15:58 +0200)
With energy minimization we need to reload old DD states after
steps are rejected. There were two bookkeeping issues in the reload.
This could lead to all kinds of, but no silent, errors.
Fixes #1272

Change-Id: Ia44c3bad27f3efdee76fa93dd281690e44dde700

src/mdlib/domdec.c

index ad5097d853240e2056be34f10daeef417b40cd70..2472a37ac9806595c838fef0b2876552bf45a129 100644 (file)
@@ -2459,6 +2459,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,
@@ -9181,7 +9183,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;
@@ -9316,6 +9318,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);
@@ -9340,8 +9343,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)
     {
@@ -9361,6 +9362,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)
         {
@@ -9384,6 +9386,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)
@@ -9429,7 +9432,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);
     }
@@ -9526,8 +9529,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);
     }
@@ -9538,7 +9541,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);