SYCL: Avoid using no_init read accessor in rocFFT
[alexxy/gromacs.git] / src / gromacs / mdlib / mdatoms.h
1 /*
2  * This file is part of the GROMACS molecular simulation package.
3  *
4  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
5  * Copyright (c) 2001-2004, The GROMACS development team.
6  * Copyright (c) 2010,2014,2015,2016,2017 by the GROMACS development team.
7  * Copyright (c) 2018,2019,2020,2021, by the GROMACS development team, led by
8  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
9  * and including many others, as listed in the AUTHORS file in the
10  * top-level source directory and at http://www.gromacs.org.
11  *
12  * GROMACS is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU Lesser General Public License
14  * as published by the Free Software Foundation; either version 2.1
15  * of the License, or (at your option) any later version.
16  *
17  * GROMACS is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
20  * Lesser General Public License for more details.
21  *
22  * You should have received a copy of the GNU Lesser General Public
23  * License along with GROMACS; if not, see
24  * http://www.gnu.org/licenses, or write to the Free Software Foundation,
25  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
26  *
27  * If you want to redistribute modifications to GROMACS, please
28  * consider that scientific software is very special. Version
29  * control is crucial - bugs must be traceable. We will be happy to
30  * consider code for inclusion in the official distribution, but
31  * derived work must not be called official GROMACS. Details are found
32  * in the README & COPYING files - if they are missing, get the
33  * official version at http://www.gromacs.org.
34  *
35  * To help us fund GROMACS development, we humbly ask that you cite
36  * the research papers on the package. Check out http://www.gromacs.org.
37  */
38 #ifndef GMX_MDLIB_MDATOMS_H
39 #define GMX_MDLIB_MDATOMS_H
40
41 #include <cstdio>
42
43 #include <memory>
44 #include <vector>
45
46 #include "gromacs/gpu_utils/hostallocator.h"
47 #include "gromacs/utility/real.h"
48 #include "gromacs/utility/unique_cptr.h"
49
50 struct gmx_mtop_t;
51 struct t_inputrec;
52 struct t_mdatoms;
53
54 namespace gmx
55 {
56
57 /*! \libinternal
58  * \brief Contains a C-style t_mdatoms while managing some of its
59  * memory with C++ vectors with allocators.
60  *
61  * \todo The group-scheme kernels needed a plain C-style t_mdatoms, so
62  * this type combines that with the memory management needed for
63  * efficient PME on GPU transfers. The mdatoms_ member should be
64  * removed. */
65 class MDAtoms
66 {
67     //! C-style mdatoms struct.
68     unique_cptr<t_mdatoms> mdatoms_;
69     //! Memory for chargeA that can be set up for efficient GPU transfer.
70     gmx::PaddedHostVector<real> chargeA_;
71     //! Memory for chargeB that can be set up for efficient GPU transfer.
72     gmx::PaddedHostVector<real> chargeB_;
73
74 public:
75     // TODO make this private
76     MDAtoms();
77     ~MDAtoms();
78     //! Getter.
79     t_mdatoms* mdatoms() { return mdatoms_.get(); }
80     //! Const getter.
81     const t_mdatoms* mdatoms() const { return mdatoms_.get(); }
82     /*! \brief Resizes memory for charges of FEP state A.
83      *
84      * \throws std::bad_alloc  If out of memory.
85      */
86     void resizeChargeA(int newSize);
87     /*! \brief Resizes memory for charges of FEP state B.
88      *
89      * \throws std::bad_alloc  If out of memory.
90      */
91     void resizeChargeB(int newSize);
92     /*! \brief Reserves memory for charges of FEP state A.
93      *
94      * \throws std::bad_alloc  If out of memory.
95      */
96     void reserveChargeA(int newCapacity);
97     /*! \brief Reserves memory for charges of FEP state B.
98      *
99      * \throws std::bad_alloc  If out of memory.
100      */
101     void reserveChargeB(int newCapacity);
102     //! Builder function.
103     friend std::unique_ptr<MDAtoms>
104     makeMDAtoms(FILE* fp, const gmx_mtop_t& mtop, const t_inputrec& ir, bool rankHasPmeGpuTask);
105 };
106
107 //! Builder function for MdAtomsWrapper.
108 std::unique_ptr<MDAtoms> makeMDAtoms(FILE* fp, const gmx_mtop_t& mtop, const t_inputrec& ir, bool useGpuForPme);
109
110 } // namespace gmx
111
112 /*! \brief This routine copies the atoms->atom struct into md.
113  *
114  * \param[in]    mtop     The molecular topology.
115  * \param[in]    inputrec The input record.
116  * \param[in]    nindex   If nindex>=0 we are doing DD.
117  * \param[in]    index    Lookup table for global atom index.
118  * \param[in]    homenr   Number of atoms on this processor.
119  * \param[inout] mdAtoms  Data set up by this routine.
120  *
121  * If index!=NULL only the indexed atoms are copied.
122  * For the masses the A-state (lambda=0) mass is used.
123  * Sets md->lambda = 0.
124  * In free-energy runs, update_mdatoms() should be called after atoms2md()
125  * to set the masses corresponding to the value of lambda at each step.
126  */
127 void atoms2md(const gmx_mtop_t&  mtop,
128               const t_inputrec&  inputrec,
129               int                nindex,
130               gmx::ArrayRef<int> index,
131               int                homenr,
132               gmx::MDAtoms*      mdAtoms);
133
134 void update_mdatoms(t_mdatoms* md, real lambda);
135 /* When necessary, sets all the mass parameters to values corresponding
136  * to the free-energy parameter lambda.
137  * Sets md->lambda = lambda.
138  */
139
140 #endif