Merge branch 'release-2019' into master
[alexxy/gromacs.git] / src / gromacs / domdec / partition.cpp
index 83ffe74855a82633455142c29b360b8769ce0134..d2764efd62f3497826aa2de90bd72f79279f44c7 100644 (file)
@@ -2709,8 +2709,11 @@ static void dd_sort_order(const gmx_domdec_t *dd,
 
     const int  movedValue = NSGRID_SIGNAL_MOVED_FAC*fr->ns->grid->ncells;
 
-    if (ncg_home_old >= 0)
+    if (ncg_home_old >= 0 && !sort->sorted.empty())
     {
+        GMX_RELEASE_ASSERT(sort->sorted.size() == static_cast<size_t>(ncg_home_old),
+                           "The sorting buffer should contain the old home charge group indices");
+
         std::vector<gmx_cgsort_t> &stationary = sort->stationary;
         std::vector<gmx_cgsort_t> &moved      = sort->moved;
 
@@ -3466,6 +3469,16 @@ void dd_partition_system(FILE                    *fplog,
 
         wallcycle_sub_stop(wcycle, ewcsDD_GRID);
     }
+    else
+    {
+        /* With the group scheme the sorting array is part of the DD state,
+         * but it just got out of sync, so mark as invalid by emptying it.
+         */
+        if (ir->cutoff_scheme == ecutsGROUP)
+        {
+            comm->sort->sorted.clear();
+        }
+    }
 
     if (comm->useUpdateGroups)
     {