Fix print_date_and_time
authorMark Abraham <mark.j.abraham@gmail.com>
Sat, 15 Mar 2014 09:40:32 +0000 (10:40 +0100)
committerGerrit Code Review <gerrit@gerrit.gromacs.org>
Sun, 23 Mar 2014 10:45:24 +0000 (11:45 +0100)
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
src/gromacs/mdlib/sim_util.c
src/programs/mdrun/md.c
src/programs/mdrun/runner.c

index 47d68cb2717f501a649976f272aeda20f6308ca0..d1d6d41a93188068d104cbe4cbde90f8c1f75f52 100644 (file)
@@ -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,
index d8ad3515540f1e4770c62b38951ca83fdc574fbd..e2fbf7c59460d760864ec10df7801eaa5cb92217 100644 (file)
@@ -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[])
index 8fb7afb3ffcb7bea0165d07d9cd2b0803d66213e..65307a83330da131f0c4aeb5fa7999464121e4b2 100644 (file)
@@ -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[],
index 30044a2d193bb8897ae3ef5934b7c788ff04d63f..add01471f37cb5e3493fef1a2f37fbb0ab25d053 100644 (file)
@@ -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 */