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