Update copyright statements and change license to LGPL
[alexxy/gromacs.git] / src / kernel / compute_io.c
1 /*
2  * This file is part of the GROMACS molecular simulation package.
3  *
4  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
5  * Copyright (c) 2001-2004, The GROMACS development team,
6  * check out http://www.gromacs.org for more information.
7  * Copyright (c) 2012, by the GROMACS development team, led by
8  * David van der Spoel, Berk Hess, Erik Lindahl, and including many
9  * others, as listed in the AUTHORS file in the top-level source
10  * directory and at http://www.gromacs.org.
11  *
12  * GROMACS is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU Lesser General Public License
14  * as published by the Free Software Foundation; either version 2.1
15  * of the License, or (at your option) any later version.
16  *
17  * GROMACS is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
20  * Lesser General Public License for more details.
21  *
22  * You should have received a copy of the GNU Lesser General Public
23  * License along with GROMACS; if not, see
24  * http://www.gnu.org/licenses, or write to the Free Software Foundation,
25  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
26  *
27  * If you want to redistribute modifications to GROMACS, please
28  * consider that scientific software is very special. Version
29  * control is crucial - bugs must be traceable. We will be happy to
30  * consider code for inclusion in the official distribution, but
31  * derived work must not be called official GROMACS. Details are found
32  * in the README & COPYING files - if they are missing, get the
33  * official version at http://www.gromacs.org.
34  *
35  * To help us fund GROMACS development, we humbly ask that you cite
36  * the research papers on the package. Check out http://www.gromacs.org.
37  */
38 #ifdef HAVE_CONFIG_H
39 #include <config.h>
40 #endif
41
42 #include <signal.h>
43 #include <stdlib.h>
44 #include "typedefs.h"
45 #include "compute_io.h"
46
47 static int div_nsteps(int nsteps,int nst)
48 {
49     if (nst > 0)
50     {
51         return (1 + nsteps + nst - 1)/nst;
52     }
53     else
54     {
55         return 0;
56     }
57 }
58
59 double compute_io(t_inputrec *ir,int natoms,gmx_groups_t *groups,
60                   int nrener,int nrepl)
61 {
62
63     int nsteps = ir->nsteps;
64     int i,nxtcatoms=0;
65     int nstx,nstv,nstf,nste,nstlog,nstxtc,nfep=0;
66     double cio;
67
68     nstx   = div_nsteps(nsteps,ir->nstxout);
69     nstv   = div_nsteps(nsteps,ir->nstvout);
70     nstf   = div_nsteps(nsteps,ir->nstfout);
71     nstxtc = div_nsteps(nsteps,ir->nstxtcout);
72     if (ir->nstxtcout > 0)
73     {
74         for(i=0; i<natoms; i++)
75         {
76             if (groups->grpnr[egcXTC] == NULL || groups->grpnr[egcXTC][i] == 0)
77             {
78                 nxtcatoms++;
79             }
80         }
81     }
82     nstlog = div_nsteps(nsteps,ir->nstlog);
83     /* We add 2 for the header */
84     nste   = div_nsteps(2+nsteps,ir->nstenergy);
85
86     cio  = 80*natoms;
87     cio += (nstx+nstf+nstv)*sizeof(real)*(3.0*natoms);
88     cio += nstxtc*(14*4 + nxtcatoms*5.0); /* roughly 5 bytes per atom */
89     cio += nstlog*(nrener*16*2.0); /* 16 bytes per energy term plus header */
90     /* t_energy contains doubles, but real is written to edr */
91     cio += (1.0*nste)*nrener*3*sizeof(real);
92
93     if ((ir->efep != efepNO || ir->bSimTemp) && (ir->fepvals->nstdhdl > 0))
94     {
95         int ndh=ir->fepvals->n_lambda;
96         int ndhdl=0;
97         int nchars=0;
98
99         for (i=0;i<efptNR;i++)
100         {
101             if (ir->fepvals->separate_dvdl[i])
102             {
103                 ndhdl+=1;
104             }
105         }
106
107         if (ir->fepvals->separate_dhdl_file==esepdhdlfileYES)
108         {
109             nchars = 8 + ndhdl*8 + ndh*10; /* time data ~8 chars/entry, dH data ~10 chars/entry */
110             if (ir->expandedvals->elmcmove > elmcmoveNO)
111             {
112                 nchars += 5;   /* alchemical state */
113             }
114             
115             if (ir->fepvals->bPrintEnergy)
116             {
117                 nchars += 12; /* energy for dhdl */
118             }
119             cio += div_nsteps(nsteps,ir->fepvals->nstdhdl)*nchars; 
120         }
121         else
122         {
123             /* dH output to ener.edr: */
124             if (ir->fepvals->dh_hist_size <= 0)
125             {
126                 int ndh_tot = ndh+ndhdl;
127                 if (ir->expandedvals->elmcmove > elmcmoveNO)
128                 {
129                     ndh_tot += 1;
130                 }
131                 if (ir->fepvals->bPrintEnergy)
132                 {
133                     ndh_tot += 1;
134                 }
135                 /* as data blocks: 1 real per dH point */
136                 cio += div_nsteps(nsteps,ir->fepvals->nstdhdl)*(ndh+ndhdl)*sizeof(real);
137             }
138             else
139             {
140                 /* as histograms: dh_hist_size ints per histogram */
141                 cio += div_nsteps(nsteps,ir->nstenergy)*
142                     sizeof(int)*ir->fepvals->dh_hist_size*ndh;
143             }
144         }
145     }
146     if (ir->pull != NULL)
147     {
148         cio += div_nsteps(nsteps,ir->pull->nstxout)*20; /* roughly 20 chars per line */
149         cio += div_nsteps(nsteps,ir->pull->nstfout)*20; /* roughly 20 chars per line */
150     }    
151
152     return cio*nrepl/(1024*1024);
153 }