From 7b3422ab4ef3b469c827a12379e60aa31e3b7d3f Mon Sep 17 00:00:00 2001 From: Izaak Beekman Date: Fri, 18 Jan 2019 15:42:46 -0500 Subject: [PATCH] Try Salvatore's timer function on windows --- base/CMakeLists.txt | 3 --- base/modules/cutil.c | 5 +--- base/modules/fakempi.c | 16 +++++++++---- base/modules/gettimeofday.c | 48 ------------------------------------- base/modules/gettimeofday.h | 15 ------------ 5 files changed, 12 insertions(+), 75 deletions(-) delete mode 100644 base/modules/gettimeofday.c delete mode 100644 base/modules/gettimeofday.h diff --git a/base/CMakeLists.txt b/base/CMakeLists.txt index 759c8a014..26e70a788 100644 --- a/base/CMakeLists.txt +++ b/base/CMakeLists.txt @@ -409,9 +409,6 @@ list(APPEND PSB_base_source_C_files modules/cutil.c) if (SERIAL_MPI) list(APPEND PSB_base_source_C_files modules/fakempi.c) endif() -if(WIN32) - list(APPEND PSB_base_source_C_files modules/gettimeofday.c modules/gettimeofday.h) -endif() foreach(file IN LISTS PSB_base_source_C_files) list(APPEND base_source_C_files ${CMAKE_CURRENT_LIST_DIR}/${file}) endforeach() diff --git a/base/modules/cutil.c b/base/modules/cutil.c index a0f51d49e..11b815051 100644 --- a/base/modules/cutil.c +++ b/base/modules/cutil.c @@ -1,7 +1,4 @@ -#ifdef _WIN32 -#include -#include -#else +#if ! (defined(_WIN32) || defined(WIN32)) #include #endif #include diff --git a/base/modules/fakempi.c b/base/modules/fakempi.c index 33c028609..0510f333c 100644 --- a/base/modules/fakempi.c +++ b/base/modules/fakempi.c @@ -1,8 +1,4 @@ -#ifdef _WIN32 -#include -#include -#include "gettimeofday.h" -#else +#if ! (defined(_WIN32) || defined(WIN32)) #include #endif #include @@ -110,6 +106,15 @@ double mpi_wtime() { +#if defined(WIN32) || defined(_WIN32) + LARGE_INTEGER tim, freq; + double seconds; + + QueryPerformanceCounter(&tim); + QeryPerformanceFrequency(&freq); + seconds = (double)tim / (double) freq; + return(seconds); +#else struct timeval tt; struct timezone tz; double temp; @@ -120,6 +125,7 @@ double mpi_wtime() temp = ((double)tt.tv_sec) + ((double)tt.tv_usec)*1.0e-6; } return(temp); +#endif } diff --git a/base/modules/gettimeofday.c b/base/modules/gettimeofday.c deleted file mode 100644 index f7a838616..000000000 --- a/base/modules/gettimeofday.c +++ /dev/null @@ -1,48 +0,0 @@ -#include -#include -#if defined(_MSC_VER) || defined(_MSC_EXTENSIONS) - #define DELTA_EPOCH_IN_MICROSECS 11644473600000000Ui64 -#else - #define DELTA_EPOCH_IN_MICROSECS 11644473600000000ULL -#endif - -typedef struct -{ - int tz_minuteswest; /* minutes W of Greenwich */ - int tz_dsttime; /* type of dst correction */ -} timezone; - -int gettimeofday(struct timeval *tv, struct timezone *tz) -{ - FILETIME ft; - unsigned __int64 tmpres = 0; - static int tzflag; - - if (NULL != tv) - { - GetSystemTimeAsFileTime(&ft); - - tmpres |= ft.dwHighDateTime; - tmpres <<= 32; - tmpres |= ft.dwLowDateTime; - - /*converting file time to unix epoch*/ - tmpres -= DELTA_EPOCH_IN_MICROSECS; - tmpres /= 10; /*convert into microseconds*/ - tv->tv_sec = (long)(tmpres / 1000000UL); - tv->tv_usec = (long)(tmpres % 1000000UL); - } - - if (NULL != tz) - { - if (!tzflag) - { - _tzset(); - tzflag++; - } - tz->tz_minuteswest = _timezone / 60; - tz->tz_dsttime = _daylight; - } - - return 0; -} diff --git a/base/modules/gettimeofday.h b/base/modules/gettimeofday.h deleted file mode 100644 index 7da9ed216..000000000 --- a/base/modules/gettimeofday.h +++ /dev/null @@ -1,15 +0,0 @@ -#include -#include -#if defined(_MSC_VER) || defined(_MSC_EXTENSIONS) - #define DELTA_EPOCH_IN_MICROSECS 11644473600000000Ui64 -#else - #define DELTA_EPOCH_IN_MICROSECS 11644473600000000ULL -#endif - -typedef struct -{ - int tz_minuteswest; /* minutes W of Greenwich */ - int tz_dsttime; /* type of dst correction */ -} timezone; - -int gettimeofday(struct timeval *tv, struct timezone *tz);