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
topology -> legacyheaders
pbcutil -> fileio
pbcutil -> legacyheaders
+listed-forces -> mdlib
/* 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;
#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"
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);
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;
}
#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)
}
//! 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++)
{
{
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)
{
#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 */
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++;
}
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;
}
#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"
#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"
--- /dev/null
+/*
+ * 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
#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"
#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
# 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)
*
* \author Roland Schulz <roland@utk.edu>
* \inlibraryapi
+ * \ingroup module_utility
*/
#ifndef GMX_MDLIB_BITMASK_H
# 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)
* 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