2 * This file is part of the GROMACS molecular simulation package.
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,2017,2018, by the GROMACS development team, led by
7 * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
8 * and including many others, as listed in the AUTHORS file in the
9 * top-level source directory and at http://www.gromacs.org.
11 * GROMACS is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public License
13 * as published by the Free Software Foundation; either version 2.1
14 * of the License, or (at your option) any later version.
16 * GROMACS is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with GROMACS; if not, see
23 * http://www.gnu.org/licenses, or write to the Free Software Foundation,
24 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 * If you want to redistribute modifications to GROMACS, please
27 * consider that scientific software is very special. Version
28 * control is crucial - bugs must be traceable. We will be happy to
29 * consider code for inclusion in the official distribution, but
30 * derived work must not be called official GROMACS. Details are found
31 * in the README & COPYING files - if they are missing, get the
32 * official version at http://www.gromacs.org.
34 * To help us fund GROMACS development, we humbly ask that you cite
35 * the research papers on the package. Check out http://www.gromacs.org.
37 /*! \libinternal \file
39 * Defines structures and functions for mapping from global to local atom
40 * indices. The functions are performance critical and should be inlined.
43 * \ingroup module_domdec
45 * \author Berk Hess <hess@kth.se>
48 #ifndef GMX_DOMDEC_GA2LA_H
49 #define GMX_DOMDEC_GA2LA_H
53 #include "gromacs/domdec/hashedmap.h"
54 #include "gromacs/utility/gmxassert.h"
56 /*! \libinternal \brief Global to local atom mapping
58 * Used for efficient mapping from global atom indices to local atom indices
59 * in the domain decomposition.
64 /*! \libinternal \brief Structure for the local atom info */
67 int la
; /**< The local atom index */
68 int cell
; /**< The DD zone index for neighboring domains, zone+zone otherwise */
71 /*! \brief Constructor
73 * \param[in] numAtomsTotal The total number of atoms in the system
74 * \param[in] numAtomsLocal An estimate of the number of home+communicated atoms
76 gmx_ga2la_t(int numAtomsTotal
,
80 usingDirect_
? data_
.direct
.~vector() : data_
.hashed
.~HashedMap();
83 /*! \brief Inserts an entry, there should not already be an entry for \p a_gl
85 * \param[in] a_gl The global atom index
86 * \param[in] value The value to set for this index
91 GMX_ASSERT(a_gl
>= 0, "Only global atom indices >= 0 are supported");
94 GMX_ASSERT(data_
.direct
[a_gl
].cell
== -1, "The key to be inserted should not be present");
95 data_
.direct
[a_gl
] = value
;
99 data_
.hashed
.insert(a_gl
, value
);
103 //! Delete the entry for global atom a_gl
108 data_
.direct
[a_gl
].cell
= -1;
112 data_
.hashed
.erase(a_gl
);
116 //! Returns a pointer to the entry when present, nullptr otherwise
117 const Entry
* find(int a_gl
) const
121 return (data_
.direct
[a_gl
].cell
== -1) ? nullptr : &(data_
.direct
[a_gl
]);
125 return (data_
.hashed
.find(a_gl
));
129 //! Returns the local atom index if it is a home atom, nullptr otherwise
130 const int* findHome(int a_gl
) const
132 const Entry
* const e
= find(a_gl
);
133 return (e
&& e
->cell
== 0) ? &(e
->la
) : nullptr;
136 /*! \brief Returns a reference to the entry for a_gl
138 * A non-release assert checks that a_gl is present.
144 GMX_ASSERT(data_
.direct
[a_gl
].cell
>= 0, "a_gl should be present");
145 return data_
.direct
[a_gl
];
149 Entry
*search
= data_
.hashed
.find(a_gl
);
150 GMX_ASSERT(search
, "a_gl should be present");
155 //! Clear all the entries in the list.
160 for (Entry
&entry
: data_
.direct
) {entry
.cell
= -1; }
164 data_
.hashed
.clear();
171 std::vector
<Entry
> direct
;
172 gmx::HashedMap
<Entry
> hashed
;
173 // constructor and destructor function in parent class
177 const bool usingDirect_
;