Merge branch 'release-4-6'
[alexxy/gromacs.git] / src / gromacs / legacyheaders / types / commrec.h
1 /*
2  *
3  *                This source code is part of
4  *
5  *                 G   R   O   M   A   C   S
6  *
7  *          GROningen MAchine for Chemical Simulations
8  *
9  *                        VERSION 3.2.0
10  * Written by David van der Spoel, Erik Lindahl, Berk Hess, and others.
11  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
12  * Copyright (c) 2001-2004, The GROMACS development team,
13  * check out http://www.gromacs.org for more information.
14
15  * This program is free software; you can redistribute it and/or
16  * modify it under the terms of the GNU General Public License
17  * as published by the Free Software Foundation; either version 2
18  * of the License, or (at your option) any later version.
19  *
20  * If you want to redistribute modifications, please consider that
21  * scientific software is very special. Version control is crucial -
22  * bugs must be traceable. We will be happy to consider code for
23  * inclusion in the official distribution, but derived work must not
24  * be called official GROMACS. Details are found in the README & COPYING
25  * files - if they are missing, get the official version at www.gromacs.org.
26  *
27  * To help us fund GROMACS development, we humbly ask that you cite
28  * the papers on the package - you can find them in the top README file.
29  *
30  * For more info, check our website at http://www.gromacs.org
31  *
32  * And Hey:
33  * GRoups of Organic Molecules in ACtion for Science
34  */
35 #ifndef _commrec_h
36 #define _commrec_h
37
38 #include "../../utility/gmxmpi.h"
39 #include "idef.h"
40
41 #ifdef __cplusplus
42 extern "C" {
43 #endif
44
45
46 #define DD_MAXZONE  8
47 #define DD_MAXIZONE 4
48
49 typedef struct gmx_domdec_master *gmx_domdec_master_p_t;
50
51 typedef struct {
52     int  j0;     /* j-zone start               */
53     int  j1;     /* j-zone end                 */
54     int  cg1;    /* i-charge-group end         */
55     int  jcg0;   /* j-charge-group start       */
56     int  jcg1;   /* j-charge-group end         */
57     ivec shift0; /* Minimum shifts to consider */
58     ivec shift1; /* Maximum shifts to consider */
59 } gmx_domdec_ns_ranges_t;
60
61 typedef struct {
62     rvec x0;     /* Zone lower corner in triclinic coordinates         */
63     rvec x1;     /* Zone upper corner in triclinic coordinates         */
64     rvec bb_x0;  /* Zone bounding box lower corner in Cartesian coords */
65     rvec bb_x1;  /* Zone bounding box upper corner in Cartesian coords */
66 } gmx_domdec_zone_size_t;
67
68 typedef struct {
69     /* The number of zones including the home zone */
70     int                    n;
71     /* The shift of the zones with respect to the home zone */
72     ivec                   shift[DD_MAXZONE];
73     /* The charge group boundaries for the zones */
74     int                    cg_range[DD_MAXZONE+1];
75     /* The number of neighbor search zones with i-particles */
76     int                    nizone;
77     /* The neighbor search charge group ranges for each i-zone */
78     gmx_domdec_ns_ranges_t izone[DD_MAXIZONE];
79     /* Boundaries of the zones */
80     gmx_domdec_zone_size_t size[DD_MAXZONE];
81     /* The cg density of the home zone */
82     real                   dens_zone0;
83 } gmx_domdec_zones_t;
84
85 typedef struct gmx_ga2la *gmx_ga2la_t;
86
87 typedef struct gmx_hash *gmx_hash_t;
88
89 typedef struct gmx_reverse_top *gmx_reverse_top_p_t;
90
91 typedef struct gmx_domdec_constraints *gmx_domdec_constraints_p_t;
92
93 typedef struct gmx_domdec_specat_comm *gmx_domdec_specat_comm_p_t;
94
95 typedef struct gmx_domdec_comm *gmx_domdec_comm_p_t;
96
97 typedef struct gmx_pme_comm_n_box *gmx_pme_comm_n_box_p_t;
98
99 typedef struct {
100     int  npbcdim;
101     int  nboundeddim;
102     rvec box0;
103     rvec box_size;
104     /* Tells if the box is skewed for each of the three cartesian directions */
105     ivec tric_dir;
106     rvec skew_fac;
107     /* Orthogonal vectors for triclinic cells, Cartesian index */
108     rvec v[DIM][DIM];
109     /* Normal vectors for the cells walls */
110     rvec normal[DIM];
111 } gmx_ddbox_t;
112
113
114 typedef struct {
115     /* these buffers are used as destination buffers if MPI_IN_PLACE isn't
116        supported.*/
117     int             *ibuf; /* for ints */
118     int              ibuf_alloc;
119
120     gmx_large_int_t *libuf;
121     int              libuf_alloc;
122
123     float           *fbuf; /* for floats */
124     int              fbuf_alloc;
125
126     double          *dbuf; /* for doubles */
127     int              dbuf_alloc;
128 } mpi_in_place_buf_t;
129
130
131 typedef struct {
132     /* The DD particle-particle nodes only */
133     /* The communication setup within the communicator all
134      * defined in dd->comm in domdec.c
135      */
136     int                    nnodes;
137     MPI_Comm               mpi_comm_all;
138     /* Use MPI_Sendrecv communication instead of non-blocking calls */
139     gmx_bool               bSendRecv2;
140     /* The local DD cell index and rank */
141     ivec                   ci;
142     int                    rank;
143     ivec                   master_ci;
144     int                    masterrank;
145     /* Communication with the PME only nodes */
146     int                    pme_nodeid;
147     gmx_bool               pme_receive_vir_ener;
148     gmx_pme_comm_n_box_p_t cnb;
149     int                    nreq_pme;
150     MPI_Request            req_pme[4];
151
152
153     /* The communication setup, identical for each cell, cartesian index */
154     ivec     nc;
155     int      ndim;
156     ivec     dim; /* indexed by 0 to ndim */
157     gmx_bool bGridJump;
158
159     /* PBC from dim 0 to npbcdim */
160     int npbcdim;
161
162     /* Screw PBC? */
163     gmx_bool bScrewPBC;
164
165     /* Forward and backward neighboring cells, indexed by 0 to ndim */
166     int  neighbor[DIM][2];
167
168     /* Only available on the master node */
169     gmx_domdec_master_p_t ma;
170
171     /* Are there inter charge group constraints */
172     gmx_bool bInterCGcons;
173     gmx_bool bInterCGsettles;
174
175     /* Global atom number to interaction list */
176     gmx_reverse_top_p_t reverse_top;
177     int                 nbonded_global;
178     int                 nbonded_local;
179
180     /* The number of inter charge-group exclusions */
181     int  n_intercg_excl;
182
183     /* Vsite stuff */
184     gmx_hash_t                 ga2la_vsite;
185     gmx_domdec_specat_comm_p_t vsite_comm;
186
187     /* Constraint stuff */
188     gmx_domdec_constraints_p_t constraints;
189     gmx_domdec_specat_comm_p_t constraint_comm;
190
191     /* The local to gobal charge group index and local cg to local atom index */
192     int   ncg_home;
193     int   ncg_tot;
194     int  *index_gl;
195     int  *cgindex;
196     int   cg_nalloc;
197     /* Local atom to local cg index, only for special cases */
198     int  *la2lc;
199     int   la2lc_nalloc;
200
201     /* The number of home atoms */
202     int   nat_home;
203     /* The total number of atoms: home and received zones */
204     int   nat_tot;
205     /* Index from the local atoms to the global atoms */
206     int  *gatindex;
207     int   gatindex_nalloc;
208
209     /* Global atom number to local atom number list */
210     gmx_ga2la_t ga2la;
211
212     /* Communication stuff */
213     gmx_domdec_comm_p_t comm;
214
215     /* The partioning count, to keep track of the state */
216     gmx_large_int_t ddp_count;
217
218
219     /* gmx_pme_recv_f buffer */
220     int   pme_recv_f_alloc;
221     rvec *pme_recv_f_buf;
222
223 } gmx_domdec_t;
224
225 typedef struct gmx_partdec *gmx_partdec_p_t;
226
227 typedef struct {
228     int       nsim;
229     int       sim;
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
233        supported.*/
234     mpi_in_place_buf_t *mpb;
235 } gmx_multisim_t;
236
237 #define DUTY_PP  (1<<0)
238 #define DUTY_PME (1<<1)
239
240 typedef struct {
241     int      bUse;
242     MPI_Comm comm_intra;
243     int      rank_intra;
244     MPI_Comm comm_inter;
245
246 } gmx_nodecomm_t;
247
248 typedef struct {
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.
252      */
253     int sim_nodeid, nnodes, npmenodes;
254
255     /* thread numbers: */
256     /* Not used yet: int threadid, nthreads; */
257     /* The nodeid in the PP/PME, PP or PME group */
258     int      nodeid;
259     MPI_Comm mpi_comm_mysim;
260     MPI_Comm mpi_comm_mygroup;
261
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 */
267
268     gmx_nodecomm_t nc;
269
270     /* For domain decomposition */
271     gmx_domdec_t *dd;
272
273     /* For particle decomposition */
274     gmx_partdec_p_t pd;
275
276     /* The duties of this node, see the defines above */
277     int             duty;
278
279     gmx_multisim_t *ms;
280
281     /* these buffers are used as destination buffers if MPI_IN_PLACE isn't
282        supported.*/
283     mpi_in_place_buf_t *mpb;
284 } t_commrec;
285
286 #define MASTERNODE(cr)     (((cr)->nodeid == 0) || !PAR(cr))
287 /* #define MASTERTHREAD(cr)   ((cr)->threadid == 0) */
288 /* #define MASTER(cr)         (MASTERNODE(cr) && MASTERTHREAD(cr)) */
289 #define MASTER(cr)         MASTERNODE(cr)
290 #define SIMMASTER(cr)      ((MASTER(cr) && ((cr)->duty & DUTY_PP)) || !PAR(cr))
291 #define NODEPAR(cr)        ((cr)->nnodes > 1)
292 /* #define THREADPAR(cr)      ((cr)->nthreads > 1) */
293 /* #define PAR(cr)            (NODEPAR(cr) || THREADPAR(cr)) */
294 #define PAR(cr)            NODEPAR(cr)
295 #define RANK(cr, nodeid)    (nodeid)
296 #define MASTERRANK(cr)     (0)
297
298 #define DOMAINDECOMP(cr)   (((cr)->dd != NULL) && PAR(cr))
299 #define DDMASTER(dd)       ((dd)->rank == (dd)->masterrank)
300
301 #define PARTDECOMP(cr)     ((cr)->pd != NULL)
302
303 #define MULTISIM(cr)       ((cr)->ms)
304 #define MSRANK(ms, nodeid)  (nodeid)
305 #define MASTERSIM(ms)      ((ms)->sim == 0)
306
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)))
309
310 #ifdef __cplusplus
311 }
312 #endif
313 #endif