Merge release-4-6 into master
[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 #ifdef GMX_LIB_MPI
39 #include <mpi.h>
40 #else
41 #ifdef GMX_THREAD_MPI
42 #include "../tmpi.h"
43 #else
44 typedef void* MPI_Comm;
45 typedef void* MPI_Request;
46 typedef void* MPI_Group;
47 #endif
48 #endif
49
50 #include "idef.h"
51
52 #ifdef __cplusplus
53 extern "C" {
54 #endif
55
56
57 #define DD_MAXZONE  8
58 #define DD_MAXIZONE 4
59
60 typedef struct gmx_domdec_master *gmx_domdec_master_p_t;
61
62 typedef struct {
63   int  j0;       /* j-cell start               */
64   int  j1;       /* j-cell end                 */
65   int  cg1;      /* i-charge-group end         */
66   int  jcg0;     /* j-charge-group start       */
67   int  jcg1;     /* j-charge-group end         */
68   ivec shift0;   /* Minimum shifts to consider */
69   ivec shift1;   /* Maximum shifts to consider */
70 } gmx_domdec_ns_ranges_t;
71
72 typedef struct {
73   /* The number of zones including the home zone */
74   int  n;
75   /* The shift of the zones with respect to the home zone */
76   ivec shift[DD_MAXZONE];
77   /* The charge group boundaries for the zones */
78   int  cg_range[DD_MAXZONE+1];
79   /* The number of neighbor search zones with i-particles */
80   int  nizone;
81   /* The neighbor search charge group ranges for each i-zone */
82   gmx_domdec_ns_ranges_t izone[DD_MAXIZONE];
83 } gmx_domdec_zones_t;
84
85 typedef struct gmx_ga2la *gmx_ga2la_t;
86
87 typedef struct gmx_reverse_top *gmx_reverse_top_p_t;
88
89 typedef struct gmx_domdec_constraints *gmx_domdec_constraints_p_t;
90
91 typedef struct gmx_domdec_specat_comm *gmx_domdec_specat_comm_p_t;
92
93 typedef struct gmx_domdec_comm *gmx_domdec_comm_p_t;
94
95 typedef struct gmx_pme_comm_n_box *gmx_pme_comm_n_box_p_t;
96
97 typedef struct {
98   int  npbcdim;
99   int  nboundeddim;
100   rvec box0;
101   rvec box_size;
102   /* Tells if the box is skewed for each of the three cartesian directions */
103   ivec tric_dir;
104   rvec skew_fac;
105   /* Orthogonal vectors for triclinic cells, Cartesian index */
106   rvec v[DIM][DIM];
107   /* Normal vectors for the cells walls */
108   rvec normal[DIM];
109 } gmx_ddbox_t;
110
111
112 typedef struct {
113   /* these buffers are used as destination buffers if MPI_IN_PLACE isn't
114      supported.*/
115   int *ibuf; /* for ints */
116   int ibuf_alloc;
117
118   gmx_large_int_t *libuf;
119   int libuf_alloc;
120
121   float *fbuf; /* for floats */
122   int fbuf_alloc;
123
124   double *dbuf; /* for doubles */
125   int dbuf_alloc;
126 } mpi_in_place_buf_t;
127
128
129 typedef struct {
130   /* The DD particle-particle nodes only */
131   /* The communication setup within the communicator all
132    * defined in dd->comm in domdec.c
133    */
134   int  nnodes;
135   MPI_Comm mpi_comm_all;
136   /* Use MPI_Sendrecv communication instead of non-blocking calls */
137   gmx_bool bSendRecv2;
138   /* The local DD cell index and rank */
139   ivec ci;
140   int  rank;
141   ivec master_ci;
142   int  masterrank;
143   /* Communication with the PME only nodes */
144   int  pme_nodeid;
145   gmx_bool pme_receive_vir_ener;
146   gmx_pme_comm_n_box_p_t cnb;
147   int  nreq_pme;
148   MPI_Request req_pme[4];
149   
150
151   /* The communication setup, identical for each cell, cartesian index */
152   ivec nc;
153   int  ndim;
154   ivec dim;  /* indexed by 0 to ndim */
155   gmx_bool bGridJump;
156
157   /* PBC from dim 0 to npbcdim */
158   int npbcdim;
159
160   /* Screw PBC? */
161   gmx_bool bScrewPBC;
162
163   /* Forward and backward neighboring cells, indexed by 0 to ndim */
164   int  neighbor[DIM][2];
165
166   /* Only available on the master node */
167   gmx_domdec_master_p_t ma;
168
169   /* Are there inter charge group constraints */
170   gmx_bool bInterCGcons;
171
172   /* Global atom number to interaction list */
173   gmx_reverse_top_p_t reverse_top;
174   int  nbonded_global;
175   int  nbonded_local;
176
177   /* The number of inter charge-group exclusions */
178   int  n_intercg_excl;
179
180   /* Vsite stuff */
181   int  *ga2la_vsite;
182   gmx_domdec_specat_comm_p_t vsite_comm;
183
184   /* Constraint stuff */
185   gmx_domdec_constraints_p_t constraints;
186   gmx_domdec_specat_comm_p_t constraint_comm;
187
188   /* The local to gobal charge group index and local cg to local atom index */
189   int  ncg_home;
190   int  ncg_tot;
191   int  *index_gl;
192   int  *cgindex;
193   int  cg_nalloc;
194   /* Local atom to local cg index, only for special cases */
195   int  *la2lc;
196   int  la2lc_nalloc;
197
198   /* The number of home atoms */
199   int  nat_home;
200   /* The total number of atoms: home and received zones */
201   int  nat_tot;
202   /* Index from the local atoms to the global atoms */
203   int  *gatindex;
204   int  gatindex_nalloc;
205
206   /* Global atom number to local atom number list */
207   gmx_ga2la_t ga2la;
208
209   /* Communication stuff */
210   gmx_domdec_comm_p_t comm;
211
212   /* The partioning count, to keep track of the state */
213   gmx_large_int_t ddp_count;
214
215
216   /* gmx_pme_recv_f buffer */
217   int pme_recv_f_alloc;
218   rvec *pme_recv_f_buf;
219
220 } gmx_domdec_t;
221
222 typedef struct gmx_partdec *gmx_partdec_p_t;
223
224 typedef struct {
225   int nsim;
226   int sim;
227   MPI_Group mpi_group_masters;
228   MPI_Comm mpi_comm_masters;
229   /* these buffers are used as destination buffers if MPI_IN_PLACE isn't
230      supported.*/
231   mpi_in_place_buf_t *mpb;
232 } gmx_multisim_t;
233
234 #define DUTY_PP  (1<<0)
235 #define DUTY_PME (1<<1)
236
237 typedef struct {
238   int      bUse;
239   MPI_Comm comm_intra;
240   int      rank_intra;
241   MPI_Comm comm_inter;
242   
243 } gmx_nodecomm_t;
244
245 typedef struct {
246         int dummy;
247 } gmx_commrec_thread_t;
248
249 typedef struct {
250   /* The nodeids in one sim are numbered sequentially from 0.
251    * All communication within some simulation should happen
252    * in mpi_comm_mysim, or its subset mpi_comm_mygroup.
253    */
254   int sim_nodeid,nnodes,npmenodes;
255
256   /* thread numbers: */
257   /* Not used yet: int threadid, nthreads; */
258   /* The nodeid in the PP/PME, PP or PME group */
259   int nodeid;
260   MPI_Comm mpi_comm_mysim;
261   MPI_Comm mpi_comm_mygroup;
262
263 #ifdef GMX_THREAD_SHM_FDECOMP
264   gmx_commrec_thread_t thread;
265 #endif
266
267   gmx_nodecomm_t nc;
268   
269   /* For domain decomposition */
270   gmx_domdec_t *dd;
271
272   /* For particle decomposition */
273   gmx_partdec_p_t pd;
274
275   /* The duties of this node, see the defines above */
276   int duty;
277
278   gmx_multisim_t *ms;
279
280   /* these buffers are used as destination buffers if MPI_IN_PLACE isn't
281      supported.*/
282   mpi_in_place_buf_t *mpb;
283 } t_commrec;
284
285 #define MASTERNODE(cr)     (((cr)->nodeid == 0) || !PAR(cr))
286   /* #define MASTERTHREAD(cr)   ((cr)->threadid == 0) */
287   /* #define MASTER(cr)         (MASTERNODE(cr) && MASTERTHREAD(cr)) */
288 #define MASTER(cr)         MASTERNODE(cr)
289 #define SIMMASTER(cr)      (MASTER(cr) && ((cr)->duty & DUTY_PP))
290 #define NODEPAR(cr)        ((cr)->nnodes > 1)
291   /* #define THREADPAR(cr)      ((cr)->nthreads > 1) */
292   /* #define PAR(cr)            (NODEPAR(cr) || THREADPAR(cr)) */
293 #define PAR(cr)            NODEPAR(cr)
294 #define RANK(cr,nodeid)    (nodeid)
295 #define MASTERRANK(cr)     (0)
296
297 #define DOMAINDECOMP(cr)   (((cr)->dd != NULL) && PAR(cr))
298 #define DDMASTER(dd)       ((dd)->rank == (dd)->masterrank)
299
300 #define PARTDECOMP(cr)     ((cr)->pd != NULL)
301
302 #define MULTISIM(cr)       ((cr)->ms)
303 #define MSRANK(ms,nodeid)  (nodeid)
304 #define MASTERSIM(ms)      ((ms)->sim == 0)
305
306 /* The master of all (the node that prints the remaining run time etc.) */
307 #define MULTIMASTER(cr)    (SIMMASTER(cr) && (!MULTISIM(cr) || MASTERSIM((cr)->ms)))
308
309 #ifdef __cplusplus
310 }
311 #endif
312 #endif