Stop timers in GpuForceReduction with no atoms
authorAndrey Alekseenko <al42and@gmail.com>
Tue, 12 Oct 2021 12:55:37 +0000 (14:55 +0200)
committerAndrey Alekseenko <al42and@gmail.com>
Tue, 12 Oct 2021 12:55:37 +0000 (14:55 +0200)
The early return, as implemented earlier, was happening after starting
the timers. Now we properly stop them.

The large "if" was used here instead of just moving the "return" up in
order to accomodate future manual event handling (see Issue #3988 and MR
!2015).

Thanks to Artem Zhmurov for noticing the problem.

src/gromacs/mdlib/gpuforcereduction_impl.cpp

index fb9ab131bd91f18645c6e506e0fb5edcb338c68e..2a3e48c4ad5afeb75ffaef6537130904bdb1bb31 100644 (file)
@@ -118,35 +118,33 @@ void GpuForceReduction::Impl::execute()
     wallcycle_start_nocount(wcycle_, WallCycleCounter::LaunchGpu);
     wallcycle_sub_start(wcycle_, WallCycleSubCounter::LaunchGpuNBFBufOps);
 
-    if (numAtoms_ == 0)
+    if (numAtoms_ != 0)
     {
-        return;
-    }
-
-    GMX_ASSERT(nbnxmForceToAdd_, "Nbnxm force for reduction has no data");
-
-    // Enqueue wait on all dependencies passed
-    for (auto* synchronizer : dependencyList_)
-    {
-        synchronizer->enqueueWaitEvent(deviceStream_);
-    }
-
-    const bool addRvecForce = static_cast<bool>(rvecForceToAdd_); // True iff initialized
-
-    launchForceReductionKernel(numAtoms_,
-                               atomStart_,
-                               addRvecForce,
-                               accumulate_,
-                               nbnxmForceToAdd_,
-                               rvecForceToAdd_,
-                               baseForce_,
-                               cellInfo_.d_cell,
-                               deviceStream_);
-
-    // Mark that kernel has been launched
-    if (completionMarker_ != nullptr)
-    {
-        completionMarker_->markEvent(deviceStream_);
+        GMX_ASSERT(nbnxmForceToAdd_, "Nbnxm force for reduction has no data");
+
+        // Enqueue wait on all dependencies passed
+        for (auto* synchronizer : dependencyList_)
+        {
+            synchronizer->enqueueWaitEvent(deviceStream_);
+        }
+
+        const bool addRvecForce = static_cast<bool>(rvecForceToAdd_); // True iff initialized
+
+        launchForceReductionKernel(numAtoms_,
+                                   atomStart_,
+                                   addRvecForce,
+                                   accumulate_,
+                                   nbnxmForceToAdd_,
+                                   rvecForceToAdd_,
+                                   baseForce_,
+                                   cellInfo_.d_cell,
+                                   deviceStream_);
+
+        // Mark that kernel has been launched
+        if (completionMarker_ != nullptr)
+        {
+            completionMarker_->markEvent(deviceStream_);
+        }
     }
 
     wallcycle_sub_stop(wcycle_, WallCycleSubCounter::LaunchGpuNBFBufOps);