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,2019, 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, int numAtomsLocal);
77 ~gmx_ga2la_t() { usingDirect_ ? data_.direct.~vector() : data_.hashed.~HashedMap(); }
79 /*! \brief Inserts an entry, there should not already be an entry for \p a_gl
81 * \param[in] a_gl The global atom index
82 * \param[in] value The value to set for this index
84 void insert(int a_gl, const Entry& value)
86 GMX_ASSERT(a_gl >= 0, "Only global atom indices >= 0 are supported");
89 GMX_ASSERT(data_.direct[a_gl].cell == -1,
90 "The key to be inserted should not be present");
91 data_.direct[a_gl] = value;
95 data_.hashed.insert(a_gl, value);
99 //! Delete the entry for global atom a_gl
104 data_.direct[a_gl].cell = -1;
108 data_.hashed.erase(a_gl);
112 //! Returns a pointer to the entry when present, nullptr otherwise
113 const Entry* find(int a_gl) const
117 return (data_.direct[a_gl].cell == -1) ? nullptr : &(data_.direct[a_gl]);
121 return (data_.hashed.find(a_gl));
125 //! Returns the local atom index if it is a home atom, nullptr otherwise
126 const int* findHome(int a_gl) const
128 const Entry* const e = find(a_gl);
129 return (e && e->cell == 0) ? &(e->la) : nullptr;
132 /*! \brief Returns a reference to the entry for a_gl
134 * A non-release assert checks that a_gl is present.
140 GMX_ASSERT(data_.direct[a_gl].cell >= 0, "a_gl should be present");
141 return data_.direct[a_gl];
145 Entry* search = data_.hashed.find(a_gl);
146 GMX_ASSERT(search, "a_gl should be present");
151 //! Clear all the entries in the list.
156 for (Entry& entry : data_.direct)
163 data_.hashed.clear();
169 std::vector<Entry> direct;
170 gmx::HashedMap<Entry> hashed;
171 // constructor and destructor function in parent class
175 const bool usingDirect_;