Fix malformed CUDA version macro check
[alexxy/gromacs.git] / include / domdec.h
1 /*
2  * This file is part of the GROMACS molecular simulation package.
3  *
4  * This file is part of Gromacs        Copyright (c) 1991-2008
5  * David van der Spoel, Erik Lindahl, Berk Hess, University of Groningen.
6  * Copyright (c) 2012,2013, by the GROMACS development team, led by
7  * David van der Spoel, Berk Hess, Erik Lindahl, and including many
8  * others, as listed in the AUTHORS file in the top-level source
9  * 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
38 #ifndef _domdec_h
39 #define _domdec_h
40 #include "visibility.h"
41 #include "typedefs.h"
42 #include "types/commrec.h"
43 #include "vsite.h"
44 #include "genborn.h"
45
46 #ifdef __cplusplus
47 extern "C" {
48 #endif
49
50 int ddglatnr(gmx_domdec_t *dd, int i);
51 /* Returns the global topology atom number belonging to local atom index i.
52  * This function is intended for writing ascii output
53  * and returns atom numbers starting at 1.
54  * When dd=NULL returns i+1.
55  */
56
57 t_block *dd_charge_groups_global(gmx_domdec_t *dd);
58 /* Return a block struct for the charge groups of the whole system */
59
60 gmx_bool dd_filled_nsgrid_home(gmx_domdec_t *dd);
61 /* Is the ns grid already filled with the home particles? */
62
63 void dd_store_state(gmx_domdec_t *dd, t_state *state);
64 /* Store the global cg indices of the home cgs in state,
65  * so it can be reset, even after a new DD partitioning.
66  */
67
68 gmx_domdec_zones_t *domdec_zones(gmx_domdec_t *dd);
69
70 void dd_get_ns_ranges(gmx_domdec_t *dd, int icg,
71                       int *jcg0, int *jcg1, ivec shift0, ivec shift1);
72
73 int dd_natoms_vsite(gmx_domdec_t *dd);
74
75 void dd_get_constraint_range(gmx_domdec_t *dd,
76                              int *at_start, int *at_end);
77
78 real dd_cutoff_mbody(gmx_domdec_t *dd);
79
80 real dd_cutoff_twobody(gmx_domdec_t *dd);
81
82 GMX_LIBMD_EXPORT
83 void get_pme_nnodes(const gmx_domdec_t *dd,
84                     int *npmenodes_x, int *npmenodes_y);
85 /* Get the number of PME nodes along x and y, can be called with dd=NULL */
86
87 gmx_bool gmx_pmeonlynode(t_commrec *cr, int nodeid);
88 /* Return if nodeid in cr->mpi_comm_mysim is a PME-only node */
89
90 void get_pme_ddnodes(t_commrec *cr, int pmenodeid,
91                      int *nmy_ddnodes, int **my_ddnodes, int *node_peer);
92 /* Returns the set of DD nodes that communicate with pme node cr->nodeid */
93
94 int dd_pme_maxshift_x(gmx_domdec_t *dd);
95 /* Returns the maximum shift for coordinate communication in PME, dim x */
96
97 int dd_pme_maxshift_y(gmx_domdec_t *dd);
98 /* Returns the maximum shift for coordinate communication in PME, dim y */
99
100 GMX_LIBMD_EXPORT
101 void make_dd_communicators(FILE *fplog, t_commrec *cr, int dd_node_order);
102
103 GMX_LIBMD_EXPORT
104 gmx_domdec_t *
105 init_domain_decomposition(FILE *fplog,
106                           t_commrec *cr,
107                           unsigned long Flags,
108                           ivec nc,
109                           real comm_distance_min, real rconstr,
110                           const char *dlb_opt, real dlb_scale,
111                           const char *sizex, const char *sizey, const char *sizez,
112                           gmx_mtop_t *mtop, t_inputrec *ir,
113                           matrix box, rvec *x,
114                           gmx_ddbox_t *ddbox,
115                           int *npme_x, int *npme_y);
116
117 GMX_LIBMD_EXPORT
118 void dd_init_bondeds(FILE *fplog,
119                      gmx_domdec_t *dd, gmx_mtop_t *mtop,
120                      gmx_vsite_t *vsite, gmx_constr_t constr,
121                      t_inputrec *ir, gmx_bool bBCheck, cginfo_mb_t *cginfo_mb);
122 /* Initialize data structures for bonded interactions */
123
124 gmx_bool dd_bonded_molpbc(gmx_domdec_t *dd, int ePBC);
125 /* Returns if we need to do pbc for calculating bonded interactions */
126
127 GMX_LIBMD_EXPORT
128 void set_dd_parameters(FILE *fplog, gmx_domdec_t *dd, real dlb_scale,
129                        t_inputrec *ir, t_forcerec *fr,
130                        gmx_ddbox_t *ddbox);
131 /* Set DD grid dimensions and limits,
132  * should be called after calling dd_init_bondeds.
133  */
134
135 GMX_LIBMD_EXPORT
136 gmx_bool change_dd_cutoff(t_commrec *cr, t_state *state, t_inputrec *ir,
137                           real cutoff_req );
138 /* Change the DD non-bonded communication cut-off.
139  * This could fail when trying to increase the cut-off,
140  * then FALSE will be returned and the cut-off is not modified.
141  */
142
143 GMX_LIBMD_EXPORT
144 void change_dd_dlb_cutoff_limit(t_commrec *cr);
145 /* Domain boundary changes due to the DD dynamic load balancing can limit
146  * the cut-off distance that can be set in change_dd_cutoff. This function
147  * limits the DLB such that using the currently set cut-off should still be
148  * possible after subsequently setting a shorter cut-off with change_dd_cutoff.
149  */
150
151 GMX_LIBMD_EXPORT
152 void dd_setup_dlb_resource_sharing(t_commrec *cr,
153                                    const gmx_hw_info_t *hwinfo,
154                                    const gmx_hw_opt_t *hw_opt);
155 /* When domains (PP MPI ranks) share a GPU, the individual GPU wait times
156  * are meaningless, as it depends on the order in which tasks on the same
157  * GPU finish. Therefore there wait times need to be averaged over the ranks
158  * sharing the same GPU. This function sets up the communication for that.
159  */
160
161 GMX_LIBMD_EXPORT
162 void setup_dd_grid(FILE *fplog, gmx_domdec_t *dd);
163
164 void dd_collect_vec(gmx_domdec_t *dd,
165                     t_state *state_local, rvec *lv, rvec *v);
166
167 GMX_LIBMD_EXPORT
168 void dd_collect_state(gmx_domdec_t *dd,
169                       t_state *state_local, t_state *state);
170
171 enum {
172     ddCyclStep, ddCyclPPduringPME, ddCyclF, ddCyclWaitGPU, ddCyclPME, ddCyclNr
173 };
174
175 GMX_LIBMD_EXPORT
176 void dd_cycles_add(gmx_domdec_t *dd, float cycles, int ddCycl);
177 /* Add the wallcycle count to the DD counter */
178
179 void dd_force_flop_start(gmx_domdec_t *dd, t_nrnb *nrnb);
180 /* Start the force flop count */
181
182 void dd_force_flop_stop(gmx_domdec_t *dd, t_nrnb *nrnb);
183 /* Stop the force flop count */
184
185 GMX_LIBMD_EXPORT
186 float dd_pme_f_ratio(gmx_domdec_t *dd);
187 /* Return the PME/PP force load ratio, or -1 if nothing was measured.
188  * Should only be called on the DD master node.
189  */
190
191 void dd_move_x(gmx_domdec_t *dd, matrix box, rvec x[]);
192 /* Communicate the coordinates to the neighboring cells and do pbc. */
193
194 void dd_move_f(gmx_domdec_t *dd, rvec f[], rvec *fshift);
195 /* Sum the forces over the neighboring cells.
196  * When fshift!=NULL the shift forces are updated to obtain
197  * the correct virial from the single sum including f.
198  */
199
200 void dd_atom_spread_real(gmx_domdec_t *dd, real v[]);
201 /* Communicate a real for each atom to the neighboring cells. */
202
203 void dd_atom_sum_real(gmx_domdec_t *dd, real v[]);
204 /* Sum the contributions to a real for each atom over the neighboring cells. */
205
206 GMX_LIBMD_EXPORT
207 void dd_partition_system(FILE                *fplog,
208                          gmx_large_int_t      step,
209                          t_commrec           *cr,
210                          gmx_bool             bMasterState,
211                          int                  nstglobalcomm,
212                          t_state             *state_global,
213                          gmx_mtop_t          *top_global,
214                          t_inputrec          *ir,
215                          t_state             *state_local,
216                          rvec               **f,
217                          t_mdatoms           *mdatoms,
218                          gmx_localtop_t      *top_local,
219                          t_forcerec          *fr,
220                          gmx_vsite_t         *vsite,
221                          gmx_shellfc_t        shellfc,
222                          gmx_constr_t         constr,
223                          t_nrnb              *nrnb,
224                          gmx_wallcycle_t      wcycle,
225                          gmx_bool             bVerbose);
226 /* Partition the system over the nodes.
227  * step is only used for printing error messages.
228  * If bMasterState==TRUE then state_global from the master node is used,
229  * else state_local is redistributed between the nodes.
230  * When f!=NULL, *f will be reallocated to the size of state_local.
231  */
232
233 GMX_LIBMD_EXPORT
234 void reset_dd_statistics_counters(gmx_domdec_t *dd);
235 /* Reset all the statistics and counters for total run counting */
236
237 void print_dd_statistics(t_commrec *cr, t_inputrec *ir, FILE *fplog);
238
239 /* In domdec_con.c */
240
241 void dd_move_f_vsites(gmx_domdec_t *dd, rvec *f, rvec *fshift);
242
243 void dd_clear_f_vsites(gmx_domdec_t *dd, rvec *f);
244
245 void dd_move_x_constraints(gmx_domdec_t *dd, matrix box,
246                            rvec *x0, rvec *x1, gmx_bool bX1IsCoord);
247 /* Move x0 and also x1 if x1!=NULL. bX1IsCoord tells if to do PBC on x1 */
248
249 void dd_move_x_vsites(gmx_domdec_t *dd, matrix box, rvec *x);
250
251 int *dd_constraints_nlocalatoms(gmx_domdec_t *dd);
252
253 void dd_clear_local_constraint_indices(gmx_domdec_t *dd);
254
255 void dd_clear_local_vsite_indices(gmx_domdec_t *dd);
256
257 int dd_make_local_vsites(gmx_domdec_t *dd, int at_start, t_ilist *lil);
258
259 int dd_make_local_constraints(gmx_domdec_t *dd, int at_start,
260                               const gmx_mtop_t *mtop,
261                               const int *cginfo,
262                               gmx_constr_t constr, int nrec,
263                               t_ilist *il_local);
264
265 void init_domdec_constraints(gmx_domdec_t *dd,
266                              gmx_mtop_t   *mtop,
267                              gmx_constr_t  constr);
268
269 void init_domdec_vsites(gmx_domdec_t *dd, int n_intercg_vsite);
270
271
272 /* In domdec_top.c */
273
274 void dd_print_missing_interactions(FILE *fplog, t_commrec *cr,
275                                    int local_count,  gmx_mtop_t *top_global, t_state *state_local);
276
277 void dd_make_reverse_top(FILE *fplog,
278                          gmx_domdec_t *dd, gmx_mtop_t *mtop,
279                          gmx_vsite_t *vsite, gmx_constr_t constr,
280                          t_inputrec *ir, gmx_bool bBCheck);
281
282 void dd_make_local_cgs(gmx_domdec_t *dd, t_block *lcgs);
283
284 void dd_make_local_top(FILE *fplog,
285                        gmx_domdec_t *dd, gmx_domdec_zones_t *zones,
286                        int npbcdim, matrix box,
287                        rvec cellsize_min, ivec npulse,
288                        t_forcerec *fr,
289                        rvec *cgcm_or_x,
290                        gmx_vsite_t *vsite,
291                        gmx_mtop_t *top, gmx_localtop_t *ltop);
292
293 void dd_sort_local_top(gmx_domdec_t *dd, t_mdatoms *mdatoms,
294                        gmx_localtop_t *ltop);
295 /* Sort ltop->ilist when we are doing free energy. */
296
297 GMX_LIBMD_EXPORT
298 gmx_localtop_t *dd_init_local_top(gmx_mtop_t *top_global);
299
300 GMX_LIBMD_EXPORT
301 void dd_init_local_state(gmx_domdec_t *dd,
302                          t_state *state_global, t_state *local_state);
303
304 t_blocka *make_charge_group_links(gmx_mtop_t *mtop, gmx_domdec_t *dd,
305                                   cginfo_mb_t *cginfo_mb);
306
307 void dd_bonded_cg_distance(FILE *fplog,
308                            gmx_domdec_t *dd, gmx_mtop_t *mtop,
309                            t_inputrec *ir, rvec *x, matrix box,
310                            gmx_bool bBCheck,
311                            real *r_2b, real *r_mb);
312
313 void write_dd_pdb(const char *fn, gmx_large_int_t step, const char *title,
314                   gmx_mtop_t *mtop,
315                   t_commrec *cr,
316                   int natoms, rvec x[], matrix box);
317 /* Dump a pdb file with the current DD home + communicated atoms.
318  * When natoms=-1, dump all known atoms.
319  */
320
321
322 /* In domdec_setup.c */
323
324 real comm_box_frac(ivec dd_nc, real cutoff, gmx_ddbox_t *ddbox);
325 /* Returns the volume fraction of the system that is communicated */
326
327 real dd_choose_grid(FILE *fplog,
328                     t_commrec *cr, gmx_domdec_t *dd, t_inputrec *ir,
329                     gmx_mtop_t *mtop, matrix box, gmx_ddbox_t *ddbox,
330                     gmx_bool bDynLoadBal, real dlb_scale,
331                     real cellsize_limit, real cutoff_dd,
332                     gmx_bool bInterCGBondeds, gmx_bool bInterCGMultiBody);
333 /* Determines the optimal DD cell setup dd->nc and possibly npmenodes
334  * for the system.
335  * On the master node returns the actual cellsize limit used.
336  */
337
338
339 /* In domdec_box.c */
340
341 void set_ddbox(gmx_domdec_t *dd, gmx_bool bMasterState, t_commrec *cr_sum,
342                t_inputrec *ir, matrix box,
343                gmx_bool bCalcUnboundedSize, t_block *cgs, rvec *x,
344                gmx_ddbox_t *ddbox);
345
346 void set_ddbox_cr(t_commrec *cr, ivec *dd_nc,
347                   t_inputrec *ir, matrix box, t_block *cgs, rvec *x,
348                   gmx_ddbox_t *ddbox);
349
350 #ifdef __cplusplus
351 }
352 #endif
353
354 #endif  /* _domdec_h */