Merge branch release-2016
[alexxy/gromacs.git] / src / gromacs / mdtypes / commrec.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) 2013,2014,2015,2017, 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.
10  *
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.
15  *
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.
20  *
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.
25  *
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.
33  *
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.
36  */
37 #ifndef GMX_MDTYPES_COMMREC_H
38 #define GMX_MDTYPES_COMMREC_H
39
40 #include <stddef.h>
41
42 #include "gromacs/math/vectypes.h"
43 #include "gromacs/utility/basedefinitions.h"
44 #include "gromacs/utility/gmxmpi.h"
45 #include "gromacs/utility/real.h"
46
47 struct gmx_domdec_t;
48
49 typedef struct {
50     /* these buffers are used as destination buffers if MPI_IN_PLACE isn't
51        supported.*/
52     int             *ibuf; /* for ints */
53     int              ibuf_alloc;
54
55     gmx_int64_t     *libuf;
56     int              libuf_alloc;
57
58     float           *fbuf; /* for floats */
59     int              fbuf_alloc;
60
61     double          *dbuf; /* for doubles */
62     int              dbuf_alloc;
63 } mpi_in_place_buf_t;
64
65 struct gmx_multisim_t {
66     int       nsim;
67     int       sim;
68     MPI_Group mpi_group_masters;
69     MPI_Comm  mpi_comm_masters;
70     /* these buffers are used as destination buffers if MPI_IN_PLACE isn't
71        supported.*/
72     mpi_in_place_buf_t *mpb;
73 };
74
75 #define DUTY_PP  (1<<0)
76 #define DUTY_PME (1<<1)
77
78 typedef struct {
79     int      bUse;
80     MPI_Comm comm_intra;
81     int      rank_intra;
82     MPI_Comm comm_inter;
83
84 } gmx_nodecomm_t;
85
86 struct t_commrec {
87     /* The nodeids in one sim are numbered sequentially from 0.
88      * All communication within some simulation should happen
89      * in mpi_comm_mysim, or its subset mpi_comm_mygroup.
90      */
91     int sim_nodeid, nnodes, npmenodes;
92
93     /* thread numbers: */
94     /* Not used yet: int threadid, nthreads; */
95     /* The nodeid in the PP/PME, PP or PME group */
96     int      nodeid;
97
98     /* MPI communicators within a single simulation
99      * Note: other parts of the code may further subset these communicators.
100      */
101     MPI_Comm mpi_comm_mysim;           /* communicator including all ranks of
102                                           a single simulation */
103     MPI_Comm mpi_comm_mygroup;         /* subset of mpi_comm_mysim including only
104                                           the ranks in the same group (PP or PME) */
105
106     /* MPI ranks and a communicator within a physical node for hardware access */
107     MPI_Comm       mpi_comm_physicalnode; /* communicator for all ranks of the physical node
108                                            * NOTE: this communicator should only be used during initialization and finalization, as it can contain ranks from PP, PME and multiple simulations with multisim
109                                            */
110     int            nrank_intranode;       /* nr of ranks on this physical node */
111     int            rank_intranode;        /* our rank on this physical node */
112     int            nrank_pp_intranode;    /* as nrank_intranode, for particle-particle only */
113     int            rank_pp_intranode;     /* as rank_intranode, for particle-particle only */
114
115     gmx_nodecomm_t nc;
116
117     /* For domain decomposition */
118     gmx_domdec_t *dd;
119
120     /* The duties of this node, see the defines above */
121     int                    duty;
122
123     gmx_multisim_t        *ms;
124
125     /* these buffers are used as destination buffers if MPI_IN_PLACE isn't
126        supported.*/
127     mpi_in_place_buf_t *mpb;
128 };
129
130 //! True if this is a simulation with more than 1 node
131 #define PAR(cr)        ((cr)->nnodes > 1)
132
133 //! True of this is the master node
134 #define MASTER(cr)     (((cr)->nodeid == 0) || !PAR(cr))
135
136 //! True if this is the particle-particle master
137 #define SIMMASTER(cr)  ((MASTER(cr) && ((cr)->duty & DUTY_PP)) || !PAR(cr))
138
139 //! The node id for this rank
140 #define RANK(cr, nodeid)    (nodeid)
141
142 //! The node id for the master
143 #define MASTERRANK(cr)     (0)
144
145 /*! \brief Do we use domain decomposition
146  *
147  * Note that even with particle decomposition removed, the use of
148  * non-DD parallelization in TPI, NM and multi-simulations means that
149  * PAR(cr) and DOMAINDECOMP(cr) are not universally synonymous. In
150  * particular, DOMAINDECOMP(cr) == true indicates that there is more
151  * than one domain, not just that the dd algorithm is active. */
152 #define DOMAINDECOMP(cr)   (((cr)->dd != NULL) && PAR(cr))
153
154 //! Are we doing multiple independent simulations
155 #define MULTISIM(cr)       ((cr)->ms)
156
157 //! Are we the master node of a multisimulation
158 #define MASTERSIM(ms)      ((ms)->sim == 0)
159
160 //! The master of all (the node that prints the remaining run time etc.)
161 #define MULTIMASTER(cr)    (SIMMASTER(cr) && (!MULTISIM(cr) || MASTERSIM((cr)->ms)))
162
163 #endif