2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2012,2013,2014,2015,2016,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.
38 * \brief Declares the PairSearch class and helper structs
40 * The PairSearch class holds the domain setup, the search grids
41 * and helper object for the pair search. It manages the search work.
42 * The actual gridding and pairlist generation is performeed by the
43 * GridSet/Grid and PairlistSet/Pairlist classes, respectively.
45 * \author Berk Hess <hess@kth.se>
47 * \ingroup module_nbnxm
50 #ifndef GMX_NBNXM_PAIRSEARCH_H
51 #define GMX_NBNXM_PAIRSEARCH_H
56 #include "gromacs/domdec/domdec.h"
57 #include "gromacs/math/vectypes.h"
58 #include "gromacs/nbnxm/atomdata.h"
59 #include "gromacs/nbnxm/pairlist.h"
60 #include "gromacs/timing/cyclecounter.h"
61 #include "gromacs/utility/alignedallocator.h"
62 #include "gromacs/utility/arrayref.h"
63 #include "gromacs/utility/real.h"
67 struct gmx_domdec_zones_t;
70 /*! \brief Convenience declaration for an std::vector with aligned memory */
72 using AlignedVector = std::vector < T, gmx::AlignedAllocator < T>>;
75 /* Local cycle count struct for profiling */
81 start_ = gmx_cycles_read();
86 cycles_ += gmx_cycles_read() - start_;
95 double averageMCycles() const
99 return static_cast<double>(cycles_)*1e-6/count_;
109 gmx_cycles_t cycles_ = 0;
110 gmx_cycles_t start_ = 0;
113 // TODO: Move nbnxn_search_work_t definition to its own file
115 /* Thread-local work struct, contains working data for Grid */
116 struct PairsearchWork
122 gmx_cache_protect_t cp0; /* Buffer to avoid cache polution */
124 std::vector<int> sortBuffer; /* Temporary buffer for sorting atoms within a grid column */
126 nbnxn_buffer_flags_t buffer_flags; /* Flags for force buffer access */
128 int ndistc; /* Number of distance checks for flop counting */
131 std::unique_ptr<t_nblist> nbl_fep; /* Temporary FEP list for load balancing */
133 nbnxn_cycle_t cycleCounter; /* Counter for thread-local cycles */
135 gmx_cache_protect_t cp1; /* Buffer to avoid cache polution */
138 /* Main pair-search struct, contains the grid(s), not the pair-list(s) */
143 * \brief Description of the domain setup: PBC and the connections between domains
148 * \brief Description of the domain setup: PBC and the connections between domains
150 //! Constructor, without DD \p numDDCells and \p ddZones should be nullptr
151 DomainSetup(int ePBC,
152 const ivec *numDDCells,
153 const gmx_domdec_zones_t *ddZones);
157 //! Tells whether we are using domain decomposition
159 //! Tells whether we are using domain decomposition per dimension
160 std::array<bool, DIM> haveDomDecPerDim;
161 //! The domain decomposition zone setup
162 const gmx_domdec_zones_t *zones;
165 //! Local cycle count enum for profiling different parts of search
167 enbsCCgrid, enbsCCsearch, enbsCCcombine, enbsCCnr
170 struct SearchCycleCounting
172 //! Start a pair search cycle counter
173 void start(const int enbsCC)
178 //! Stop a pair search cycle counter
179 void stop(const int enbsCC)
184 //! Print the cycle counts to \p fp
185 void printCycles(FILE *fp,
186 gmx::ArrayRef<const PairsearchWork> work) const;
188 bool recordCycles_ = false;
189 int searchCount_ = 0;
190 nbnxn_cycle_t cc_[enbsCCnr];
193 //! Puts the atoms in \p ddZone on the grid and copies the coordinates to \p nbat
194 void putOnGrid(const matrix box,
196 const rvec lowerCorner,
197 const rvec upperCorner,
198 const gmx::UpdateGroupsCog *updateGroupsCog,
203 gmx::ArrayRef<const gmx::RVec> x,
206 nbnxn_atomdata_t *nbat)
208 cycleCounting_.start(enbsCCgrid);
210 gridSet_.putOnGrid(box, ddZone, lowerCorner, upperCorner,
211 updateGroupsCog, atomStart, atomEnd, atomDensity,
212 atinfo, x, numAtomsMoved, move, nbat);
214 cycleCounting_.stop(enbsCCgrid);
217 /* \brief Constructor
219 * \param[in] ePBC The periodic boundary conditions
220 * \param[in] numDDCells The number of domain decomposition cells per dimension, without DD nullptr should be passed
221 * \param[in] zones The domain decomposition zone setup, without DD nullptr should be passed
222 * \param[in] haveFep Tells whether non-bonded interactions are perturbed
223 * \param[in] maxNumThreads The maximum number of threads used in the search
226 const ivec *numDDCells,
227 const gmx_domdec_zones_t *zones,
228 PairlistType pairlistType,
232 //! Sets the order of the local atoms to the order grid atom ordering
233 void setLocalAtomOrder()
235 gridSet_.setLocalAtomOrder();
238 const DomainSetup domainSetup() const
243 //! Returns the set of search grids
244 const Nbnxm::GridSet &gridSet() const
249 //! Returns the list of thread-local work objects
250 gmx::ArrayRef<const PairsearchWork> work() const
255 //! Returns the list of thread-local work objects
256 gmx::ArrayRef<PairsearchWork> work()
263 DomainSetup domainSetup_;
264 //! The set of search grids
265 Nbnxm::GridSet gridSet_;
266 //! Work objects, one entry for each thread
267 std::vector<PairsearchWork> work_;
270 //! Cycle counting for measuring components of the search
271 SearchCycleCounting cycleCounting_;