2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2016,2017, 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.
37 * Declares gmx::PaddedRVecVector
39 * \author Mark Abraham <mark.j.abraham@gmail.com>
41 * \ingroup module_math
43 #ifndef GMX_MATH_PADDEDVECTOR_H
44 #define GMX_MATH_PADDEDVECTOR_H
49 #include "gromacs/math/vectypes.h"
50 #include "gromacs/utility/alignedallocator.h"
51 #include "gromacs/utility/arrayref.h"
56 /*! \brief Temporary definition of a type usable for SIMD-style loads of RVec quantities.
58 * \note When resizing paddedRVecVector, the size should be chosen with
59 paddedRVecVectorSize() to ensure correct padding.
60 * \todo Consider replacing the padding applied in resizePaddedRVecVector()
61 * by automated padding on resize() of the vector.
62 * \todo Undo the move of allocator.h and alignedallocator.h from the internal
63 * to be public API applied in Change-Id: Ifb8dacf, needed to use
64 * AlignedAllocationPolicy here, when replacing std::vector here.
66 using PaddedRVecVector
= std::vector
< RVec
, Allocator
< RVec
, AlignedAllocationPolicy
> >;
68 /*! \brief Returns the padded size for PaddedRVecVector given the number of atoms
70 * \param[in] numAtoms The number of atoms for which data will be stored in a PaddedRVecVector
72 static inline size_t paddedRVecVectorSize(size_t numAtoms
)
74 /* We need one real extra for 4-wide SIMD load/store of RVec.
75 * But because the vector contains RVecs, we need to add 1 RVec.
77 size_t simdScatterAccessSize
;
80 simdScatterAccessSize
= numAtoms
+ 1;
84 simdScatterAccessSize
= 0;
87 /* We need padding up to a multiple of the SIMD real width.
88 * But because we don't want a dependence on the SIMD module,
89 * we use GMX_REAL_MAX_SIMD_WIDTH here.
91 size_t simdFlatAccesSize
= ((numAtoms
+ (GMX_REAL_MAX_SIMD_WIDTH
- 1))/GMX_REAL_MAX_SIMD_WIDTH
)*GMX_REAL_MAX_SIMD_WIDTH
;
93 return std::max(simdScatterAccessSize
, simdFlatAccesSize
);
96 /*! \brief Temporary definition of a type usable for SIMD-style loads of RVec quantities from a view.
98 * \todo Find a more permanent solution that permits the update code to safely
99 * use a padded, aligned array-ref type. */
100 template <typename T
>
101 using PaddedArrayRef
= ArrayRef
<T
>;
105 // TODO These are hacks to avoid littering gmx:: all over code that is
106 // almost all destined to move into the gmx namespace at some point.
107 // An alternative would be about 20 files with using statements.
108 using gmx::PaddedRVecVector
;