Debian Codegraph @

src/gromacs/nbnxm/pairlist_imask.h

raw symbols SCIP
1 /*
2 * This file is part of the GROMACS molecular simulation package.
3 *
4 * Copyright 2024- The GROMACS Authors
5 * and the project initiators Erik Lindahl, Berk Hess and David van der Spoel.
6 * Consult the AUTHORS/COPYING files and https://www.gromacs.org for details.
7 *
8 * GROMACS is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public License
10 * as published by the Free Software Foundation; either version 2.1
11 * of the License, or (at your option) any later version.
12 *
13 * GROMACS is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with GROMACS; if not, see
20 * https://www.gnu.org/licenses, or write to the Free Software Foundation,
21 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 *
23 * If you want to redistribute modifications to GROMACS, please
24 * consider that scientific software is very special. Version
25 * control is crucial - bugs must be traceable. We will be happy to
26 * consider code for inclusion in the official distribution, but
27 * derived work must not be called official GROMACS. Details are found
28 * in the README & COPYING files - if they are missing, get the
29 * official version at https://www.gromacs.org.
30 *
31 * To help us fund GROMACS development, we humbly ask that you cite
32 * the research papers on the package. Check out https://www.gromacs.org.
33 */
34
35 /*! \internal \file
36 *
37 * \brief
38 * Declares and defines pairlist interaction mask generation functions
39 *
40 * \author Berk Hess <[email protected]>
41 * \ingroup module_nbnxm
42 */
43
44 #ifndef GMX_NBNXM_PAIRLIST_IMASK_H
45 #define GMX_NBNXM_PAIRLIST_IMASK_Hcxx . . $ `src/gromacs/nbnxm/pairlist_imask.h:45:9`!
46
47 namespace gmxcxx . . $ gmx/
48 {
49
50 /*! \brief Returns a diagonal interaction mask with atoms j<i masked out
51 *
52 * \tparam T Integer type, should have at least iClusterSize*jClusterSize bits
53 * \tparam iClusterSize The i-cluster size
54 * \tparam jClusterSize The j-cluster size
55 *
56 * Condition: jClusterSize <= iClusterSize
57 */
58 template<typename T, int iClusterSize, int jClusterSize>
59 constexpr stdcxx . . $ std/::arraycxx . . $ std/array#<T, iClusterSize / jClusterSize> diagonalMaskJSmallerIcxx . . $ gmx/diagonalMaskJSmallerI(633bc23ff8486f79).()
60 {
61 static_assert(jClusterSize <= iClusterSize);
62 static_assert(iClusterSize * jClusterSize <= sizeof(T) * CHAR_BITcxx . . $ `<external>/67164224788392828/limits.h:64:9`!);
63
64 // Call the constructor to initialize the array to zero
65 // to permit the function to be declared constexpr.
66 stdcxx . . $ std/::arraycxx . . $ std/array#<T, iClusterSize / jClusterSize> mask{};
67
68 for (int maskIndex = 0; maskIndex < iClusterSize / jClusterSize; maskIndex++)
69 {
70 for (int i = 0; i < iClusterSize; i++)
71 {
72 for (int j = stdcxx . . $ std/::maxcxx . . $ std/max(2a338fce5842aa6a).(i + 1 - maskIndex * jClusterSize, 0); j < jClusterSize; j++)
73 {
74 mask[maskIndex] |= (T(1) <<cxx . . $ gmx/`operator<<`(d49a3ac4a748bb06). (i * jClusterSize + j));
75 }
76 }
77 }
78
79 return mask;
80 }
81
82 /*! \brief Returns a diagonal interaction mask with atoms j>i masked out
83 *
84 * \tparam T Integer type, should have at least iClusterSize*jClusterSize bits
85 * \tparam iClusterSize The i-cluster size
86 * \tparam jClusterSize The j-cluster size
87 *
88 * Condition: jClusterSize >= iClusterSize
89 */
90 template<typename T, int iClusterSize, int jClusterSize>
91 constexpr stdcxx . . $ std/::arraycxx . . $ std/array#<T, jClusterSize / iClusterSize> diagonalMaskJLargerIcxx . . $ gmx/diagonalMaskJLargerI(31b35fc39e6d2749).()
92 {
93 static_assert(jClusterSize >= iClusterSize);
94 static_assert(iClusterSize * jClusterSize <= sizeof(T) * CHAR_BITcxx . . $ `<external>/67164224788392828/limits.h:64:9`!);
95
96 // Call the constructor to initialize the array to zero
97 // to permit the function to be declared constexpr.
98 stdcxx . . $ std/::arraycxx . . $ std/array#<T, jClusterSize / iClusterSize> mask{};
99
100 for (int maskIndex = 0; maskIndex < jClusterSize / iClusterSize; maskIndex++)
101 {
102 for (int i = 0; i < iClusterSize; i++)
103 {
104 for (int j = maskIndex * iClusterSize + i + 1; j < jClusterSize; j++)
105 {
106 mask[maskIndex] |= (T(1) <<cxx . . $ gmx/`operator<<`(d49a3ac4a748bb06). (i * jClusterSize + j));
107 }
108 }
109 }
110
111 return mask;
112 }
113
114 /*! \brief Returns a diagonal or off-diagonal interaction mask
115 *
116 * \tparam iClusterSize The i-cluster size
117 * \tparam jClusterSize The j-cluster size
118 * \param[in] maskOutSubDiagonal Whether to mask out the sub-diagonal interactions
119 * \param[in] ci The i-cluster index
120 * \param[in] cj The j-cluster index
121 */
122 template<int iClusterSize, int jClusterSize>
123 static gmx_unusedcxx . . $ `api/legacy/include/gromacs/utility/basedefinitions.h:103:17`! uint32_tcxx . . $ uint32_t# getImaskcxx . . $ gmx/getImask(87559ddfb36e4e1e).(const bool maskOutSubDiagonal, const int ci, const int cj)
124 {
125 if constexpr (jClusterSize >= iClusterSize)
126 {
127 // static, so the diagonal mask is only created once
128 static constexpr auto sc_diagonalMask =
129 diagonalMaskJLargerIcxx . . $ gmx/diagonalMaskJLargerI(31b35fc39e6d2749).<uint32_tcxx . . $ uint32_t#, iClusterSize, jClusterSize>();
130
131 constexpr int ratio = jClusterSize / iClusterSize;
132 const int diff = ci - cj * ratio;
133
134 return (maskOutSubDiagonal && diff >= 0 && diff < ratio ? sc_diagonalMask[diff]
135 : NBNXN_INTERACTION_MASK_ALLcxx . . $ gmx/NBNXN_INTERACTION_MASK_ALL.);
136 }
137 else
138 {
139 // static, so the diagonal mask is only created once
140 static constexpr auto sc_diagonalMask =
141 diagonalMaskJSmallerIcxx . . $ gmx/diagonalMaskJSmallerI(633bc23ff8486f79).<uint32_tcxx . . $ uint32_t#, iClusterSize, jClusterSize>();
142
143 constexpr int ratio = iClusterSize / jClusterSize;
144 const int diff = cj - ci * ratio;
145
146 return (maskOutSubDiagonal && diff >= 0 && diff < ratio ? sc_diagonalMask[diff]
147 : NBNXN_INTERACTION_MASK_ALLcxx . . $ gmx/NBNXN_INTERACTION_MASK_ALL.);
148 }
149 }
150
151 } // namespace gmx
152
153 #endif // GMX_NBNXM_PAIRLIST_IMASK_H