32969441c1e0a54bd1bac2fe950fa99ca720bae9
[alexxy/gromacs.git] / src / gromacs / mdlib / compute_io.cpp
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  * Copyright (c) 2012,2014,2015,2017,2018,2019, by the GROMACS development team, led by
7  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
8  * and including many others, as listed in the AUTHORS file in the
9  * top-level source 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 #include "gmxpre.h"
38
39 #include "compute_io.h"
40
41 #include <csignal>
42 #include <cstdlib>
43
44 #include "gromacs/mdtypes/inputrec.h"
45 #include "gromacs/mdtypes/md_enums.h"
46 #include "gromacs/mdtypes/pull_params.h"
47 #include "gromacs/topology/topology.h"
48
49 static int div_nsteps(int nsteps, int nst)
50 {
51     if (nst > 0)
52     {
53         return (1 + nsteps + nst - 1) / nst;
54     }
55     else
56     {
57         return 0;
58     }
59 }
60
61 double compute_io(const t_inputrec* ir, int natoms, const SimulationGroups& groups, int nrener, int nrepl)
62 {
63
64     int    nsteps = ir->nsteps;
65     int    i, nxtcatoms = 0;
66     int    nstx, nstv, nstf, nste, nstlog, nstxtc;
67     double cio;
68
69     nstx   = div_nsteps(nsteps, ir->nstxout);
70     nstv   = div_nsteps(nsteps, ir->nstvout);
71     nstf   = div_nsteps(nsteps, ir->nstfout);
72     nstxtc = div_nsteps(nsteps, ir->nstxout_compressed);
73     if (ir->nstxout_compressed > 0)
74     {
75         for (int i = 0; i < natoms; i++)
76         {
77             if (groups.groupNumbers[SimulationAtomGroupType::CompressedPositionOutput].empty()
78                 || groups.groupNumbers[SimulationAtomGroupType::CompressedPositionOutput][i] == 0)
79             {
80                 nxtcatoms++;
81             }
82         }
83     }
84     nstlog = div_nsteps(nsteps, ir->nstlog);
85     /* We add 2 for the header */
86     nste = div_nsteps(2 + nsteps, ir->nstenergy);
87
88     cio = 80 * natoms;
89     cio += (nstx + nstf + nstv) * sizeof(real) * (3.0 * natoms);
90     cio += nstxtc * (14 * 4 + nxtcatoms * 5.0); /* roughly 5 bytes per atom */
91     cio += nstlog * (nrener * 16 * 2.0);        /* 16 bytes per energy term plus header */
92     /* t_energy contains doubles, but real is written to edr */
93     cio += (1.0 * nste) * nrener * 3 * sizeof(real);
94
95     if ((ir->efep != efepNO || ir->bSimTemp) && (ir->fepvals->nstdhdl > 0))
96     {
97         int ndh    = ir->fepvals->n_lambda;
98         int ndhdl  = 0;
99         int nchars = 0;
100
101         for (i = 0; i < efptNR; i++)
102         {
103             if (ir->fepvals->separate_dvdl[i])
104             {
105                 ndhdl += 1;
106             }
107         }
108
109         if (ir->fepvals->separate_dhdl_file == esepdhdlfileYES)
110         {
111             nchars = 8 + ndhdl * 8 + ndh * 10; /* time data ~8 chars/entry, dH data ~10 chars/entry */
112             if (ir->expandedvals->elmcmove > elmcmoveNO)
113             {
114                 nchars += 5; /* alchemical state */
115             }
116
117             if (ir->fepvals->edHdLPrintEnergy != edHdLPrintEnergyNO)
118             {
119                 nchars += 12; /* energy for dhdl */
120             }
121             cio += div_nsteps(nsteps, ir->fepvals->nstdhdl) * nchars;
122         }
123         else
124         {
125             /* dH output to ener.edr: */
126             if (ir->fepvals->dh_hist_size <= 0)
127             {
128                 int ndh_tot = ndh + ndhdl;
129                 if (ir->expandedvals->elmcmove > elmcmoveNO)
130                 {
131                     ndh_tot += 1;
132                 }
133                 if (ir->fepvals->edHdLPrintEnergy != edHdLPrintEnergyNO)
134                 {
135                     ndh_tot += 1;
136                 }
137                 /* as data blocks: 1 real per dH point */
138                 cio += div_nsteps(nsteps, ir->fepvals->nstdhdl) * ndh_tot * sizeof(real);
139             }
140             else
141             {
142                 /* as histograms: dh_hist_size ints per histogram */
143                 cio += div_nsteps(nsteps, ir->nstenergy) * sizeof(int) * ir->fepvals->dh_hist_size * ndh;
144             }
145         }
146     }
147     if (ir->pull != nullptr)
148     {
149         cio += div_nsteps(nsteps, ir->pull->nstxout) * 20; /* roughly 20 chars per line */
150         cio += div_nsteps(nsteps, ir->pull->nstfout) * 20; /* roughly 20 chars per line */
151     }
152
153     return cio * nrepl / (1024 * 1024);
154 }