Use bitmask for bonded
authorRoland Schulz <roland@utk.edu>
Wed, 26 Nov 2014 01:40:30 +0000 (20:40 -0500)
committerGerrit Code Review <gerrit@gerrit.gromacs.org>
Sat, 13 Dec 2014 20:54:56 +0000 (21:54 +0100)
Also move bitmask to utility and f_thread_t to forcerec-threading.h.
This introduces a cycle because listed-forces now depends on
mdlib/forcerec-threading.h. There is not yet a module where
forcerec-threading.h can go.

Change-Id: Ic220be2880f7263aa0e50b13f07ed509eb86e1b3

16 files changed:
docs/doxygen/cycle-suppressions.txt
src/gromacs/legacyheaders/types/forcerec.h
src/gromacs/listed-forces/listed-forces.cpp
src/gromacs/listed-forces/manage-threading.cpp
src/gromacs/mdlib/clincs.cpp
src/gromacs/mdlib/force.cpp
src/gromacs/mdlib/forcerec-threading.h [new file with mode: 0644]
src/gromacs/mdlib/forcerec.cpp
src/gromacs/mdlib/nbnxn_pairlist.h
src/gromacs/mdlib/tests/CMakeLists.txt
src/gromacs/utility/bitmask.h [moved from src/gromacs/mdlib/bitmask.h with 99% similarity]
src/gromacs/utility/tests/CMakeLists.txt
src/gromacs/utility/tests/bitmask.h [moved from src/gromacs/mdlib/tests/bitmask.h with 98% similarity]
src/gromacs/utility/tests/bitmask128.cpp [moved from src/gromacs/mdlib/tests/bitmask128.cpp with 100% similarity]
src/gromacs/utility/tests/bitmask32.cpp [moved from src/gromacs/mdlib/tests/bitmask32.cpp with 100% similarity]
src/gromacs/utility/tests/bitmask64.cpp [moved from src/gromacs/mdlib/tests/bitmask64.cpp with 100% similarity]

index eae10369dc45b52aa19125dbcf4ef888c41bdca9..38023f9f2dd75854eea2ef0b13b659c5fc7f045a 100644 (file)
@@ -19,3 +19,4 @@ topology -> fileio
 topology -> legacyheaders
 pbcutil -> fileio
 pbcutil -> legacyheaders
