diff --git a/src/timer.cpp b/src/timer.cpp index aa428bd50d..39327bc256 100644 --- a/src/timer.cpp +++ b/src/timer.cpp @@ -13,6 +13,7 @@ #include "mpi.h" #include "string.h" +#include "stdlib.h" #include "timer.h" #include "comm.h" #include "error.h" @@ -27,9 +28,6 @@ #include #endif -#include -#include - using namespace LAMMPS_NS; // convert a timespec ([[HH:]MM:]SS) to seconds @@ -228,13 +226,19 @@ void Timer::print_timeout(FILE *fp) // format timeout setting if (_timeout > 0) { - char timebuf[32]; - double delta = MPI_Wtime() - timeout_start; - time_t sec = _timeout - delta; - int hsec = 100*((_timeout - delta) - tv); - struct tm *tm = gmtime(&sec); - strftime(timebuf,32,"%H:%M:%S",tm); - fprintf(fp," Walltime left: %s.%02d\n",timebuf,hsec); + // time since init_timeout() + const double d = MPI_Wtime() - timeout_start; + // remaining timeout in seconds + int s = _timeout - d; + // remaining 1/100ths of seconds + const int hs = 100*((_timeout - d) - s); + // breaking s down into second/minutes/hours + const int seconds = s % 60; + s = (s - seconds) / 60; + const int minutes = s % 60; + const int hours = (s - minutes) / 60; + fprintf(fp," Walltime left: %d:%02d:%02d.%02d\n", + hours,minutes,seconds,hs); } }