From 3683dac839f59c33b4be996ae0b87df609f8be58 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 4 Jul 2013 00:07:07 +0200 Subject: [PATCH] remove unused system time, add cpu time for windows --- src/timer.cpp | 42 +++++++++--------------------------------- src/timer.h | 5 ----- 2 files changed, 9 insertions(+), 38 deletions(-) diff --git a/src/timer.cpp b/src/timer.cpp index c33bc1a1b1..85e9f2497b 100644 --- a/src/timer.cpp +++ b/src/timer.cpp @@ -44,24 +44,18 @@ static double get_cpu_time() rv += (double) ru.ru_utime.tv_usec * 0.000001; } return rv; -#endif -#endif - return 0.0; -} - -/* ---------------------------------------------------------------------- */ -static double get_sys_time() -{ -#ifndef _WIN32 - struct rusage ru; +#else /* _WIN32 */ + // from MSD docs. + FILETIME ct,et,kt,ut; double rv = 0.0; - if (getrusage(RUSAGE_SELF, &ru) == 0) { - rv = (double) ru.ru_stime.tv_sec; - rv += (double) ru.ru_stime.tv_usec * 0.000001; + if (GetProcessTimes(GetCurrentProcess(),&ct,&et,&kt,&ut)) { + rv = (double) dwLowDateTime * 0.0000001; + rv += (double) dwHighDateTime *429.4967296; } return rv; +); +#endif /* _WIN32 */ #endif - return 0.0; } /* ---------------------------------------------------------------------- */ @@ -69,7 +63,7 @@ static double get_wall_time() { #ifdef LMP_CLOCK_GETTIME struct timespec tp; - clock_gettime(CLOCK_REALTIME_HR,&tp); + clock_gettime(CLOCK_REALTIME,&tp); double rv = (double) tp.tv_sec; rv += (double) tp.tv_nsec * 0.0000000001; return rv; @@ -83,7 +77,6 @@ static double get_wall_time() Timer::Timer(LAMMPS *lmp) : Pointers(lmp) { memory->create(cpu_array,TIME_N,"timer:cpu_array"); - memory->create(sys_array,TIME_N,"timer:sys_array"); memory->create(wall_array,TIME_N,"timer:wall_array"); } @@ -92,7 +85,6 @@ Timer::Timer(LAMMPS *lmp) : Pointers(lmp) Timer::~Timer() { memory->destroy(cpu_array); - memory->destroy(sys_array); memory->destroy(wall_array); } @@ -101,7 +93,6 @@ Timer::~Timer() void Timer::init() { for (int i = 0; i < TIME_N; i++) cpu_array[i] = 0.0; - for (int i = 0; i < TIME_N; i++) sys_array[i] = 0.0; for (int i = 0; i < TIME_N; i++) wall_array[i] = 0.0; } @@ -112,7 +103,6 @@ void Timer::stamp() // uncomment if want synchronized timing // MPI_Barrier(world); previous_cpu = get_cpu_time(); - previous_sys = get_sys_time(); previous_wall = get_wall_time(); } @@ -123,13 +113,10 @@ void Timer::stamp(enum ttype which) // uncomment if want synchronized timing // MPI_Barrier(world); double current_cpu = get_cpu_time(); - double current_sys = get_sys_time(); double current_wall = get_wall_time(); cpu_array[which] += current_cpu - previous_cpu; - sys_array[which] += current_sys - previous_sys; wall_array[which] += current_wall - previous_wall; previous_cpu = current_cpu; - previous_sys = current_sys; previous_wall = current_wall; } @@ -139,7 +126,6 @@ void Timer::barrier_start(enum ttype which) { MPI_Barrier(world); cpu_array[which] = get_cpu_time(); - sys_array[which] = get_sys_time(); wall_array[which] = get_wall_time(); } @@ -149,10 +135,8 @@ void Timer::barrier_stop(enum ttype which) { MPI_Barrier(world); double current_cpu = get_cpu_time(); - double current_sys = get_sys_time(); double current_wall = get_wall_time(); cpu_array[which] = current_cpu - cpu_array[which]; - sys_array[which] = current_sys - sys_array[which]; wall_array[which] = current_wall - wall_array[which]; } @@ -166,14 +150,6 @@ double Timer::cpu(enum ttype which) /* ---------------------------------------------------------------------- */ -double Timer::sys(enum ttype which) -{ - double current_sys = get_sys_time(); - return (current_sys - sys_array[which]); -} - -/* ---------------------------------------------------------------------- */ - double Timer::elapsed(enum ttype which) { double current_wall = get_wall_time(); diff --git a/src/timer.h b/src/timer.h index 7308696157..22bede9c80 100644 --- a/src/timer.h +++ b/src/timer.h @@ -32,12 +32,9 @@ class Timer : protected Pointers { void barrier_stop(enum ttype); double elapsed(enum ttype); double cpu(enum ttype); - double sys(enum ttype); double get_cpu(enum ttype which) const { return cpu_array[which]; }; - double get_sys(enum ttype which) const { - return sys_array[which]; }; double get_wall(enum ttype which) const { return wall_array[which]; }; @@ -45,10 +42,8 @@ class Timer : protected Pointers { private: double *cpu_array; - double *sys_array; double *wall_array; double previous_cpu; - double previous_sys; double previous_wall; };