Introduce SimulatorBuilder
[gromacs.git] / src / gromacs / nbnxm / pairlistsets.h
blob41e8dc25b50465102a88c8724a099867ffc598b7
1 /*
2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2012,2013,2014,2015,2017,2018,2019, by the GROMACS development team, led by
5 * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
6 * and including many others, as listed in the AUTHORS file in the
7 * top-level source directory and at http://www.gromacs.org.
9 * GROMACS is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public License
11 * as published by the Free Software Foundation; either version 2.1
12 * of the License, or (at your option) any later version.
14 * GROMACS is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with GROMACS; if not, see
21 * http://www.gnu.org/licenses, or write to the Free Software Foundation,
22 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 * If you want to redistribute modifications to GROMACS, please
25 * consider that scientific software is very special. Version
26 * control is crucial - bugs must be traceable. We will be happy to
27 * consider code for inclusion in the official distribution, but
28 * derived work must not be called official GROMACS. Details are found
29 * in the README & COPYING files - if they are missing, get the
30 * official version at http://www.gromacs.org.
32 * To help us fund GROMACS development, we humbly ask that you cite
33 * the research papers on the package. Check out http://www.gromacs.org.
36 /*! \internal \file
38 * \brief
39 * Declares the PairlistSets class
41 * This class holds the local and non-local pairlist sets.
43 * \author Berk Hess <hess@kth.se>
44 * \ingroup module_nbnxm
47 #ifndef GMX_NBNXM_PAIRLISTSETS_H
48 #define GMX_NBNXM_PAIRLISTSETS_H
50 #include <memory>
52 #include "locality.h"
53 #include "pairlistparams.h"
55 struct nbnxn_atomdata_t;
56 class PairlistSet;
57 enum class PairlistType;
58 class PairSearch;
59 struct t_blocka;
60 struct t_nrnb;
63 class PairlistSets
65 public:
66 PairlistSets(const PairlistParams &pairlistParams,
67 bool haveMultipleDomains,
68 int minimumIlistCountForGpuBalancing);
70 //! Construct the pairlist set for the given locality
71 void construct(Nbnxm::InteractionLocality iLocality,
72 PairSearch *pairSearch,
73 nbnxn_atomdata_t *nbat,
74 const t_blocka *excl,
75 int64_t step,
76 t_nrnb *nrnb);
78 //! Dispatches the dynamic pruning kernel for the given locality
79 void dispatchPruneKernel(Nbnxm::InteractionLocality iLocality,
80 const nbnxn_atomdata_t *nbat,
81 const rvec *shift_vec);
83 //! Returns the pair list parameters
84 const PairlistParams &params() const
86 return params_;
89 //! Returns the number of steps performed with the current pair list
90 int numStepsWithPairlist(int64_t step) const
92 return step - outerListCreationStep_;
95 //! Returns whether step is a dynamic list pruning step, for CPU lists
96 bool isDynamicPruningStepCpu(int64_t step) const
98 return (params_.useDynamicPruning &&
99 numStepsWithPairlist(step) % params_.nstlistPrune == 0);
102 //! Returns whether step is a dynamic list pruning step, for GPU lists
103 bool isDynamicPruningStepGpu(int64_t step) const
105 const int age = numStepsWithPairlist(step);
107 return (params_.useDynamicPruning &&
108 age > 0 &&
109 age < params_.lifetime &&
110 (params_.haveMultipleDomains || age % 2 == 0));
113 //! Changes the pair-list outer and inner radius
114 void changePairlistRadii(real rlistOuter,
115 real rlistInner)
117 params_.rlistOuter = rlistOuter;
118 params_.rlistInner = rlistInner;
121 //! Returns the pair-list set for the given locality
122 const PairlistSet &pairlistSet(Nbnxm::InteractionLocality iLocality) const
124 if (iLocality == Nbnxm::InteractionLocality::Local)
126 return *localSet_;
128 else
130 GMX_ASSERT(nonlocalSet_, "Need a non-local set when requesting access");
131 return *nonlocalSet_;
135 private:
136 //! Returns the pair-list set for the given locality
137 PairlistSet &pairlistSet(Nbnxm::InteractionLocality iLocality)
139 if (iLocality == Nbnxm::InteractionLocality::Local)
141 return *localSet_;
143 else
145 GMX_ASSERT(nonlocalSet_, "Need a non-local set when requesting access");
146 return *nonlocalSet_;
150 //! Parameters for the search and list pruning setup
151 PairlistParams params_;
152 //! Pair list balancing parameter for use with GPU
153 int minimumIlistCountForGpuBalancing_;
154 //! Local pairlist set
155 std::unique_ptr<PairlistSet> localSet_;
156 //! Non-local pairlist set
157 std::unique_ptr<PairlistSet> nonlocalSet_;
158 //! MD step at with the outer lists in pairlistSets_ were created
159 int64_t outerListCreationStep_;
162 #endif