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,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 #ifndef GMX_MDTYPES_COMMREC_H
38 #define GMX_MDTYPES_COMMREC_H
42 #include "gromacs/utility/basedefinitions.h"
43 #include "gromacs/utility/gmxassert.h"
44 #include "gromacs/utility/gmxmpi.h"
46 struct mpi_in_place_buf_t;
49 #define DUTY_PP (1U<<0U)
50 #define DUTY_PME (1U<<1U)
61 /* The nodeids in one sim are numbered sequentially from 0.
62 * All communication within some simulation should happen
63 * in mpi_comm_mysim, or its subset mpi_comm_mygroup.
65 int sim_nodeid, nnodes, npmenodes;
68 /* Not used yet: int threadid, nthreads; */
69 /* The nodeid in the PP/PME, PP or PME group */
72 /* MPI communicators within a single simulation
73 * Note: other parts of the code may further subset these communicators.
75 MPI_Comm mpi_comm_mysim; /* communicator including all ranks of
76 a single simulation */
77 MPI_Comm mpi_comm_mygroup; /* subset of mpi_comm_mysim including only
78 the ranks in the same group (PP or PME) */
82 /* For domain decomposition */
85 /* The duties of this node, see the DUTY_ defines above.
86 * This should be read through thisRankHasDuty() or getThisRankDuties().
90 /* these buffers are used as destination buffers if MPI_IN_PLACE isn't
92 mpi_in_place_buf_t *mpb;
96 * Returns the rank's duty, and asserts that it has been initialized.
98 inline int getThisRankDuties(const t_commrec *cr)
100 GMX_ASSERT(cr, "Invalid commrec pointer");
101 GMX_ASSERT(cr->duty != 0, "Commrec duty was not initialized!");
106 * A convenience getter for the commrec duty assignment;
107 * asserts that duty is actually valid (have been initialized).
109 * \param[in] cr Communication structure pointer
110 * \param[in] duty A single duty's corresponding DUTY_ flag. Combinations are not supported.
112 * \returns Whether this duty is assigned to this rank.
114 inline bool thisRankHasDuty(const t_commrec *cr, int duty)
116 GMX_ASSERT((duty == DUTY_PME) || (duty == DUTY_PP), "Invalid duty type");
117 return (getThisRankDuties(cr) & duty) != 0;
120 //! True if this is a simulation with more than 1 node
121 #define PAR(cr) ((cr)->nnodes > 1)
123 //! True of this is the master node
124 #define MASTER(cr) (((cr)->nodeid == 0) || !PAR(cr))
126 //! True if this is the particle-particle master
127 #define SIMMASTER(cr) ((MASTER(cr) && thisRankHasDuty((cr), DUTY_PP)) || !PAR(cr))
129 //! The node id for this rank
130 #define RANK(cr, nodeid) (nodeid)
132 //! The node id for the master
133 #define MASTERRANK(cr) (0)
135 /*! \brief Do we use domain decomposition
137 * Note that even with particle decomposition removed, the use of
138 * non-DD parallelization in TPI, NM and multi-simulations means that
139 * PAR(cr) and DOMAINDECOMP(cr) are not universally synonymous. In
140 * particular, DOMAINDECOMP(cr) == true indicates that there is more
141 * than one domain, not just that the dd algorithm is active. */
142 #define DOMAINDECOMP(cr) (((cr)->dd != nullptr) && PAR(cr))
144 /*! \brief Returns whether we have actual domain decomposition for the particle-particle interactions
146 * Will return false when we use 1 rank for PP and 1 for PME
148 static bool inline havePPDomainDecomposition(const t_commrec *cr)
150 /* NOTE: It would be better to use cr->dd->nnodes, but we do not want
151 * to pull in a dependency on domdec.h into this file.
153 return (cr != nullptr &&
155 cr->nnodes - cr->npmenodes > 1);