Split lines with many copyright years
[alexxy/gromacs.git] / src / gromacs / mdrunutility / printtime.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) 2013,2014,2015,2016,2017 by the GROMACS development team.
7  * Copyright (c) 2018,2019,2020, 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 "printtime.h"
41
42 #include "config.h"
43
44 #include "gromacs/mdtypes/commrec.h"
45 #include "gromacs/mdtypes/inputrec.h"
46 #include "gromacs/timing/walltime_accounting.h"
47 #include "gromacs/utility/cstringutil.h"
48 #include "gromacs/utility/strconvert.h"
49 #include "gromacs/utility/sysinfo.h"
50
51 void print_time(FILE*                     out,
52                 gmx_walltime_accounting_t walltime_accounting,
53                 int64_t                   step,
54                 const t_inputrec*         ir,
55                 const t_commrec*          cr)
56 {
57     time_t finish;
58     double dt, elapsed_seconds, time_per_step;
59
60 #if !GMX_THREAD_MPI
61     if (!PAR(cr))
62 #endif
63     {
64         fprintf(out, "\r");
65     }
66     fputs("step ", out);
67     fputs(gmx::int64ToString(step).c_str(), out);
68     fflush(out);
69
70     if ((step >= ir->nstlist))
71     {
72         double seconds_since_epoch = gmx_gettime();
73         elapsed_seconds =
74                 seconds_since_epoch - walltime_accounting_get_start_time_stamp(walltime_accounting);
75         time_per_step = elapsed_seconds / (step - ir->init_step + 1);
76         dt            = (ir->nsteps + ir->init_step - step) * time_per_step;
77
78         if (ir->nsteps >= 0)
79         {
80             if (dt >= 300)
81             {
82                 finish       = static_cast<time_t>(seconds_since_epoch + dt);
83                 auto timebuf = gmx_ctime_r(&finish);
84                 timebuf.erase(timebuf.find_first_of('\n'));
85                 fputs(", will finish ", out);
86                 fputs(timebuf.c_str(), out);
87             }
88             else
89             {
90                 fprintf(out, ", remaining wall clock time: %5d s          ", static_cast<int>(dt));
91             }
92         }
93         else
94         {
95             fprintf(out, " performance: %.1f ns/day    ", ir->delta_t / 1000 * 24 * 60 * 60 / time_per_step);
96         }
97     }
98 #if !GMX_THREAD_MPI
99     if (PAR(cr))
100     {
101         fprintf(out, "\n");
102     }
103 #else
104     GMX_UNUSED_VALUE(cr);
105 #endif
106
107     fflush(out);
108 }
109
110 void print_date_and_time(FILE* fplog, int nodeid, const char* title, double the_time)
111 {
112     if (!fplog)
113     {
114         return;
115     }
116
117     time_t temp_time = static_cast<time_t>(the_time);
118
119     auto timebuf = gmx_ctime_r(&temp_time);
120
121     fprintf(fplog, "%s on rank %d %s\n", title, nodeid, timebuf.c_str());
122 }
123
124 void print_start(FILE* fplog, const t_commrec* cr, gmx_walltime_accounting_t walltime_accounting, const char* name)
125 {
126     char buf[STRLEN];
127
128     sprintf(buf, "Started %s", name);
129     print_date_and_time(fplog, cr->nodeid, buf,
130                         walltime_accounting_get_start_time_stamp(walltime_accounting));
131 }