Disable OpenMP for llvm-gcc 4.2.x
[gromacs.git] / include / mdrun.h
bloba3de0379bd99efd4909b5c25326714c3df8116d0
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.
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.
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.
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.
30 * For more info, check our website at http://www.gromacs.org
32 * And Hey:
33 * Gromacs Runs On Most of All Computer Systems
36 #ifndef _mdrun_h
37 #define _mdrun_h
39 #include <stdio.h>
40 #include <time.h>
41 #include "typedefs.h"
42 #include "network.h"
43 #include "tgroup.h"
44 #include "filenm.h"
45 #include "mshift.h"
46 #include "force.h"
47 #include "edsam.h"
48 #include "mdebin.h"
49 #include "vcm.h"
50 #include "vsite.h"
51 #include "pull.h"
52 #include "update.h"
54 #ifdef __cplusplus
55 extern "C" {
56 #endif
58 #define MD_POLARISE (1<<2)
59 #define MD_IONIZE (1<<3)
60 #define MD_RERUN (1<<4)
61 #define MD_RERUN_VSITE (1<<5)
62 #define MD_FFSCAN (1<<6)
63 #define MD_SEPPOT (1<<7)
64 #define MD_PARTDEC (1<<9)
65 #define MD_DDBONDCHECK (1<<10)
66 #define MD_DDBONDCOMM (1<<11)
67 #define MD_CONFOUT (1<<12)
68 #define MD_REPRODUCIBLE (1<<13)
69 #define MD_READ_RNG (1<<14)
70 #define MD_APPENDFILES (1<<15)
71 #define MD_APPENDFILESSET (1<<21)
72 #define MD_KEEPANDNUMCPT (1<<16)
73 #define MD_READ_EKIN (1<<17)
74 #define MD_STARTFROMCPT (1<<18)
75 #define MD_RESETCOUNTERSHALFWAY (1<<19)
77 /* Define a number of flags to better control the information
78 * passed to compute_globals in md.c and global_stat.
81 /* We are rerunning the simulation */
82 #define CGLO_RERUNMD (1<<1)
83 /* we are computing the kinetic energy from average velocities */
84 #define CGLO_EKINAVEVEL (1<<2)
85 /* we are removing the center of mass momenta */
86 #define CGLO_STOPCM (1<<3)
87 /* bGStat is defined in do_md */
88 #define CGLO_GSTAT (1<<4)
89 /* Sum the energy terms in global computation */
90 #define CGLO_ENERGY (1<<6)
91 /* Sum the kinetic energy terms in global computation */
92 #define CGLO_TEMPERATURE (1<<7)
93 /* Sum the kinetic energy terms in global computation */
94 #define CGLO_PRESSURE (1<<8)
95 /* Sum the constraint term in global computation */
96 #define CGLO_CONSTRAINT (1<<9)
97 /* we are using an integrator that requires iteration over some steps - currently not used*/
98 #define CGLO_ITERATE (1<<10)
99 /* it is the first time we are iterating (or, only once through is required */
100 #define CGLO_FIRSTITERATE (1<<11)
101 /* Reading ekin from the trajectory */
102 #define CGLO_READEKIN (1<<12)
103 /* we need to reset the ekin rescaling factor here */
104 #define CGLO_SCALEEKIN (1<<13)
106 enum {
107 ddnoSEL, ddnoINTERLEAVE, ddnoPP_PME, ddnoCARTESIAN, ddnoNR
110 typedef struct {
111 double real;
112 #ifdef GMX_CRAY_XT3
113 double proc;
114 #else
115 clock_t proc;
116 #endif
117 double realtime;
118 double proctime;
119 double time_per_step;
120 double last;
121 gmx_large_int_t nsteps_done;
122 } gmx_runtime_t;
124 typedef struct {
125 t_fileio *fp_trn;
126 t_fileio *fp_xtc;
127 int xtc_prec;
128 ener_file_t fp_ene;
129 const char *fn_cpt;
130 gmx_bool bKeepAndNumCPT;
131 int eIntegrator;
132 int simulation_part;
133 FILE *fp_dhdl;
134 FILE *fp_field;
135 } gmx_mdoutf_t;
137 /* Variables for temporary use with the deform option,
138 * used in runner.c and md.c.
139 * (These variables should be stored in the tpx file.)
141 extern gmx_large_int_t deform_init_init_step_tpx;
142 extern matrix deform_init_box_tpx;
143 #ifdef GMX_THREAD_MPI
144 extern tMPI_Thread_mutex_t deform_init_box_mutex;
146 /* The minimum number of atoms per thread. With fewer atoms than this,
147 * the number of threads will get lowered.
149 #define MIN_ATOMS_PER_THREAD 90
150 #endif
153 typedef double gmx_integrator_t(FILE *log,t_commrec *cr,
154 int nfile,const t_filenm fnm[],
155 const output_env_t oenv, gmx_bool bVerbose,
156 gmx_bool bCompact, int nstglobalcomm,
157 gmx_vsite_t *vsite,gmx_constr_t constr,
158 int stepout,
159 t_inputrec *inputrec,
160 gmx_mtop_t *mtop,t_fcdata *fcd,
161 t_state *state,
162 t_mdatoms *mdatoms,
163 t_nrnb *nrnb,gmx_wallcycle_t wcycle,
164 gmx_edsam_t ed,
165 t_forcerec *fr,
166 int repl_ex_nst,int repl_ex_seed,
167 real cpt_period,real max_hours,
168 const char *deviceOptions,
169 unsigned long Flags,
170 gmx_runtime_t *runtime);
172 typedef struct gmx_global_stat *gmx_global_stat_t;
174 /* ROUTINES from md.c */
176 gmx_integrator_t do_md;
178 gmx_integrator_t do_md_openmm;
182 /* ROUTINES from minimize.c */
184 gmx_integrator_t do_steep;
185 /* Do steepest descents EM */
187 gmx_integrator_t do_cg;
188 /* Do conjugate gradient EM */
190 gmx_integrator_t do_lbfgs;
191 /* Do conjugate gradient L-BFGS */
193 gmx_integrator_t do_nm;
194 /* Do normal mode analysis */
196 /* ROUTINES from tpi.c */
198 gmx_integrator_t do_tpi;
199 /* Do test particle insertion */
202 /* ROUTINES from md_support.c */
204 /* return the number of steps between global communcations */
205 int check_nstglobalcomm(FILE *fplog,t_commrec *cr,
206 int nstglobalcomm,t_inputrec *ir);
208 /* check whether an 'nst'-style parameter p is a multiple of nst, and
209 set it to be one if not, with a warning. */
210 void check_nst_param(FILE *fplog,t_commrec *cr,
211 const char *desc_nst,int nst,
212 const char *desc_p,int *p);
214 /* check which of the multisim simulations has the shortest number of
215 steps and return that number of nsteps */
216 gmx_large_int_t get_multisim_nsteps(const t_commrec *cr,
217 gmx_large_int_t nsteps);
219 void rerun_parallel_comm(t_commrec *cr,t_trxframe *fr,
220 gmx_bool *bNotLastFrame);
222 /* get the conserved energy associated with the ensemble type*/
223 real compute_conserved_from_auxiliary(t_inputrec *ir, t_state *state,
224 t_extmass *MassQ);
226 /* reset all cycle and time counters. */
227 void reset_all_counters(FILE *fplog,t_commrec *cr,
228 gmx_large_int_t step,
229 gmx_large_int_t *step_rel,t_inputrec *ir,
230 gmx_wallcycle_t wcycle,t_nrnb *nrnb,
231 gmx_runtime_t *runtime);
235 /* ROUTINES from sim_util.c */
236 void do_pbc_first(FILE *log,matrix box,t_forcerec *fr,
237 t_graph *graph,rvec x[]);
239 void do_pbc_first_mtop(FILE *fplog,int ePBC,matrix box,
240 gmx_mtop_t *mtop,rvec x[]);
242 void do_pbc_mtop(FILE *fplog,int ePBC,matrix box,
243 gmx_mtop_t *mtop,rvec x[]);
247 /* ROUTINES from stat.c */
248 gmx_global_stat_t global_stat_init(t_inputrec *ir);
250 void global_stat_destroy(gmx_global_stat_t gs);
252 void global_stat(FILE *log,gmx_global_stat_t gs,
253 t_commrec *cr,gmx_enerdata_t *enerd,
254 tensor fvir,tensor svir,rvec mu_tot,
255 t_inputrec *inputrec,
256 gmx_ekindata_t *ekind,
257 gmx_constr_t constr,t_vcm *vcm,
258 int nsig,real *sig,
259 gmx_mtop_t *top_global, t_state *state_local,
260 gmx_bool bSumEkinhOld, int flags);
261 /* Communicate statistics over cr->mpi_comm_mysim */
263 gmx_mdoutf_t *init_mdoutf(int nfile,const t_filenm fnm[],
264 int mdrun_flags,
265 const t_commrec *cr,const t_inputrec *ir,
266 const output_env_t oenv);
267 /* Returns a pointer to a data structure with all output file pointers
268 * and names required by mdrun.
271 void done_mdoutf(gmx_mdoutf_t *of);
272 /* Close all open output files and free the of pointer */
274 #define MDOF_X (1<<0)
275 #define MDOF_V (1<<1)
276 #define MDOF_F (1<<2)
277 #define MDOF_XTC (1<<3)
278 #define MDOF_CPT (1<<4)
280 void write_traj(FILE *fplog,t_commrec *cr,
281 gmx_mdoutf_t *of,
282 int mdof_flags,
283 gmx_mtop_t *top_global,
284 gmx_large_int_t step,double t,
285 t_state *state_local,t_state *state_global,
286 rvec *f_local,rvec *f_global,
287 int *n_xtc,rvec **x_xtc);
288 /* Routine that writes frames to trn, xtc and/or checkpoint.
289 * What is written is determined by the mdof_flags defined above.
290 * Data is collected to the master node only when necessary.
293 int do_per_step(gmx_large_int_t step,gmx_large_int_t nstep);
294 /* Return TRUE if io should be done */
296 int do_any_io(int step, t_inputrec *ir);
298 /* ROUTINES from sim_util.c */
300 double gmx_gettime();
302 void print_time(FILE *out, gmx_runtime_t *runtime,
303 gmx_large_int_t step,t_inputrec *ir, t_commrec *cr);
305 void runtime_start(gmx_runtime_t *runtime);
307 void runtime_end(gmx_runtime_t *runtime);
309 void runtime_upd_proc(gmx_runtime_t *runtime);
310 /* The processor time should be updated every once in a while,
311 * since on 32-bit manchines it loops after 72 minutes.
314 void print_date_and_time(FILE *log,int pid,const char *title,
315 const gmx_runtime_t *runtime);
317 void nstop_cm(FILE *log,t_commrec *cr,
318 int start,int nr_atoms,real mass[],rvec x[],rvec v[]);
320 void finish_run(FILE *log,t_commrec *cr,const char *confout,
321 t_inputrec *inputrec,
322 t_nrnb nrnb[],gmx_wallcycle_t wcycle,
323 gmx_runtime_t *runtime,
324 gmx_bool bWriteStat);
326 void calc_enervirdiff(FILE *fplog,int eDispCorr,t_forcerec *fr);
328 void calc_dispcorr(FILE *fplog,t_inputrec *ir,t_forcerec *fr,
329 gmx_large_int_t step, int natoms,
330 matrix box,real lambda,tensor pres,tensor virial,
331 real *prescorr, real *enercorr, real *dvdlcorr);
333 typedef enum
335 LIST_SCALARS =0001,
336 LIST_INPUTREC =0002,
337 LIST_TOP =0004,
338 LIST_X =0010,
339 LIST_V =0020,
340 LIST_F =0040,
341 LIST_LOAD =0100
342 } t_listitem;
344 void check_nnodes_top(char *fn,t_topology *top);
345 /* Reset the tpr file to work with one node if necessary */
348 /* check the version */
349 void check_ir_old_tpx_versions(t_commrec *cr,FILE *fplog,
350 t_inputrec *ir,gmx_mtop_t *mtop);
352 /* Allocate and initialize node-local state entries. */
353 void set_state_entries(t_state *state,const t_inputrec *ir,int nnodes);
355 /* Broadcast the data for a simulation, and allocate node-specific settings
356 such as rng generators. */
357 void init_parallel(FILE *log, t_commrec *cr, t_inputrec *inputrec,
358 gmx_mtop_t *mtop);
361 void do_constrain_first(FILE *log,gmx_constr_t constr,
362 t_inputrec *inputrec,t_mdatoms *md,
363 t_state *state,rvec *f,
364 t_graph *graph,t_commrec *cr,t_nrnb *nrnb,
365 t_forcerec *fr, gmx_localtop_t *top, tensor shake_vir);
367 void dynamic_load_balancing(gmx_bool bVerbose,t_commrec *cr,real capacity[],
368 int dimension,t_mdatoms *md,t_topology *top,
369 rvec x[],rvec v[],matrix box);
370 /* Perform load balancing, i.e. split the particles over processors
371 * based on their coordinates in the "dimension" direction.
374 int multisim_min(const gmx_multisim_t *ms,int nmin,int n);
375 /* Set an appropriate value for n across the whole multi-simulation */
377 int multisim_nstsimsync(const t_commrec *cr,
378 const t_inputrec *ir,int repl_ex_nst);
379 /* Determine the interval for inter-simulation communication */
381 void init_global_signals(globsig_t *gs,const t_commrec *cr,
382 const t_inputrec *ir,int repl_ex_nst);
383 /* Constructor for globsig_t */
385 void copy_coupling_state(t_state *statea,t_state *stateb,
386 gmx_ekindata_t *ekinda,gmx_ekindata_t *ekindb, t_grpopts* opts);
387 /* Copy stuff from state A to state B */
389 void compute_globals(FILE *fplog, gmx_global_stat_t gstat, t_commrec *cr, t_inputrec *ir,
390 t_forcerec *fr, gmx_ekindata_t *ekind,
391 t_state *state, t_state *state_global, t_mdatoms *mdatoms,
392 t_nrnb *nrnb, t_vcm *vcm, gmx_wallcycle_t wcycle,
393 gmx_enerdata_t *enerd,tensor force_vir, tensor shake_vir, tensor total_vir,
394 tensor pres, rvec mu_tot, gmx_constr_t constr,
395 globsig_t *gs,gmx_bool bInterSimGS,
396 matrix box, gmx_mtop_t *top_global, real *pcurr,
397 int natoms, gmx_bool *bSumEkinhOld, int flags);
398 /* Compute global variables during integration */
400 int mdrunner(int nthreads_requested, FILE *fplog,t_commrec *cr,int nfile,
401 const t_filenm fnm[], const output_env_t oenv, gmx_bool bVerbose,
402 gmx_bool bCompact, int nstglobalcomm, ivec ddxyz,int dd_node_order,
403 real rdd, real rconstr, const char *dddlb_opt,real dlb_scale,
404 const char *ddcsx,const char *ddcsy,const char *ddcsz,
405 int nstepout, int resetstep, int nmultisim, int repl_ex_nst,
406 int repl_ex_seed, real pforce,real cpt_period,real max_hours,
407 const char *deviceOptions, unsigned long Flags);
408 /* Driver routine, that calls the different methods */
410 void md_print_warning(const t_commrec *cr,FILE *fplog,const char *buf);
411 /* Print a warning message to stderr on the master node
412 * and to fplog if fplog!=NULL.
415 void init_md(FILE *fplog,
416 t_commrec *cr,t_inputrec *ir, const output_env_t oenv,
417 double *t,double *t0,
418 real *lambda,double *lam0,
419 t_nrnb *nrnb,gmx_mtop_t *mtop,
420 gmx_update_t *upd,
421 int nfile,const t_filenm fnm[],
422 gmx_mdoutf_t **outf,t_mdebin **mdebin,
423 tensor force_vir,tensor shake_vir,
424 rvec mu_tot,
425 gmx_bool *bSimAnn,t_vcm **vcm,
426 t_state *state, unsigned long Flags);
427 /* Routine in sim_util.c */
429 #ifdef __cplusplus
431 #endif
433 #endif /* _mdrun_h */