Skip to content

Commit d419e80

Browse files
author
Ralph Castain
authored
Merge pull request #3456 from sjeaugey/wtime-fix-v1.10
Wtime fix for v1.10
2 parents c58875d + d9d7b80 commit d419e80

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

ompi/mpi/c/wtick.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
* Copyright (c) 2004-2005 The Regents of the University of California.
1111
* All rights reserved.
1212
* Copyright (c) 2007-2014 Cisco Systems, Inc. All rights reserved.
13+
* Copyright (c) 2017 IBM Corporation. All rights reserved.
14+
* Copyright (c) 2017 Los Alamos National Security, LLC. All rights
15+
* reserved.
1316
* $COPYRIGHT$
1417
*
1518
* Additional copyrights may follow
@@ -22,6 +25,9 @@
2225
#include <sys/time.h>
2326
#endif
2427
#include <stdio.h>
28+
#ifdef HAVE_TIME_H
29+
#include <time.h>
30+
#endif
2531

2632
#include MCA_timer_IMPLEMENTATION_HEADER
2733
#include "ompi/mpi/c/bindings.h"
@@ -40,6 +46,11 @@ double MPI_Wtick(void)
4046
{
4147
OPAL_CR_NOOP_PROGRESS();
4248

49+
/*
50+
* See https://github.com/open-mpi/ompi/issues/3003
51+
* to get an idea what's going on here.
52+
*/
53+
#if 0
4354
#if OPAL_TIMER_USEC_NATIVE
4455
/* We may or may not have native usec precision on Windows, so put
4556
this #if before the #ifdef checking for Windows. */
@@ -49,8 +60,21 @@ double MPI_Wtick(void)
4960
opal_output( 0, "No timer frequency\n" );
5061
}
5162
return (double)opal_timer_base_get_freq();
63+
#endif
64+
#else
65+
#if defined(__linux__) && OPAL_HAVE_CLOCK_GETTIME
66+
struct timespec spec;
67+
double wtick = 0.0;
68+
if (0 == clock_getres(CLOCK_MONOTONIC, &spec)){
69+
wtick = spec.tv_sec + spec.tv_nsec * 1.0e-09;
70+
} else {
71+
/* guess */
72+
wtick = 1.0e-09;
73+
}
74+
return wtick;
5275
#else
5376
/* Otherwise, we already return usec precision. */
5477
return 0.000001;
5578
#endif
79+
#endif
5680
}

ompi/mpi/c/wtime.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
* Copyright (c) 2004-2005 The Regents of the University of California.
1111
* All rights reserved.
1212
* Copyright (c) 2006-2014 Cisco Systems, Inc. All rights reserved.
13+
* Copyright (c) 2017 IBM Corporation. All rights reserved.
14+
* Copyright (c) 2017 Los Alamos National Security, LLC. All rights
15+
* reserved.
1316
* $COPYRIGHT$
1417
*
1518
* Additional copyrights may follow
@@ -22,6 +25,9 @@
2225
#include <sys/time.h>
2326
#endif
2427
#include <stdio.h>
28+
#ifdef HAVE_TIME_H
29+
#include <time.h>
30+
#endif /* HAVE_TIME_H */
2531

2632
#include MCA_timer_IMPLEMENTATION_HEADER
2733
#include "ompi/mpi/c/bindings.h"
@@ -40,19 +46,32 @@ double MPI_Wtime(void)
4046
{
4147
double wtime;
4248

49+
/*
50+
* See https://github.com/open-mpi/ompi/issues/3003 to find out
51+
* what's happening here.
52+
*/
53+
#if 0
4354
#if OPAL_TIMER_USEC_NATIVE
4455
/* We may or may not have native usec precision on Windows, so put
4556
this #if before the #ifdef checking for Windows. */
4657
wtime = ((double) opal_timer_base_get_usec()) / 1000000.0;
4758
#elif defined(__WINDOWS__)
4859
wtime = ((double) opal_timer_base_get_cycles()) /
4960
((double) opal_timer_base_get_freq());
61+
#endif
62+
#else
63+
#if defined(__linux__) && OPAL_HAVE_CLOCK_GETTIME
64+
struct timespec tp = {.tv_sec = 0, .tv_nsec = 0};
65+
(void) clock_gettime(CLOCK_MONOTONIC, &tp);
66+
wtime = tp.tv_sec;
67+
wtime += tp.tv_nsec/1.0e+9;
5068
#else
5169
/* Fall back to gettimeofday() if we have nothing else */
5270
struct timeval tv;
5371
gettimeofday(&tv, NULL);
5472
wtime = tv.tv_sec;
5573
wtime += (double)tv.tv_usec / 1000000.0;
74+
#endif
5675
#endif
5776

5877
OPAL_CR_NOOP_PROGRESS();

0 commit comments

Comments
 (0)