From 7329f1dadcbcc803b6d347ec1ef8f6ef0889baf3 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sun, 26 Feb 2012 10:57:23 -0500 Subject: [PATCH] add option to support hi-res timers in linux --- src/timer.cpp | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/src/timer.cpp b/src/timer.cpp index d323e5f8bb..767f07827a 100644 --- a/src/timer.cpp +++ b/src/timer.cpp @@ -15,15 +15,27 @@ #include "timer.h" #include "memory.h" +// #define LMP_CLOCK_GETTIME 1 + +#ifdef LMP_CLOCK_GETTIME +#include +#endif #ifndef _WIN32 -#include "sys/time.h" -#include "sys/resource.h" +#include +#include #endif using namespace LAMMPS_NS; static double get_cpu_time() { +#ifdef LMP_CLOCK_GETTIME + struct timespec tp; + clock_gettime(CLOCK_PROCESS_CPUTIME_ID,&tp); + double rv = (double) tp.tv_sec; + rv += (double) tp.tv_nsec * 0.0000000001; + return rv; +#else #ifndef _WIN32 struct rusage ru; double rv = 0.0; @@ -32,6 +44,7 @@ static double get_cpu_time() rv += (double) ru.ru_utime.tv_usec * 0.000001; } return rv; +#endif #endif return 0.0; } @@ -54,7 +67,15 @@ static double get_sys_time() /* ---------------------------------------------------------------------- */ static double get_wall_time() { +#ifdef LMP_CLOCK_GETTIME + struct timespec tp; + clock_gettime(CLOCK_REALTIME_HR,&tp); + double rv = (double) tp.tv_sec; + rv += (double) tp.tv_nsec * 0.0000000001; + return rv; +#else return MPI_Wtime(); +#endif } /* ---------------------------------------------------------------------- */