960f5f96791dbf4e2a529672a28b1b779f6524a9
[alexxy/gromacs.git] / src / gromacs / nbnxm / pairlistsets.h
1 /*
2  * This file is part of the GROMACS molecular simulation package.
3  *
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.
8  *
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.
13  *
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.
18  *
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.
23  *
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.
31  *
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.
34  */
35
36 /*! \internal \file
37  *
38  * \brief
39  * Declares the PairlistSets class
40  *
41  * This class holds the local and non-local pairlist sets.
42  *
43  * \author Berk Hess <hess@kth.se>
44  * \ingroup module_nbnxm
45  */
46
47 #ifndef GMX_NBNXM_PAIRLISTSETS_H
48 #define GMX_NBNXM_PAIRLISTSETS_H
49
50 #include <memory>
51
52 #include "gromacs/mdtypes/locality.h"
53
54 #include "pairlistparams.h"
55
56 struct nbnxn_atomdata_t;
57 class PairlistSet;
58 enum class PairlistType;
59 class PairSearch;
60 struct t_nrnb;
61
62 namespace gmx
63 {
64 template<typename>
65 class ListOfLists;
66 }
67
68 class PairlistSets
69 {
70 public:
71     PairlistSets(const PairlistParams& pairlistParams,
72                  bool                  haveMultipleDomains,
73                  int                   minimumIlistCountForGpuBalancing);
74
75     //! Construct the pairlist set for the given locality
76     void construct(gmx::InteractionLocality     iLocality,
77                    PairSearch*                  pairSearch,
78                    nbnxn_atomdata_t*            nbat,
79                    const gmx::ListOfLists<int>& exclusions,
80                    int64_t                      step,
81                    t_nrnb*                      nrnb);
82
83     //! Dispatches the dynamic pruning kernel for the given locality
84     void dispatchPruneKernel(gmx::InteractionLocality iLocality,
85                              const nbnxn_atomdata_t*  nbat,
86                              const rvec*              shift_vec);
87
88     //! Returns the pair list parameters
89     const PairlistParams& params() const { return params_; }
90
91     //! Returns the number of steps performed with the current pair list
92     int numStepsWithPairlist(int64_t step) const
93     {
94         return static_cast<int>(step - outerListCreationStep_);
95     }
96
97     //! Returns whether step is a dynamic list pruning step, for CPU lists
98     bool isDynamicPruningStepCpu(int64_t step) const
99     {
100         return (params_.useDynamicPruning && numStepsWithPairlist(step) % params_.nstlistPrune == 0);
101     }
102
103     //! Returns whether step is a dynamic list pruning step, for GPU lists
104     bool isDynamicPruningStepGpu(int64_t step) const
105     {
106         const int age = numStepsWithPairlist(step);
107
108         return (params_.useDynamicPruning && age > 0 && age < params_.lifetime
109                 && (params_.haveMultipleDomains || age % 2 == 0));
110     }
111
112     //! Changes the pair-list outer and inner radius
113     void changePairlistRadii(real rlistOuter, real rlistInner)
114     {
115         params_.rlistOuter = rlistOuter;
116         params_.rlistInner = rlistInner;
117     }
118
119     //! Returns the pair-list set for the given locality
120     const PairlistSet& pairlistSet(gmx::InteractionLocality iLocality) const
121     {
122         if (iLocality == gmx::InteractionLocality::Local)
123         {
124             return *localSet_;
125         }
126         else
127         {
128             GMX_ASSERT(nonlocalSet_, "Need a non-local set when requesting access");
129             return *nonlocalSet_;
130         }
131     }
132
133 private:
134     //! Returns the pair-list set for the given locality
135     PairlistSet& pairlistSet(gmx::InteractionLocality iLocality)
136     {
137         if (iLocality == gmx::InteractionLocality::Local)
138         {
139             return *localSet_;
140         }
141         else
142         {
143             GMX_ASSERT(nonlocalSet_, "Need a non-local set when requesting access");
144             return *nonlocalSet_;
145         }
146     }
147
148     //! Parameters for the search and list pruning setup
149     PairlistParams params_;
150     //! Pair list balancing parameter for use with GPU
151     int minimumIlistCountForGpuBalancing_;
152     //! Local pairlist set
153     std::unique_ptr<PairlistSet> localSet_;
154     //! Non-local pairlist set
155     std::unique_ptr<PairlistSet> nonlocalSet_;
156     //! MD step at with the outer lists in pairlistSets_ were created
157     int64_t outerListCreationStep_;
158 };
159
160 #endif