Reduced cost of Berendsen pressure coupling
authorBerk Hess <hess@kth.se>
Mon, 9 Mar 2015 14:47:49 +0000 (15:47 +0100)
committerSzilárd Páll <pall.szilard@gmail.com>
Wed, 11 Mar 2015 00:04:40 +0000 (01:04 +0100)
The coordinate and box scaling for Berendsen pressure coupling is now
done only every nstpcouple steps. It now also uses OpenMP threading.

Partially solves #1694

Change-Id: Id6abbb7f60960076e683707277ebbe5ff8e75453

src/gromacs/mdlib/coupling.cpp
src/gromacs/mdlib/update.cpp

index 8677c2d97075a7d51dcbaf384ddafcfec454cbb2..311ead52fe88fa245d78ba1eaf32d7fb601c658e 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -40,6 +40,7 @@
 
 #include <algorithm>
 
+#include "gromacs/legacyheaders/gmx_omp_nthreads.h"
 #include "gromacs/legacyheaders/macros.h"
 #include "gromacs/legacyheaders/mdrun.h"
 #include "gromacs/legacyheaders/names.h"
@@ -646,12 +647,25 @@ void berendsen_pscale(t_inputrec *ir, matrix mu,
                       t_nrnb *nrnb)
 {
     ivec   *nFreeze = ir->opts.nFreeze;
-    int     n, d, g = 0;
+    int     n, d;
+    int     nthreads gmx_unused;
+
+#ifndef __clang_analyzer__
+    // cppcheck-suppress unreadVariable
+    nthreads = gmx_omp_nthreads_get(emntUpdate);
+#endif
 
     /* Scale the positions */
+#pragma omp parallel for num_threads(nthreads) schedule(static)
     for (n = start; n < start+nr_atoms; n++)
     {
-        if (cFREEZE)
+        int g;
+
+        if (cFREEZE == NULL)
+        {
+            g = 0;
+        }
+        else
         {
             g = cFREEZE[n];
         }
index eab7fb193283abd5011841ce242a11dfd82f5593..d5d18d2ab4e6e53f951774bc34f92167812104a1 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -1778,8 +1778,16 @@ void update_box(FILE             *fplog,
         case (epcNO):
             break;
         case (epcBERENDSEN):
-            berendsen_pscale(inputrec, pcoupl_mu, state->box, state->box_rel,
-                             start, homenr, state->x, md->cFREEZE, nrnb);
+            /* We should only scale after a step where the pressure (kinetic
+             * energy and virial) was calculated. This happens after the
+             * coordinate update, whereas the current routine is called before
+             * that, so we scale when step % nstpcouple = 1 instead of 0.
+             */
+            if (inputrec->nstpcouple == 1 || (step % inputrec->nstpcouple == 1))
+            {
+                berendsen_pscale(inputrec, pcoupl_mu, state->box, state->box_rel,
+                                 start, homenr, state->x, md->cFREEZE, nrnb);
+            }
             break;
         case (epcPARRINELLORAHMAN):
             /* The box velocities were updated in do_pr_pcoupl in the update