From 93403f822075c47a3b553622c2309760d2142973 Mon Sep 17 00:00:00 2001 From: Mark Abraham Date: Sat, 15 Mar 2014 10:40:32 +0100 Subject: [PATCH] Fix print_date_and_time The old call signature and lack of documentation of this function made it easy to misuse, and (e.g.) mdrun was reporting the same initial and final time stamp. Fixed signature and documented. Change-Id: Ib4d9a07bc6e1165affa3bfdf7cd3b54c615d4765 --- src/gromacs/legacyheaders/sim_util.h | 12 ++++++++-- src/gromacs/mdlib/sim_util.c | 33 +++++++++++++--------------- src/programs/mdrun/md.c | 2 +- src/programs/mdrun/runner.c | 2 +- 4 files changed, 27 insertions(+), 22 deletions(-) diff --git a/src/gromacs/legacyheaders/sim_util.h b/src/gromacs/legacyheaders/sim_util.h index 47d68cb271..d1d6d41a93 100644 --- a/src/gromacs/legacyheaders/sim_util.h +++ b/src/gromacs/legacyheaders/sim_util.h @@ -87,8 +87,16 @@ int do_per_step(gmx_int64_t step, gmx_int64_t nstep); void print_time(FILE *out, gmx_walltime_accounting_t walltime_accounting, gmx_int64_t step, t_inputrec *ir, t_commrec *cr); -void print_date_and_time(FILE *log, int pid, const char *title, - const gmx_walltime_accounting_t walltime_accounting); +/*! \brief Print date, time, MPI rank and a description of this point + * in time. + * + * \param[in] log logfile, or NULL to suppress output + * \param[in] nodeid MPI rank to include in the output + * \param[in] title Description to include in the output + * \param[in] the_time Seconds since the epoch, e.g. as reported by gmx_gettime + */ +void print_date_and_time(FILE *log, int rank, const char *title, + double the_time); void print_start(FILE *fplog, t_commrec *cr, gmx_walltime_accounting_t walltime_accounting, diff --git a/src/gromacs/mdlib/sim_util.c b/src/gromacs/mdlib/sim_util.c index d8ad351554..e2fbf7c594 100644 --- a/src/gromacs/mdlib/sim_util.c +++ b/src/gromacs/mdlib/sim_util.c @@ -155,33 +155,29 @@ void print_time(FILE *out, } void print_date_and_time(FILE *fplog, int nodeid, const char *title, - const gmx_walltime_accounting_t walltime_accounting) + double the_time) { - int i; - char timebuf[STRLEN]; char time_string[STRLEN]; - time_t tmptime; - if (fplog) + if (!fplog) { - if (walltime_accounting != NULL) - { - tmptime = (time_t) walltime_accounting_get_start_time_stamp(walltime_accounting); - gmx_ctime_r(&tmptime, timebuf, STRLEN); - } - else - { - tmptime = (time_t) gmx_gettime(); - gmx_ctime_r(&tmptime, timebuf, STRLEN); - } + return; + } + + { + int i; + char timebuf[STRLEN]; + time_t temp_time = (time_t) the_time; + + gmx_ctime_r(&temp_time, timebuf, STRLEN); for (i = 0; timebuf[i] >= ' '; i++) { time_string[i] = timebuf[i]; } time_string[i] = '\0'; - - fprintf(fplog, "%s on node %d %s\n", title, nodeid, time_string); } + + fprintf(fplog, "%s on node %d %s\n", title, nodeid, time_string); } void print_start(FILE *fplog, t_commrec *cr, @@ -191,7 +187,8 @@ void print_start(FILE *fplog, t_commrec *cr, char buf[STRLEN]; sprintf(buf, "Started %s", name); - print_date_and_time(fplog, cr->nodeid, buf, walltime_accounting); + print_date_and_time(fplog, cr->nodeid, buf, + walltime_accounting_get_start_time_stamp(walltime_accounting)); } static void sum_forces(int start, int end, rvec f[], rvec flr[]) diff --git a/src/programs/mdrun/md.c b/src/programs/mdrun/md.c index 8fb7afb3ff..65307a8333 100644 --- a/src/programs/mdrun/md.c +++ b/src/programs/mdrun/md.c @@ -129,7 +129,7 @@ static void reset_all_counters(FILE *fplog, t_commrec *cr, *step_rel = 0; wallcycle_start(wcycle, ewcRUN); walltime_accounting_start(walltime_accounting); - print_date_and_time(fplog, cr->nodeid, "Restarted time", walltime_accounting); + print_date_and_time(fplog, cr->nodeid, "Restarted time", gmx_gettime()); } double do_md(FILE *fplog, t_commrec *cr, int nfile, const t_filenm fnm[], diff --git a/src/programs/mdrun/runner.c b/src/programs/mdrun/runner.c index 30044a2d19..add01471f3 100644 --- a/src/programs/mdrun/runner.c +++ b/src/programs/mdrun/runner.c @@ -1803,7 +1803,7 @@ int mdrunner(gmx_hw_opt_t *hw_opt, gmx_hardware_info_free(hwinfo); /* Does what it says */ - print_date_and_time(fplog, cr->nodeid, "Finished mdrun", walltime_accounting); + print_date_and_time(fplog, cr->nodeid, "Finished mdrun", gmx_gettime()); walltime_accounting_destroy(walltime_accounting); /* Close logfile already here if we were appending to it */ -- 2.22.0