Skip to content

Commit 12bd4e9

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 12bd4e9

File tree

2 files changed

+28
-5
lines changed

2 files changed

+28
-5
lines changed

ompi/mpi/c/wtick.c

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@
2525
#include <sys/time.h>
2626
#endif
2727
#include <stdio.h>
28+
#ifdef HAVE_TIME_H
29+
#include <time.h>
30+
#endif
2831

2932
#include MCA_timer_IMPLEMENTATION_HEADER
3033
#include "ompi/mpi/c/bindings.h"
@@ -43,8 +46,7 @@ double MPI_Wtick(void)
4346

4447
/*
4548
* 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.
49+
* to get an idea what's going on here.
4850
*/
4951
#if 0
5052
#if OPAL_TIMER_CYCLE_NATIVE
@@ -60,8 +62,20 @@ double MPI_Wtick(void)
6062
#elif OPAL_TIMER_USEC_NATIVE
6163
return 0.000001;
6264
#endif
65+
#else
66+
#if defined(__linux__) && OPAL_HAVE_CLOCK_GETTIME
67+
struct timespec spec;
68+
double wtick = 0.0;
69+
if (0 == clock_getres(CLOCK_MONOTONIC, &spec)){
70+
wtick = spec.tv_sec + spec.tv_nsec * 1.0e-09;
71+
} else {
72+
/* guess */
73+
wtick = 1.0e-09;
74+
}
75+
return wtick;
6376
#else
6477
/* Otherwise, we already return usec precision. */
6578
return 0.000001;
6679
#endif
80+
#endif
6781
}

ompi/mpi/c/wtime.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@
2525
#include <sys/time.h>
2626
#endif
2727
#include <stdio.h>
28+
#ifdef HAVE_TIME_H
29+
#include <time.h>
30+
#endif /* HAVE_TIME_H */
2831

2932
#include MCA_timer_IMPLEMENTATION_HEADER
3033
#include "ompi/mpi/c/bindings.h"
@@ -42,22 +45,28 @@ double MPI_Wtime(void)
4245
double wtime;
4346

4447
/*
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.
48+
* See https://github.com/open-mpi/ompi/issues/3003 to find out
49+
* what's happening here.
4850
*/
4951
#if 0
5052
#if OPAL_TIMER_CYCLE_NATIVE
5153
wtime = ((double) opal_timer_base_get_cycles()) / opal_timer_base_get_freq();
5254
#elif OPAL_TIMER_USEC_NATIVE
5355
wtime = ((double) opal_timer_base_get_usec()) / 1000000.0;
5456
#endif
57+
#else
58+
#if defined(__linux__) && OPAL_HAVE_CLOCK_GETTIME
59+
struct timespec tp = {.tv_sec = 0, .tv_nsec = 0};
60+
(void) clock_gettime(CLOCK_MONOTONIC, &tp);
61+
wtime = tp.tv_sec;
62+
wtime += tp.tv_nsec/1.0e+9;
5563
#else
5664
/* Fall back to gettimeofday() if we have nothing else */
5765
struct timeval tv;
5866
gettimeofday(&tv, NULL);
5967
wtime = tv.tv_sec;
6068
wtime += (double)tv.tv_usec / 1000000.0;
69+
#endif
6170
#endif
6271

6372
OPAL_CR_NOOP_PROGRESS();

0 commit comments

Comments
 (0)