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, 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.
40 #include "../../utility/gmxmpi.h"
41 #include "../typedefs.h"
51 typedef struct gmx_domdec_master *gmx_domdec_master_p_t;
54 int j0; /* j-zone start */
55 int j1; /* j-zone end */
56 int cg1; /* i-charge-group end */
57 int jcg0; /* j-charge-group start */
58 int jcg1; /* j-charge-group end */
59 ivec shift0; /* Minimum shifts to consider */
60 ivec shift1; /* Maximum shifts to consider */
61 } gmx_domdec_ns_ranges_t;
64 rvec x0; /* Zone lower corner in triclinic coordinates */
65 rvec x1; /* Zone upper corner in triclinic coordinates */
66 rvec bb_x0; /* Zone bounding box lower corner in Cartesian coords */
67 rvec bb_x1; /* Zone bounding box upper corner in Cartesian coords */
68 } gmx_domdec_zone_size_t;
70 struct gmx_domdec_zones_t {
71 /* The number of zones including the home zone */
73 /* The shift of the zones with respect to the home zone */
74 ivec shift[DD_MAXZONE];
75 /* The charge group boundaries for the zones */
76 int cg_range[DD_MAXZONE+1];
77 /* The number of neighbor search zones with i-particles */
79 /* The neighbor search charge group ranges for each i-zone */
80 gmx_domdec_ns_ranges_t izone[DD_MAXIZONE];
81 /* Boundaries of the zones */
82 gmx_domdec_zone_size_t size[DD_MAXZONE];
83 /* The cg density of the home zone */
87 typedef struct gmx_ga2la *gmx_ga2la_t;
89 typedef struct gmx_hash *gmx_hash_t;
91 typedef struct gmx_reverse_top *gmx_reverse_top_p_t;
93 typedef struct gmx_domdec_constraints *gmx_domdec_constraints_p_t;
95 typedef struct gmx_domdec_specat_comm *gmx_domdec_specat_comm_p_t;
97 typedef struct gmx_domdec_comm *gmx_domdec_comm_p_t;
99 typedef struct gmx_pme_comm_n_box *gmx_pme_comm_n_box_p_t;
106 /* Tells if the box is skewed for each of the three cartesian directions */
109 /* Orthogonal vectors for triclinic cells, Cartesian index */
111 /* Normal vectors for the cells walls */
117 /* these buffers are used as destination buffers if MPI_IN_PLACE isn't
119 int *ibuf; /* for ints */
125 float *fbuf; /* for floats */
128 double *dbuf; /* for doubles */
130 } mpi_in_place_buf_t;
133 struct gmx_domdec_t {
134 /* The DD particle-particle nodes only */
135 /* The communication setup within the communicator all
136 * defined in dd->comm in domdec.c
139 MPI_Comm mpi_comm_all;
140 /* Use MPI_Sendrecv communication instead of non-blocking calls */
142 /* The local DD cell index and rank */
147 /* Communication with the PME only nodes */
149 gmx_bool pme_receive_vir_ener;
150 gmx_pme_comm_n_box_p_t cnb;
152 MPI_Request req_pme[8];
155 /* The communication setup, identical for each cell, cartesian index */
158 ivec dim; /* indexed by 0 to ndim */
161 /* PBC from dim 0 to npbcdim */
167 /* Forward and backward neighboring cells, indexed by 0 to ndim */
168 int neighbor[DIM][2];
170 /* Only available on the master node */
171 gmx_domdec_master_p_t ma;
173 /* Are there inter charge group constraints */
174 gmx_bool bInterCGcons;
175 gmx_bool bInterCGsettles;
177 /* Global atom number to interaction list */
178 gmx_reverse_top_p_t reverse_top;
182 /* The number of inter charge-group exclusions */
186 gmx_hash_t ga2la_vsite;
187 gmx_domdec_specat_comm_p_t vsite_comm;
189 /* Constraint stuff */
190 gmx_domdec_constraints_p_t constraints;
191 gmx_domdec_specat_comm_p_t constraint_comm;
193 /* The local to gobal charge group index and local cg to local atom index */
199 /* Local atom to local cg index, only for special cases */
203 /* The number of home atoms */
205 /* The total number of atoms: home and received zones */
207 /* Index from the local atoms to the global atoms */
211 /* Global atom number to local atom number list */
214 /* Communication stuff */
215 gmx_domdec_comm_p_t comm;
217 /* The partioning count, to keep track of the state */
218 gmx_int64_t ddp_count;
221 /* gmx_pme_recv_f buffer */
222 int pme_recv_f_alloc;
223 rvec *pme_recv_f_buf;
227 struct gmx_multisim_t {
230 MPI_Group mpi_group_masters;
231 MPI_Comm mpi_comm_masters;
232 /* these buffers are used as destination buffers if MPI_IN_PLACE isn't
234 mpi_in_place_buf_t *mpb;
237 #define DUTY_PP (1<<0)
238 #define DUTY_PME (1<<1)
249 /* The nodeids in one sim are numbered sequentially from 0.
250 * All communication within some simulation should happen
251 * in mpi_comm_mysim, or its subset mpi_comm_mygroup.
253 int sim_nodeid, nnodes, npmenodes;
255 /* thread numbers: */
256 /* Not used yet: int threadid, nthreads; */
257 /* The nodeid in the PP/PME, PP or PME group */
259 MPI_Comm mpi_comm_mysim;
260 MPI_Comm mpi_comm_mygroup;
262 /* MPI ranks within a physical node for hardware access */
263 int nrank_intranode; /* nr of ranks on this physical node */
264 int rank_intranode; /* our rank on this physical node */
265 int nrank_pp_intranode; /* as nrank_intranode, for particle-particle only */
266 int rank_pp_intranode; /* as rank_intranode, for particle-particle only */
270 /* For domain decomposition */
273 /* The duties of this node, see the defines above */
278 /* these buffers are used as destination buffers if MPI_IN_PLACE isn't
280 mpi_in_place_buf_t *mpb;
283 #define MASTERNODE(cr) (((cr)->nodeid == 0) || !PAR(cr))
284 /* #define MASTERTHREAD(cr) ((cr)->threadid == 0) */
285 /* #define MASTER(cr) (MASTERNODE(cr) && MASTERTHREAD(cr)) */
286 #define MASTER(cr) MASTERNODE(cr)
287 #define SIMMASTER(cr) ((MASTER(cr) && ((cr)->duty & DUTY_PP)) || !PAR(cr))
288 #define NODEPAR(cr) ((cr)->nnodes > 1)
289 /* #define THREADPAR(cr) ((cr)->nthreads > 1) */
290 /* #define PAR(cr) (NODEPAR(cr) || THREADPAR(cr)) */
291 #define PAR(cr) NODEPAR(cr)
292 #define RANK(cr, nodeid) (nodeid)
293 #define MASTERRANK(cr) (0)
295 /* Note that even with particle decomposition removed, the use of
296 * non-DD parallelization in TPI, NM and multi-simulations means that
297 * PAR(cr) and DOMAINDECOMP(cr) are not universally synonymous. In
298 * particular, DOMAINDECOMP(cr) == true indicates that there is more
299 * than one domain, not just that the dd algorithm is active. */
300 #define DOMAINDECOMP(cr) (((cr)->dd != NULL) && PAR(cr))
301 #define DDMASTER(dd) ((dd)->rank == (dd)->masterrank)
303 #define MULTISIM(cr) ((cr)->ms)
304 #define MSRANK(ms, nodeid) (nodeid)
305 #define MASTERSIM(ms) ((ms)->sim == 0)
307 /* The master of all (the node that prints the remaining run time etc.) */
308 #define MULTIMASTER(cr) (SIMMASTER(cr) && (!MULTISIM(cr) || MASTERSIM((cr)->ms)))