Skip to content

Commit a75d285

Browse files
authored
Merge pull request #12958 from bosilca/topic/wtime_based_on_mpi_init
MPI_Wtime relative to MPI_Init
2 parents ec987ee + c0b371b commit a75d285

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

ompi/instance/instance.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
* of Tennessee Research Foundation. All rights
88
* reserved.
99
* Copyright (c) 2023 Jeffrey M. Squyres. All rights reserved.
10+
* Copyright (c) 2024 NVIDIA Corporation. All rights reserved.
1011
* $COPYRIGHT$
1112
*
1213
* Additional copyrights may follow
@@ -53,10 +54,11 @@
5354
#include "ompi/mca/topo/base/base.h"
5455
#include "opal/mca/pmix/base/base.h"
5556

56-
#include "opal/mca/mpool/base/mpool_base_tree.h"
5757
#include "ompi/mca/pml/base/pml_base_bsend.h"
5858
#include "ompi/util/timings.h"
59+
#include "opal/mca/mpool/base/mpool_base_tree.h"
5960
#include "opal/mca/pmix/pmix-internal.h"
61+
#include "opal/util/clock_gettime.h"
6062

6163
ompi_predefined_instance_t ompi_mpi_instance_null = {{{{0}}}};
6264

@@ -74,6 +76,14 @@ __opal_attribute_constructor__ static void instance_lock_init(void) {
7476
/** MPI_Init instance */
7577
ompi_instance_t *ompi_mpi_instance_default = NULL;
7678

79+
/**
80+
* @brief: Base timer initialization. All timers returned to the user via MPI_Wtime
81+
* are relative to this timer. Setting it early in during the common
82+
* initialization (world or session model) allows for measuring the cost of
83+
* the MPI initialization.
84+
*/
85+
struct timespec ompi_wtime_time_origin = {.tv_sec = 0};
86+
7787
enum {
7888
OMPI_INSTANCE_INITIALIZING = -1,
7989
OMPI_INSTANCE_FINALIZING = -2,
@@ -358,6 +368,10 @@ static int ompi_mpi_instance_init_common (int argc, char **argv)
358368
opal_pmix_lock_t mylock;
359369
OMPI_TIMING_INIT(64);
360370

371+
// We intentionally don't use the OPAL timer framework here. See
372+
// https://github.com/open-mpi/ompi/issues/3003 for more details.
373+
(void) opal_clock_gettime(&ompi_wtime_time_origin);
374+
361375
ret = ompi_mpi_instance_retain ();
362376
if (OPAL_UNLIKELY(OMPI_SUCCESS != ret)) {
363377
return ret;

ompi/mpi/c/wtime.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
* Copyright (c) 2017 IBM Corporation. All rights reserved.
1616
* Copyright (c) 2017 Los Alamos National Security, LLC. All rights
1717
* reserved.
18+
* Copyright (c) 2024 NVIDIA Corporation. All rights reserved.
1819
* $COPYRIGHT$
1920
*
2021
* Additional copyrights may follow
@@ -42,15 +43,13 @@
4243
#pragma weak MPI_Wtime = PMPI_Wtime
4344
#endif
4445
#define MPI_Wtime PMPI_Wtime
46+
#endif
4547
/**
46-
* Have a base time set on the first call to wtime, to improve the range
48+
* Use this as a base time set early during MPI initialization to improve the range
4749
* and accuracy of the user visible timer.
4850
* More info: https://github.com/mpi-forum/mpi-issues/issues/77#issuecomment-369663119
4951
*/
50-
struct timespec ompi_wtime_time_origin = {.tv_sec = 0};
51-
#else /* OMPI_BUILD_MPI_PROFILING */
5252
extern struct timespec ompi_wtime_time_origin;
53-
#endif
5453

5554
double MPI_Wtime(void)
5655
{
@@ -62,9 +61,6 @@ double MPI_Wtime(void)
6261
// https://github.com/open-mpi/ompi/issues/3003 for more details.
6362
struct timespec tp;
6463
(void) opal_clock_gettime(&tp);
65-
if (OPAL_UNLIKELY(0 == ompi_wtime_time_origin.tv_sec)) {
66-
ompi_wtime_time_origin = tp;
67-
}
6864
wtime = (double)(tp.tv_nsec - ompi_wtime_time_origin.tv_nsec)/1.0e+9;
6965
wtime += (tp.tv_sec - ompi_wtime_time_origin.tv_sec);
7066

0 commit comments

Comments
 (0)