Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MPI_Wtime relative to MPI_Init #12958

Merged
merged 1 commit into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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};
jsquyres marked this conversation as resolved.
Show resolved Hide resolved

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
Loading