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