Move responsibility for GPU force clearing to state propagator
[alexxy/gromacs.git] / src / gromacs / mdlib / sim_util.cpp
index 80190c6fa833da33d9c76e441485df290658d8c2..1db242af88b3374ced1cfadf2cc88826764b1df7 100644 (file)
@@ -2039,7 +2039,15 @@ void do_force(FILE*                               fplog,
 
             if (stepWork.useGpuFHalo)
             {
-                communicateGpuHaloForces(*cr, domainWork.haveCpuLocalForceWork);
+                // If there exist CPU forces, data from halo exchange should accumulate into these
+                bool accumulateForces = domainWork.haveCpuLocalForceWork;
+                if (!accumulateForces)
+                {
+                    // Force halo exchange will set a subset of local atoms with remote non-local data
+                    // First clear local portion of force array, so that untouched atoms are zero
+                    stateGpu->clearForcesOnGpu(AtomLocality::Local);
+                }
+                communicateGpuHaloForces(*cr, accumulateForces);
             }
             else
             {