Skip to content

Commit

Permalink
MPI_Wtime relative to MPI_Init
Browse files Browse the repository at this point in the history
Issue #12953 identified an issue with MPI_Wtime taking the first call
as the source of relative timing. This patch moves the timing root
early in the MPI initialization (sessions or world model).

Fixes #12953.

Signed-off-by: George Bosilca <[email protected]>
(cherry picked from commit c0b371b)
  • Loading branch information
bosilca committed Dec 11, 2024
1 parent 428650e commit 6b6b5ae
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
16 changes: 15 additions & 1 deletion ompi/instance/instance.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* of Tennessee Research Foundation. All rights
* reserved.
* Copyright (c) 2023 Jeffrey M. Squyres. All rights reserved.
* Copyright (c) 2024 NVIDIA Corporation. All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
Expand Down Expand Up @@ -53,10 +54,11 @@
#include "ompi/mca/topo/base/base.h"
#include "opal/mca/pmix/base/base.h"

#include "opal/mca/mpool/base/mpool_base_tree.h"
#include "ompi/mca/pml/base/pml_base_bsend.h"
#include "ompi/util/timings.h"
#include "opal/mca/mpool/base/mpool_base_tree.h"
#include "opal/mca/pmix/pmix-internal.h"
#include "opal/util/clock_gettime.h"

ompi_predefined_instance_t ompi_mpi_instance_null = {{{{0}}}};

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

/**
* @brief: Base timer initialization. All timers returned to the user via MPI_Wtime
* are relative to this timer. Setting it early in during the common
* initialization (world or session model) allows for measuring the cost of
* the MPI initialization.
*/
struct timespec ompi_wtime_time_origin = {.tv_sec = 0};

enum {
OMPI_INSTANCE_INITIALIZING = -1,
OMPI_INSTANCE_FINALIZING = -2,
Expand Down Expand Up @@ -358,6 +368,10 @@ static int ompi_mpi_instance_init_common (int argc, char **argv)
opal_pmix_lock_t mylock;
OMPI_TIMING_INIT(64);

// We intentionally don't use the OPAL timer framework here. See
// https://github.com/open-mpi/ompi/issues/3003 for more details.
(void) opal_clock_gettime(&ompi_wtime_time_origin);

ret = ompi_mpi_instance_retain ();
if (OPAL_UNLIKELY(OMPI_SUCCESS != ret)) {
return ret;
Expand Down
10 changes: 3 additions & 7 deletions ompi/mpi/c/wtime.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* Copyright (c) 2017 IBM Corporation. All rights reserved.
* Copyright (c) 2017 Los Alamos National Security, LLC. All rights
* reserved.
* Copyright (c) 2024 NVIDIA Corporation. All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
Expand Down Expand Up @@ -42,15 +43,13 @@
#pragma weak MPI_Wtime = PMPI_Wtime
#endif
#define MPI_Wtime PMPI_Wtime
#endif
/**
* Have a base time set on the first call to wtime, to improve the range
* Use this as a base time set early during MPI initialization to improve the range
* and accuracy of the user visible timer.
* More info: https://github.com/mpi-forum/mpi-issues/issues/77#issuecomment-369663119
*/
struct timespec ompi_wtime_time_origin = {.tv_sec = 0};
#else /* OMPI_BUILD_MPI_PROFILING */
extern struct timespec ompi_wtime_time_origin;
#endif

double MPI_Wtime(void)
{
Expand All @@ -62,9 +61,6 @@ double MPI_Wtime(void)
// https://github.com/open-mpi/ompi/issues/3003 for more details.
struct timespec tp;
(void) opal_clock_gettime(&tp);
if (OPAL_UNLIKELY(0 == ompi_wtime_time_origin.tv_sec)) {
ompi_wtime_time_origin = tp;
}
wtime = (double)(tp.tv_nsec - ompi_wtime_time_origin.tv_nsec)/1.0e+9;
wtime += (tp.tv_sec - ompi_wtime_time_origin.tv_sec);

Expand Down

0 comments on commit 6b6b5ae

Please sign in to comment.