b30f37a50b320b6ba533fcd13102654d92f72f4e
[alexxy/gromacs.git] / src / gromacs / nbnxm / pairlistwork.h
1 /*
2  * This file is part of the GROMACS molecular simulation package.
3  *
4  * Copyright (c) 2019,2020,2021, 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 Declares working data structures for the CPU and GPU pairlists
39  *
40  * \author Berk Hess <hess@kth.se>
41  *
42  * \ingroup module_nbnxm
43  */
44
45 #ifndef GMX_NBNXM_PAIRLISTWORK_H
46 #define GMX_NBNXM_PAIRLISTWORK_H
47
48 #include <memory>
49 #include <vector>
50
51 #include "gromacs/simd/simd.h"
52
53 #include "boundingboxes.h"
54 #include "grid.h"
55 #include "pairlist.h"
56
57 //! Working data for the actual i-supercell during pair search \internal
58 struct NbnxnPairlistCpuWork
59 {
60     //! Struct for storing coordinates and bounding box for an i-entry during search \internal
61     struct IClusterData
62     {
63         IClusterData() :
64             bb(1),
65             x(c_nbnxnCpuIClusterSize * DIM),
66             xSimd(c_nbnxnCpuIClusterSize * DIM * GMX_REAL_MAX_SIMD_WIDTH)
67         {
68         }
69
70         //! The bounding boxes, pbc shifted, for each cluster
71         AlignedVector<Nbnxm::BoundingBox> bb;
72         //! The coordinates, pbc shifted, for each atom
73         std::vector<real> x;
74         //! Aligned list for storing 4*DIM*GMX_SIMD_REAL_WIDTH reals
75         AlignedVector<real> xSimd;
76     };
77
78     //! Protect data from cache pollution between threads
79     gmx_cache_protect_t cp0;
80
81     //! Work data for generating an IEntry in the pairlist
82     IClusterData iClusterData;
83     //! The current cj_ind index for the current list
84     int cj_ind;
85     //! Temporary j-cluster list, used for sorting on exclusions
86     std::vector<nbnxn_cj_t> cj;
87
88     //! Nr. of cluster pairs without Coulomb for flop counting
89     int ncj_noq;
90     //! Nr. of cluster pairs with 1/2 LJ for flop count
91     int ncj_hlj;
92
93     //! Protect data from cache pollution between threads
94     gmx_cache_protect_t cp1;
95 };
96
97 /* Working data for the actual i-supercell during pair search */
98 struct NbnxnPairlistGpuWork
99 {
100     struct ISuperClusterData
101     {
102         ISuperClusterData() :
103             bb(c_gpuNumClusterPerCell),
104 #if NBNXN_SEARCH_BB_SIMD4
105             bbPacked(c_gpuNumClusterPerCell / c_packedBoundingBoxesDimSize * c_packedBoundingBoxesSize),
106 #endif
107             x(c_gpuNumClusterPerCell * c_nbnxnGpuClusterSize * DIM),
108             xSimd(c_gpuNumClusterPerCell * c_nbnxnGpuClusterSize * DIM)
109         {
110         }
111
112         //! The bounding boxes, pbc shifted, for each cluster
113         AlignedVector<Nbnxm::BoundingBox> bb;
114         //! As bb, but in packed xxxx format
115         AlignedVector<float> bbPacked;
116         //! The coordinates, pbc shifted, for each atom
117         AlignedVector<real> x;
118         //! Aligned coordinate list used for 4*DIM*GMX_SIMD_REAL_WIDTH floats
119         AlignedVector<real> xSimd;
120     };
121
122     NbnxnPairlistGpuWork() :
123         distanceBuffer(c_gpuNumClusterPerCell),
124         sci_sort({}, { gmx::PinningPolicy::PinnedIfSupported })
125     {
126     }
127
128     //! Protect data from cache pollution between threads
129     gmx_cache_protect_t cp0;
130
131     //! Work data for generating an i-entry in the pairlist
132     ISuperClusterData iSuperClusterData;
133     //! The current j-cluster index for the current list
134     int cj_ind;
135     //! Bounding box distance work array
136     AlignedVector<float> distanceBuffer;
137
138     //! Buffer for sorting list entries
139     std::vector<int> sortBuffer;
140
141     //! Second sci array, for sorting
142     gmx::HostVector<nbnxn_sci_t> sci_sort;
143
144     //! Protect data from cache pollution between threads
145     gmx_cache_protect_t cp1;
146 };
147
148 #endif