13
13
* Copyright (c) 2015 Research Organization for Information Science
14
14
* and Technology (RIST). All rights reserved.
15
15
* Copyright (c) 2017 IBM Corporation. All rights reserved.
16
+ * Copyright (c) 2017 Los Alamos National Security, LLC. All rights
17
+ * reserved.
16
18
* $COPYRIGHT$
17
19
*
18
20
* Additional copyrights may follow
25
27
#include <sys/time.h>
26
28
#endif
27
29
#include <stdio.h>
30
+ #ifdef HAVE_TIME_H
31
+ #include <time.h>
32
+ #endif /* HAVE_TIME_H */
28
33
29
34
#include MCA_timer_IMPLEMENTATION_HEADER
30
35
#include "ompi/mpi/c/bindings.h"
@@ -42,22 +47,28 @@ double MPI_Wtime(void)
42
47
double wtime ;
43
48
44
49
/*
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.
48
52
*/
49
53
#if 0
50
54
#if OPAL_TIMER_CYCLE_NATIVE
51
55
wtime = ((double ) opal_timer_base_get_cycles ()) / opal_timer_base_get_freq ();
52
56
#elif OPAL_TIMER_USEC_NATIVE
53
57
wtime = ((double ) opal_timer_base_get_usec ()) / 1000000.0 ;
54
58
#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 ;
55
65
#else
56
66
/* Fall back to gettimeofday() if we have nothing else */
57
67
struct timeval tv ;
58
68
gettimeofday (& tv , NULL );
59
69
wtime = tv .tv_sec ;
60
70
wtime += (double )tv .tv_usec / 1000000.0 ;
71
+ #endif
61
72
#endif
62
73
63
74
OPAL_CR_NOOP_PROGRESS ();
0 commit comments