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