Merge branch 'release-4-6' (incl. AdResS Patch)
[alexxy/gromacs.git] / src / gromacs / gmxpreprocess / compute_io.c
1 /* -*- mode: c; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; c-file-style: "stroustrup"; -*-
2  *
3  * 
4  *                This source code is part of
5  * 
6  *                 G   R   O   M   A   C   S
7  * 
8  *          GROningen MAchine for Chemical Simulations
9  * 
10  *                        VERSION 3.2.0
11  * Written by David van der Spoel, Erik Lindahl, Berk Hess, and others.
12  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
13  * Copyright (c) 2001-2004, The GROMACS development team,
14  * check out http://www.gromacs.org for more information.
15
16  * This program is free software; you can redistribute it and/or
17  * modify it under the terms of the GNU General Public License
18  * as published by the Free Software Foundation; either version 2
19  * of the License, or (at your option) any later version.
20  * 
21  * If you want to redistribute modifications, please consider that
22  * scientific software is very special. Version control is crucial -
23  * bugs must be traceable. We will be happy to consider code for
24  * inclusion in the official distribution, but derived work must not
25  * be called official GROMACS. Details are found in the README & COPYING
26  * files - if they are missing, get the official version at www.gromacs.org.
27  * 
28  * To help us fund GROMACS development, we humbly ask that you cite
29  * the papers on the package - you can find them in the top README file.
30  * 
31  * For more info, check our website at http://www.gromacs.org
32  * 
33  * And Hey:
34  * Gallium Rubidium Oxygen Manganese Argon Carbon Silicon
35  */
36 #ifdef HAVE_CONFIG_H
37 #include <config.h>
38 #endif
39
40 #include <signal.h>
41 #include <stdlib.h>
42 #include "typedefs.h"
43
44 static int div_nsteps(int nsteps,int nst)
45 {
46     if (nst > 0)
47     {
48         return (1 + nsteps + nst - 1)/nst;
49     }
50     else
51     {
52         return 0;
53     }
54 }
55
56 double compute_io(t_inputrec *ir,int natoms,gmx_groups_t *groups,
57                   int nrener,int nrepl)
58 {
59   int nsteps = ir->nsteps;
60   int i,nxtcatoms=0;
61   int nstx,nstv,nstf,nste,nstlog,nstxtc,nfep=0;
62   double cio;
63   
64     nstx   = div_nsteps(nsteps,ir->nstxout);
65     nstv   = div_nsteps(nsteps,ir->nstvout);
66     nstf   = div_nsteps(nsteps,ir->nstfout);
67     nstxtc = div_nsteps(nsteps,ir->nstxtcout);
68     if (ir->nstxtcout > 0)
69     {
70         for(i=0; i<natoms; i++)
71         {
72             if (groups->grpnr[egcXTC] == NULL || groups->grpnr[egcXTC][i] == 0)
73             {
74                 nxtcatoms++;
75             }
76         }
77     }
78     nstlog = div_nsteps(nsteps,ir->nstlog);
79     /* We add 2 for the header */
80     nste   = div_nsteps(2+nsteps,ir->nstenergy);
81
82   cio  = 80*natoms;
83   cio += (nstx+nstf+nstv)*sizeof(real)*(3.0*natoms);
84   cio += nstxtc*(14*4 + nxtcatoms*5.0); /* roughly 5 bytes per atom */
85   cio += nstlog*(nrener*16*2.0); /* 16 bytes per energy term plus header */
86   /* t_energy contains doubles, but real is written to edr */
87   cio += (1.0*nste)*nrener*3*sizeof(real);
88   
89   if (ir->efep != efepNO) {
90       int ndh=ir->n_flambda;
91       if (ir->dhdl_derivatives == dhdlderivativesYES)
92       {
93           ndh += 1;
94       }   
95       if (ir->separate_dhdl_file==sepdhdlfileYES)
96       {
97           int nchars = 8 + ndh*10; /* time data ~8 chars/line,
98                                         dH data ~10 chars/line */
99           cio += div_nsteps(nsteps,ir->nstdhdl)*nchars;
100       }
101       else
102       {
103           /* dH output to ener.edr: */
104           if (ir->dh_hist_size <= 0) 
105           {
106               /* as data blocks: 1 real per dH point */
107               cio += div_nsteps(nsteps,ir->nstenergy)*ndh*sizeof(real); 
108           }
109           else
110           {
111               /* as histograms: dh_hist_size ints per histogram */
112               cio += div_nsteps(nsteps,ir->nstenergy)*
113                         sizeof(int)*ir->dh_hist_size*ndh;
114           }
115       }
116   }
117     if (ir->pull != NULL)
118     {
119         cio += div_nsteps(nsteps,ir->pull->nstxout)*20; /* roughly 20 chars per line */
120         cio += div_nsteps(nsteps,ir->pull->nstfout)*20; /* roughly 20 chars per line */
121     }
122
123   return cio*nrepl/(1024*1024);
124 }