File tree Expand file tree Collapse file tree 2 files changed +27
-3
lines changed Expand file tree Collapse file tree 2 files changed +27
-3
lines changed Original file line number Diff line number Diff line change 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"
@@ -60,8 +63,20 @@ double MPI_Wtick(void)
6063#elif OPAL_TIMER_USEC_NATIVE
6164 return 0.000001 ;
6265#endif
66+ #else
67+ #if defined(__linux__ ) && OPAL_HAVE_CLOCK_GETTIME
68+ struct timespec spec ;
69+ double wtick = 0.0 ;
70+ if (0 == clock_getres (CLOCK_MONOTONIC , & spec )){
71+ wtick = spec .tv_sec + spec .tv_nsec * 1.0e-09 ;
72+ } else {
73+ /* guess */
74+ wtick = 1.0e-09 ;
75+ }
76+ return wtick ;
6377#else
6478 /* Otherwise, we already return usec precision. */
6579 return 0.000001 ;
6680#endif
81+ #endif
6782}
Original file line number Diff line number Diff line change 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 ();
You can’t perform that action at this time.
0 commit comments