Skip to content

Commit 43ab707

Browse files
hppritchajsquyres
authored andcommitted
timer: hack use of clock_gettime
better solution needed later workaround for #3003 Signed-off-by: Howard Pritchard <[email protected]> (cherry picked from commit b933152) Signed-off-by: Jeff Squyres <[email protected]>
1 parent ab7dad2 commit 43ab707

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"
@@ -41,8 +46,7 @@ double MPI_Wtick(void)
4146
{
4247
/*
4348
* See https://github.com/open-mpi/ompi/issues/3003
44-
* For now we are forcing the use of gettimeofday() until we find a
45-
* more portable solution.
49+
* to get an idea what's going on here.
4650
*/
4751
#if 0
4852
#if OPAL_TIMER_CYCLE_NATIVE
@@ -58,8 +62,20 @@ double MPI_Wtick(void)
5862
#elif OPAL_TIMER_USEC_NATIVE
5963
return 0.000001;
6064
#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;
6176
#else
6277
/* Otherwise, we already return usec precision. */
6378
return 0.000001;
6479
#endif
80+
#endif
6581
}

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
return wtime;

0 commit comments

Comments
 (0)