Skip to content

Commit b933152

Browse files
committed
timer: hack use of clock_gettime
better solution needed later workaround for #3003 Signed-off-by: Howard Pritchard <[email protected]>
1 parent 48d13aa commit b933152

File tree

2 files changed

+32
-5
lines changed

2 files changed

+32
-5
lines changed

ompi/mpi/c/wtick.c

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
* Copyright (c) 2015-2016 Research Organization for Information Science
1414
* and Technology (RIST). All rights reserved.
1515
* Copyright (c) 2017 IBM Corporation. All rights reserved.
16+
* Copyright (c) 2017 Los Alamos National Security, LLC. All rights
17+
* reserved.
1618
* $COPYRIGHT$
1719
*
1820
* Additional copyrights may follow
@@ -25,6 +27,9 @@
2527
#include <sys/time.h>
2628
#endif
2729
#include <stdio.h>
30+
#ifdef HAVE_TIME_H
31+
#include <time.h>
32+
#endif
2833

2934
#include MCA_timer_IMPLEMENTATION_HEADER
3035
#include "ompi/mpi/c/bindings.h"
@@ -43,8 +48,7 @@ double MPI_Wtick(void)
4348

4449
/*
4550
* See https://github.com/open-mpi/ompi/issues/3003
46-
* For now we are forcing the use of gettimeofday() until we find a
47-
* more portable solution.
51+
* to get an idea what's going on here.
4852
*/
4953
#if 0
5054
#if OPAL_TIMER_CYCLE_NATIVE
@@ -60,8 +64,20 @@ double MPI_Wtick(void)
6064
#elif OPAL_TIMER_USEC_NATIVE
6165
return 0.000001;
6266
#endif
67+
#else
68+
#if defined(__linux__) && OPAL_HAVE_CLOCK_GETTIME
69+
struct timespec spec;
70+
double wtick = 0.0;
71+
if (0 == clock_getres(CLOCK_MONOTONIC, &spec)){
72+
wtick = spec.tv_sec + spec.tv_nsec * 1.0e-09;
73+
} else {
74+
/* guess */
75+
wtick = 1.0e-09;
76+
}
77+
return wtick;
6378
#else
6479
/* Otherwise, we already return usec precision. */
6580
return 0.000001;
6681
#endif
82+
#endif
6783
}

ompi/mpi/c/wtime.c

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
* Copyright (c) 2015 Research Organization for Information Science
1414
* and Technology (RIST). All rights reserved.
1515
* Copyright (c) 2017 IBM Corporation. All rights reserved.
16+
* Copyright (c) 2017 Los Alamos National Security, LLC. All rights
17+
* reserved.
1618
* $COPYRIGHT$
1719
*
1820
* Additional copyrights may follow
@@ -25,6 +27,9 @@
2527
#include <sys/time.h>
2628
#endif
2729
#include <stdio.h>
30+
#ifdef HAVE_TIME_H
31+
#include <time.h>
32+
#endif /* HAVE_TIME_H */
2833

2934
#include MCA_timer_IMPLEMENTATION_HEADER
3035
#include "ompi/mpi/c/bindings.h"
@@ -42,22 +47,28 @@ double MPI_Wtime(void)
4247
double wtime;
4348

4449
/*
45-
* See https://github.com/open-mpi/ompi/issues/3003
46-
* For now we are forcing the use of gettimeofday() until we find a
47-
* more portable solution.
50+
* See https://github.com/open-mpi/ompi/issues/3003 to find out
51+
* what's happening here.
4852
*/
4953
#if 0
5054
#if OPAL_TIMER_CYCLE_NATIVE
5155
wtime = ((double) opal_timer_base_get_cycles()) / opal_timer_base_get_freq();
5256
#elif OPAL_TIMER_USEC_NATIVE
5357
wtime = ((double) opal_timer_base_get_usec()) / 1000000.0;
5458
#endif
59+
#else
60+
#if defined(__linux__) && OPAL_HAVE_CLOCK_GETTIME
61+
struct timespec tp = {.tv_sec = 0, .tv_nsec = 0};
62+
(void) clock_gettime(CLOCK_MONOTONIC, &tp);
63+
wtime = tp.tv_sec;
64+
wtime += tp.tv_nsec/1.0e+9;
5565
#else
5666
/* Fall back to gettimeofday() if we have nothing else */
5767
struct timeval tv;
5868
gettimeofday(&tv, NULL);
5969
wtime = tv.tv_sec;
6070
wtime += (double)tv.tv_usec / 1000000.0;
71+
#endif
6172
#endif
6273

6374
OPAL_CR_NOOP_PROGRESS();

0 commit comments

Comments
 (0)