+listed-forces -> mdlib
index 59cd9f4279d61196597b5d97cccad70202711039..49f32af748a5fc8812fbf94992fbb0ccb36ec900 100644 (file)
@@ -185,19 +185,7 @@ typedef struct {
 /* Forward declaration of type for managing Ewald tables */
 struct gmx_ewald_tab_t;
 
-typedef struct {
-    rvec             *f;
-    int               f_nalloc;
-    unsigned          red_mask; /* Mask for marking which parts of f are filled */
-    rvec             *fshift;
-    real              ener[F_NRE];
-    gmx_grppairener_t grpp;
-    real              Vcorr_q;
-    real              Vcorr_lj;
-    real              dvdl[efptNR];
-    tensor            vir_q;
-    tensor            vir_lj;
-} f_thread_t;
+typedef struct f_thread_t f_thread_t;
 
 typedef struct {
     interaction_const_t *ic;
index fd46c3519cd8d9dc6c262c0ccfd68970be27cb48..e23f348065e279059330ce70ccdcabe13e570152 100644 (file)
@@ -60,6 +60,7 @@
 #include "gromacs/listed-forces/bonded.h"
 #include "gromacs/listed-forces/position-restraints.h"
 #include "gromacs/math/vec.h"
+#include "gromacs/mdlib/forcerec-threading.h"
 #include "gromacs/pbcutil/ishift.h"
 #include "gromacs/pbcutil/pbc.h"
 #include "gromacs/timing/wallcycle.h"
@@ -92,11 +93,11 @@ zero_thread_forces(f_thread_t *f_t, int n,
         srenew(f_t->f, f_t->f_nalloc);
     }
 
-    if (f_t->red_mask != 0)
+    if (!bitmask_is_zero(f_t->red_mask))
     {
         for (b = 0; b < nblock; b++)
         {
-            if (f_t->red_mask && (1U<<b))
+            if (bitmask_is_set(f_t->red_mask, b))
             {
                 a0 = b*blocksize;
                 a1 = std::min((b+1)*blocksize, n);
@@ -161,7 +162,7 @@ reduce_thread_force_buffer(int n, rvec *f,
         nfb = 0;
         for (ft = 1; ft < nthreads; ft++)
         {
-            if (f_t[ft].red_mask & (1U<<b))
+            if (bitmask_is_set(f_t[ft].red_mask, b))
             {
                 fp[nfb++] = f_t[ft].f;
             }
index 3c10bdef1c7d0b2fe665911f7888c242d380f48a..c63110e33c0097eb74a47ecf26a18299a6885eb2 100644 (file)
 #include <algorithm>
 
 #include "gromacs/listed-forces/bonded.h"
+#include "gromacs/mdlib/forcerec-threading.h"
 #include "gromacs/utility/fatalerror.h"
 #include "gromacs/utility/smalloc.h"
+#include "gromacs/utility/stringutil.h"
 
 //! Divides listed interactions over threads
 static void divide_bondeds_over_threads(t_idef *idef, int nthreads)
@@ -110,15 +112,14 @@ static void divide_bondeds_over_threads(t_idef *idef, int nthreads)
 }
 
 //! Construct a reduction mask for which interaction was computed on which thread
-static unsigned
-calc_bonded_reduction_mask(const t_idef *idef,
+static void
+calc_bonded_reduction_mask(gmx_bitmask_t *mask,
+                           const t_idef *idef,
                            int shift,
                            int t, int nt)
 {
-    unsigned mask;
-    int      ftype, nb, nat1, nb0, nb1, i, a;
-
-    mask = 0;
+    int           ftype, nb, nat1, nb0, nb1, i, a;
+    bitmask_clear(mask);
 
     for (ftype = 0; ftype < F_NRE; ftype++)
     {
@@ -139,21 +140,19 @@ calc_bonded_reduction_mask(const t_idef *idef,
                 {
                     for (a = 1; a < nat1; a++)
                     {
-                        mask |= (1U << (idef->il[ftype].iatoms[i+a]>>shift));
+                        bitmask_set_bit(mask, idef->il[ftype].iatoms[i+a]>>shift);
                     }
                 }
             }
         }
     }
-
-    return mask;
 }
 
 
-/*! \brief We divide the force array in a maximum of 32 blocks.
+/*! \brief We divide the force array in a maximum of BITMASK_SIZE (default 32) blocks.
  * Minimum force block reduction size is thus 2^6=64.
  */
-const int maxBlockBits = 32;
+const int maxBlockBits = BITMASK_SIZE;
 
 void setup_bonded_threading(t_forcerec   *fr, t_idef *idef)
 {
@@ -189,8 +188,8 @@ void setup_bonded_threading(t_forcerec   *fr, t_idef *idef)
 #pragma omp parallel for num_threads(fr->nthreads) schedule(static)
     for (t = 1; t < fr->nthreads; t++)
     {
-        fr->f_t[t].red_mask =
-            calc_bonded_reduction_mask(idef, fr->red_ashift, t, fr->nthreads);
+        calc_bonded_reduction_mask(&fr->f_t[t].red_mask,
+                                   idef, fr->red_ashift, t, fr->nthreads);
     }
 
     /* Determine the maximum number of blocks we need to reduce over */
@@ -201,7 +200,7 @@ void setup_bonded_threading(t_forcerec   *fr, t_idef *idef)
         c = 0;
         for (b = 0; b < maxBlockBits; b++)
         {
-            if (fr->f_t[t].red_mask & (1U<<b))
+            if (bitmask_is_set(fr->f_t[t].red_mask, b))
             {
                 fr->red_nblock = std::max(fr->red_nblock, b+1);
                 c++;
@@ -209,8 +208,15 @@ void setup_bonded_threading(t_forcerec   *fr, t_idef *idef)
         }
         if (debug)
         {
-            fprintf(debug, "thread %d flags %x count %d\n",
-                    t, fr->f_t[t].red_mask, c);
+#if BITMASK_SIZE <= 64 //move into bitmask when it is C++
+            std::string flags = gmx::formatString("%x", fr->f_t[t].red_mask);
+#else
+            std::string flags = gmx::formatAndJoin(fr->f_t[t].red_mask,
+                                                   fr->f_t[t].red_mask+BITMASK_ALEN,
+                                                   "", gmx::StringFormatter("%x"));
+#endif
+            fprintf(debug, "thread %d flags %s count %d\n",
+                    t, flags.c_str(), c);
         }
         ctot += c;
     }
index aa4e633f77e0729350f3b990760068ca7f8bafa8..480a96596d841b2b1afcb99627f738aa78b843ab 100644 (file)
 #include "gromacs/legacyheaders/types/commrec.h"
 #include "gromacs/math/units.h"
 #include "gromacs/math/vec.h"
-#include "gromacs/mdlib/bitmask.h"
 #include "gromacs/pbcutil/pbc.h"
 #include "gromacs/topology/block.h"
 #include "gromacs/topology/mtop_util.h"
+#include "gromacs/utility/bitmask.h"
 #include "gromacs/utility/fatalerror.h"
 #include "gromacs/utility/gmxomp.h"
 #include "gromacs/utility/smalloc.h"
index 16393693189644140e2fab7f46aa16feb3e6efef..6eab0bb0b0c614e9d82ecc5ed1843d1de2ecd462 100644 (file)
@@ -62,6 +62,7 @@
 #include "gromacs/legacyheaders/types/commrec.h"
 #include "gromacs/listed-forces/listed-forces.h"
 #include "gromacs/math/vec.h"
+#include "gromacs/mdlib/forcerec-threading.h"
 #include "gromacs/pbcutil/ishift.h"
 #include "gromacs/pbcutil/mshift.h"
 #include "gromacs/pbcutil/pbc.h"
diff --git a/src/gromacs/mdlib/forcerec-threading.h b/src/gromacs/mdlib/forcerec-threading.h
new file mode 100644 (file)
index 0000000..b40a18b
--- /dev/null
@@ -0,0 +1,63 @@
+/*
+ * This file is part of the GROMACS molecular simulation package.
+ *
+ * Copyright (c) 2014, 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.
+ *
+ * GROMACS is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1
+ * of the License, or (at your option) any later version.
+ *
+ * GROMACS is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with GROMACS; if not, see
+ * http://www.gnu.org/licenses, or write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
+ *
+ * If you want to redistribute modifications to GROMACS, please
+ * consider that scientific software is very special. Version
+ * control is crucial - bugs must be traceable. We will be happy to
+ * consider code for inclusion in the official distribution, but
+ * derived work must not be called official GROMACS. Details are found
+ * in the README & COPYING files - if they are missing, get the
+ * official version at http://www.gromacs.org.
+ *
+ * To help us fund GROMACS development, we humbly ask that you cite
+ * the research papers on the package. Check out http://www.gromacs.org.
+ */
+
+#ifndef GMX_MDLIB_FORCEREC_THREADING_H
+#define GMX_MDLIB_FORCEREC_THREADING_H
+
+#include "gromacs/utility/bitmask.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct f_thread_t {
+    rvec             *f;
+    int               f_nalloc;
+    gmx_bitmask_t     red_mask; /* Mask for marking which parts of f are filled */
+    rvec             *fshift;
+    real              ener[F_NRE];
+    gmx_grppairener_t grpp;
+    real              Vcorr_q;
+    real              Vcorr_lj;
+    real              dvdl[efptNR];
+    tensor            vir_q;
+    tensor            vir_lj;
+};
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
index 611642825deb39a849dbcd7d76e78e16c1f95c69..d3bb4be6f68aca0d95ae4d5ef5fa0bf20c928510 100644 (file)
@@ -68,6 +68,7 @@
 #include "gromacs/math/units.h"
 #include "gromacs/math/utilities.h"
 #include "gromacs/math/vec.h"
+#include "gromacs/mdlib/forcerec-threading.h"
 #include "gromacs/mdlib/nb_verlet.h"
 #include "gromacs/mdlib/nbnxn_atomdata.h"
 #include "gromacs/mdlib/nbnxn_consts.h"
index 09d429a27d79ce456d69d0933ff5a038f3ec941d..09163178a358aa1f5e7bc2cab50cf0763c35069b 100644 (file)
@@ -42,8 +42,8 @@
 
 #include "gromacs/legacyheaders/types/nblist.h"
 #include "gromacs/math/vectypes.h"
-#include "gromacs/mdlib/bitmask.h"
 #include "gromacs/utility/basedefinitions.h"
+#include "gromacs/utility/bitmask.h"
 #include "gromacs/utility/real.h"
 
 #ifdef __cplusplus
index 4e00c4717a73bacb83df607ed6336962ee933538..ba2e72945a60941d5ad52d749b3d808ad32e4501 100644 (file)
@@ -33,5 +33,4 @@
 # the research papers on the package. Check out http://www.gromacs.org.
 
 gmx_add_unit_test(MdlibUnitTest mdlib-test
-                  bitmask32.cpp bitmask64.cpp bitmask128.cpp
                   shake.cpp)
similarity index 99%
rename from src/gromacs/mdlib/bitmask.h
rename to src/gromacs/utility/bitmask.h
index 4b9c812513327131e896e6212e6af33f1f82a29a..e1c5989669a2da26393bcaddcd936475a0a40a5c 100644 (file)
@@ -38,6 +38,7 @@
  *
  * \author Roland Schulz <roland@utk.edu>
  * \inlibraryapi
+ * \ingroup module_utility
  */
 
 #ifndef GMX_MDLIB_BITMASK_H
index 49c752b85754a07da183634c918a999619783aca..9024e56ea608d12acd0320e8af4243ba0b88c705 100644 (file)
@@ -33,4 +33,5 @@
 # the research papers on the package. Check out http://www.gromacs.org.
 
 gmx_add_unit_test(UtilityUnitTests utility-test
+                  bitmask32.cpp bitmask64.cpp bitmask128.cpp
                   stringutil.cpp)
similarity index 98%
rename from src/gromacs/mdlib/tests/bitmask.h
rename to src/gromacs/utility/tests/bitmask.h
index 7041c770c25c7c06bc63863cd4d66141e3e1a81e..3cc5376b1f1f410d74a8e4b4af0651e7e80b6796 100644 (file)
  * These tests check the functionality of bitmask.h
 
  * \author Roland Schulz <roland@rschulz.eu>
+ * \ingroup module_utility
  */
 #include <gtest/gtest.h>
 
-#include "gromacs/mdlib/bitmask.h"
+#include "gromacs/utility/bitmask.h"
 
 //! Implemenation of BITMASK_CLASSNAME
 #define BITMASK_CLASSNAME_(S) BitmaskTest ## S