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) 2013,2014,2015,2017,2018 by the GROMACS development team.
7 * Copyright (c) 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.
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.
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.
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.
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.
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.
38 #ifndef GMX_MDTYPES_COMMREC_H
39 #define GMX_MDTYPES_COMMREC_H
43 #include "gromacs/utility/gmxassert.h"
44 #include "gromacs/utility/gmxmpi.h"
48 #define DUTY_PP (1U << 0U)
49 #define DUTY_PME (1U << 1U)
51 //! Whether the current DD role is master or slave
58 //! Whether one or more ranks are used
76 /* The nodeids in one sim are numbered sequentially from 0.
77 * All communication within some simulation should happen
78 * in mpi_comm_mysim, or its subset mpi_comm_mygroup.
80 int sim_nodeid, nnodes, npmenodes;
83 /* Not used yet: int threadid, nthreads; */
84 /* The nodeid in the PP/PME, PP or PME group */
87 /* MPI communicators within a single simulation
88 * Note: other parts of the code may further subset these communicators.
90 MPI_Comm mpi_comm_mysim; /* communicator including all ranks of
91 a single simulation */
92 MPI_Comm mpi_comm_mygroup; /* subset of mpi_comm_mysim including only
93 the ranks in the same group (PP or PME) */
94 //! The communicator used before DD was initialized
95 MPI_Comm mpiDefaultCommunicator;
96 int sizeOfDefaultCommunicator;
97 int rankInDefaultCommunicator;
101 /* For domain decomposition */
104 /* The duties of this node, see the DUTY_ defines above.
105 * This should be read through thisRankHasDuty() or getThisRankDuties().
111 * Returns the rank's duty, and asserts that it has been initialized.
113 inline int getThisRankDuties(const t_commrec* cr)
115 GMX_ASSERT(cr, "Invalid commrec pointer");
116 GMX_ASSERT(cr->duty != 0, "Commrec duty was not initialized!");
121 * A convenience getter for the commrec duty assignment;
122 * asserts that duty is actually valid (have been initialized).
124 * \param[in] cr Communication structure pointer
125 * \param[in] duty A single duty's corresponding DUTY_ flag. Combinations are not supported.
127 * \returns Whether this duty is assigned to this rank.
129 inline bool thisRankHasDuty(const t_commrec* cr, int duty)
131 GMX_ASSERT((duty == DUTY_PME) || (duty == DUTY_PP), "Invalid duty type");
132 return (getThisRankDuties(cr) & duty) != 0;
135 /*! \brief True if this is a simulation with more than 1 rank
137 * In particular, this is true for multi-rank runs with TPI and NM, because
138 * they use a decomposition that is not the domain decomposition used by
139 * other simulation types. */
140 #define PAR(cr) ((cr)->sizeOfDefaultCommunicator > 1)
142 //! True of this is the master node
143 #define MASTER(cr) (((cr)->rankInDefaultCommunicator == 0) || !PAR(cr))
145 // Note that currently, master is always PP master, so this is equivalent to MASTER(cr)
146 //! True if this is the particle-particle master
147 #define SIMMASTER(cr) ((MASTER(cr) && thisRankHasDuty((cr), DUTY_PP)) || !PAR(cr))
149 //! The node id for this rank
150 #define RANK(cr, nodeid) (nodeid)
152 //! The node id for the master
153 #define MASTERRANK(cr) (0)
155 /*! \brief Do we decompose the work of this simulation?
157 * True if this simulation uses more than one PP rank, or if this simulation
158 * uses at least one PME-only rank.
160 * PAR(cr) is true if this is true, but the converse does not apply (see docs
163 * This is true if havePPDomainDecomposition is true, but the converse does not
164 * apply (see docs of havePpDomainDecomposition()).
166 * \todo As part of Issue #2395, replace calls to this with
167 * havePPDomainDecomposition or a call of some other/new function, as
168 * appropriate to each case. Then eliminate this macro. */
169 #define DOMAINDECOMP(cr) (((cr)->dd != nullptr) && PAR(cr))
171 /*! \brief Returns whether we have actual domain decomposition for the particle-particle interactions
173 * Will return false when we use 1 rank for PP and 1 for PME
175 static bool inline havePPDomainDecomposition(const t_commrec* cr)
177 /* NOTE: It would be better to use cr->dd->nnodes, but we do not want
178 * to pull in a dependency on domdec.h into this file.
180 GMX_ASSERT(cr != nullptr, "Invalid call of havePPDomainDecomposition before commrec is made");
181 GMX_ASSERT(cr->npmenodes >= 0,
182 "Invalid call of havePPDomainDecomposition before MPMD automated decomposition was "
184 return (cr->dd != nullptr && cr->nnodes - cr->npmenodes > 1);