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