From cf98657adbe7fd0cef6bd30ac19c437db57a4382 Mon Sep 17 00:00:00 2001 From: Jeff Squyres Date: Mon, 26 Nov 2007 18:23:53 +0000 Subject: [PATCH] * Clean up a little #if logic in MPI_WTICK / MPI_WTIME * Update MPI_WTICK / MPI_WTIME man pages: * Fix C++ declarations * Note that we may use better than gettimeofday() on some platforms * Add "MPI_WTIME support" ("options:mpi-wtime") flag in ompi_info output indicating whether we use "native" or "gettimeofday" for MPI_WTIME This commit was SVN r16774. --- ompi/mpi/c/wtick.c | 12 ++++++------ ompi/mpi/c/wtime.c | 17 ++++++++--------- ompi/mpi/man/man3/MPI_Wtick.3 | 18 ++++++++++++------ ompi/mpi/man/man3/MPI_Wtime.3 | 14 ++++++++++++-- ompi/tools/ompi_info/param.cc | 3 +++ 5 files changed, 41 insertions(+), 23 deletions(-) diff --git a/ompi/mpi/c/wtick.c b/ompi/mpi/c/wtick.c index b415338e42..693ca6869b 100644 --- a/ompi/mpi/c/wtick.c +++ b/ompi/mpi/c/wtick.c @@ -9,6 +9,7 @@ * University of Stuttgart. All rights reserved. * Copyright (c) 2004-2005 The Regents of the University of California. * All rights reserved. + * Copyright (c) 2007 Cisco Systems, Inc. All rights reserved. * $COPYRIGHT$ * * Additional copyrights may follow @@ -42,17 +43,16 @@ double MPI_Wtick(void) OPAL_CR_TEST_CHECKPOINT_READY(); #if OPAL_TIMER_USEC_NATIVE + /* We may or may not have native usec precision on Windows, so put + this #if before the #ifdef checking for Windows. */ return 0.000001; -#else - -#if defined(__WINDOWS__) +#elif defined(__WINDOWS__) if( (opal_timer_t)0 == opal_timer_base_get_freq() ) { opal_output( 0, "No timer frequency\n" ); } return (double)opal_timer_base_get_freq(); #else + /* Otherwise, we already return usec precision. */ return 0.000001; -#endif /* defined(__WINDOWS__) */ - -#endif /* OPAL_TIMER_USEC_NATIVE */ +#endif } diff --git a/ompi/mpi/c/wtime.c b/ompi/mpi/c/wtime.c index 2d0a12859d..e704d2e51c 100644 --- a/ompi/mpi/c/wtime.c +++ b/ompi/mpi/c/wtime.c @@ -44,20 +44,19 @@ double MPI_Wtime(void) double wtime; #if OPAL_TIMER_USEC_NATIVE - wtime = (double)opal_timer_base_get_usec() / 1000000.0; -#else - -#if defined(__WINDOWS__) - wtime = ((double)opal_timer_base_get_cycles()) / ((double)opal_timer_base_get_freq()); - return wtime; + /* We may or may not have native usec precision on Windows, so put + this #if before the #ifdef checking for Windows. */ + wtime = ((double) opal_timer_base_get_usec()) / 1000000.0; +#elif defined(__WINDOWS__) + wtime = ((double) opal_timer_base_get_cycles()) / + ((double) opal_timer_base_get_freq()); #else + /* Fall back to gettimeofday() if we have nothing else */ struct timeval tv; gettimeofday(&tv, NULL); wtime = tv.tv_sec; wtime += (double)tv.tv_usec / 1000000.0; -#endif /* defined(__WINDOWS__) */ - -#endif /* OPAL_TIMER_USEC_NATIVE */ +#endif OPAL_CR_TEST_CHECKPOINT_READY(); diff --git a/ompi/mpi/man/man3/MPI_Wtick.3 b/ompi/mpi/man/man3/MPI_Wtick.3 index 9b8d363e40..1476ed219a 100644 --- a/ompi/mpi/man/man3/MPI_Wtick.3 +++ b/ompi/mpi/man/man3/MPI_Wtick.3 @@ -19,7 +19,7 @@ DOUBLE PRECISION MPI_WTICK() .SH C++ Syntax .nf #include -double Wtick() +double MPI::Wtick() .SH RETURN VALUE .ft R @@ -27,16 +27,22 @@ Time in seconds of resolution of MPI_Wtime. .SH DESCRIPTION .ft R -MPI_Wtick returns the resolution of MPI_Wtime in seconds. That is, it returns, as a double-precision value, the number of seconds between successive clock ticks. For example, if the clock is implemented by the hardware as a counter that is incremented every millisecond, the value returned by MPI_Wtick should be 10^-3. +MPI_Wtick returns the resolution of MPI_Wtime in seconds. That is, it +returns, as a double-precision value, the number of seconds between +successive clock ticks. For example, if the clock is implemented by +the hardware as a counter that is incremented every millisecond, the +value returned by MPI_Wtick should be 10^-3. +.PP +Note that on POSIX platforms, Open MPI should always return 10^-3 for +MPI_Wtick. The returned value may be different on Windows platforms. .PP -.SH NOTE -This function does not return an error value. Consequently, the result of calling it before MPI_Init or after MPI_Finalize is undefined. +.SH NOTE +This function does not return an error value. Consequently, the result +of calling it before MPI_Init or after MPI_Finalize is undefined. .SH SEE ALSO .ft R .sp MPI_Wtime - - ' @(#)MPI_Wtick.3 1.21 06/03/09 diff --git a/ompi/mpi/man/man3/MPI_Wtime.3 b/ompi/mpi/man/man3/MPI_Wtime.3 index 8690ce3183..86624815b3 100644 --- a/ompi/mpi/man/man3/MPI_Wtime.3 +++ b/ompi/mpi/man/man3/MPI_Wtime.3 @@ -19,7 +19,7 @@ DOUBLE PRECISION MPI_WTIME() .SH C++ Syntax .nf #include -double Wtime() +double MPI::Wtime() .SH RETURN VALUE .ft R @@ -48,7 +48,17 @@ The times returned are local to the node that called them. There is no requireme The boolean variable MPI_WTIME_IS_GLOBAL, a predefined attribute key that indicates whether clocks are synchronized, does not have a valid value in Open MPI, as the clocks are not guaranteed to be synchronized. .PP -This is intended to be a high-resolution, elapsed (or wall) clock. See MPI_Wtick to determine the resolution of MPI_Wtime. +This function is intended to be a high-resolution, elapsed (or wall) clock. See MPI_Wtick to determine the resolution of MPI_Wtime. +.PP +On POSIX platforms, this function may utilize a timer that is cheaper +to invoke than the gettimeofday() system call, but will fall back to +gettimeofday() if a cheap high-resolution timer is not available. The +ompi_info command can be consulted to see if Open MPI supports a +native high-resolution timer on your platform; see the value for "MPI_WTIME +support" (or "options:mpi-wtime" when viewing the parsable +output). If this value is "native", a method that is likely to be +cheaper than gettimeofday() will be used to obtain the time when +MPI_Wtime is invoked. .PP This function does not return an error value. Consequently, the result of calling it before MPI_Init or after MPI_Finalize is undefined. diff --git a/ompi/tools/ompi_info/param.cc b/ompi/tools/ompi_info/param.cc index 0fbd7058c1..8f99876d6b 100644 --- a/ompi/tools/ompi_info/param.cc +++ b/ompi/tools/ompi_info/param.cc @@ -33,6 +33,7 @@ #include #endif +#include MCA_timer_IMPLEMENTATION_HEADER #include "opal/mca/installdirs/installdirs.h" #include "opal/class/opal_value_array.h" #include "opal/util/printf.h" @@ -353,6 +354,7 @@ void ompi_info::do_config(bool want_all) "yes" : "no"); const string sparse_groups(OMPI_GROUP_SPARSE ? "yes" : "no"); const string have_mpi_io(OMPI_PROVIDE_MPI_FILE_INTERFACE ? "yes" : "no"); + const string wtime_support(OPAL_TIMER_USEC_NATIVE ? "native" : "gettimeofday"); if (OMPI_HAVE_SOLARIS_THREADS || OMPI_HAVE_POSIX_THREADS) { threads = OMPI_HAVE_SOLARIS_THREADS ? "solaris" : @@ -589,4 +591,5 @@ void ompi_info::do_config(bool want_all) out("mpirun default --prefix", "mpirun:prefix_by_default", mpirun_prefix_by_default); out("MPI I/O support", "options:mpi-io", have_mpi_io); + out("MPI_WTIME support", "options:mpi-wtime", wtime_support); }