|
Packit Service |
c5cf8c |
/* -*- Mode: C; c-basic-offset:4 ; -*- */
|
|
Packit Service |
c5cf8c |
/*
|
|
Packit Service |
c5cf8c |
* (C) 2001 by Argonne National Laboratory.
|
|
Packit Service |
c5cf8c |
* See COPYRIGHT in top-level directory.
|
|
Packit Service |
c5cf8c |
*/
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
#if !defined(MPL_TIMER_H_INCLUDED)
|
|
Packit Service |
c5cf8c |
#define MPL_TIMER_H_INCLUDED
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
#include "mplconfig.h"
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
#if defined (MPL_HAVE_UNISTD_H)
|
|
Packit Service |
c5cf8c |
#include <unistd.h>
|
|
Packit Service |
c5cf8c |
#if defined (MPL_NEEDS_USLEEP_DECL)
|
|
Packit Service |
c5cf8c |
int usleep(useconds_t usec);
|
|
Packit Service |
c5cf8c |
#endif
|
|
Packit Service |
c5cf8c |
#endif
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/*
|
|
Packit Service |
c5cf8c |
* This include file provide the definitions that are necessary to use the
|
|
Packit Service |
c5cf8c |
* timer calls, including the definition of the time stamp type and
|
|
Packit Service |
c5cf8c |
* any inlined timer calls.
|
|
Packit Service |
c5cf8c |
*
|
|
Packit Service |
c5cf8c |
* The include file timerconf.h (created by autoheader from configure.ac)
|
|
Packit Service |
c5cf8c |
* is needed only to build the function versions of the timers.
|
|
Packit Service |
c5cf8c |
*/
|
|
Packit Service |
c5cf8c |
/* Include the appropriate files */
|
|
Packit Service |
c5cf8c |
#define MPL_TIMER_KIND__GETHRTIME 1
|
|
Packit Service |
c5cf8c |
#define MPL_TIMER_KIND__CLOCK_GETTIME 2
|
|
Packit Service |
c5cf8c |
#define MPL_TIMER_KIND__GETTIMEOFDAY 3
|
|
Packit Service |
c5cf8c |
#define MPL_TIMER_KIND__LINUX86_CYCLE 4
|
|
Packit Service |
c5cf8c |
#define MPL_TIMER_KIND__QUERYPERFORMANCECOUNTER 6
|
|
Packit Service |
c5cf8c |
#define MPL_TIMER_KIND__WIN86_CYCLE 7
|
|
Packit Service |
c5cf8c |
#define MPL_TIMER_KIND__GCC_IA64_CYCLE 8
|
|
Packit Service |
c5cf8c |
/* The value "MPL_TIMER_KIND__DEVICE" means that the ADI device provides the timer */
|
|
Packit Service |
c5cf8c |
#define MPL_TIMER_KIND__DEVICE 9
|
|
Packit Service |
c5cf8c |
#define MPL_TIMER_KIND__WIN64_CYCLE 10
|
|
Packit Service |
c5cf8c |
#define MPL_TIMER_KIND__MACH_ABSOLUTE_TIME 11
|
|
Packit Service |
c5cf8c |
#define MPL_TIMER_KIND__PPC64_CYCLE 12
|
|
Packit Service |
c5cf8c |
#define MPL_TIMER_KIND @MPL_TIMER_KIND@
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* Define a time stamp */
|
|
Packit Service |
c5cf8c |
/* *INDENT-OFF* */
|
|
Packit Service |
c5cf8c |
typedef @MPL_TIMER_TYPE@ MPL_time_t;
|
|
Packit Service |
c5cf8c |
/* *INDENT-ON* */
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* The timer code is allowed to return "NOT_INITIALIZED" before the
|
|
Packit Service |
c5cf8c |
* device is initialized. Once the device is initialized, it must
|
|
Packit Service |
c5cf8c |
* always return SUCCESS, so the upper layers do not need to check for
|
|
Packit Service |
c5cf8c |
* the return code. */
|
|
Packit Service |
c5cf8c |
#define MPL_TIMER_SUCCESS 0
|
|
Packit Service |
c5cf8c |
#define MPL_TIMER_ERR_NOT_INITIALIZED 1
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
#if MPL_TIMER_KIND == MPL_TIMER_KIND__GETHRTIME
|
|
Packit Service |
c5cf8c |
#include "mpl_timer_gethrtime.h"
|
|
Packit Service |
c5cf8c |
#elif MPL_TIMER_KIND == MPL_TIMER_KIND__CLOCK_GETTIME
|
|
Packit Service |
c5cf8c |
#include "mpl_timer_clock_gettime.h"
|
|
Packit Service |
c5cf8c |
#elif MPL_TIMER_KIND == MPL_TIMER_KIND__GETTIMEOFDAY
|
|
Packit Service |
c5cf8c |
#include "mpl_timer_gettimeofday.h"
|
|
Packit Service |
c5cf8c |
#elif MPL_TIMER_KIND == MPL_TIMER_KIND__LINUX86_CYCLE
|
|
Packit Service |
c5cf8c |
#include "mpl_timer_linux86_cycle.h"
|
|
Packit Service |
c5cf8c |
#elif MPL_TIMER_KIND == MPL_TIMER_KIND__QUERYPERFORMANCECOUNTER
|
|
Packit Service |
c5cf8c |
#include "mpl_timer_query_performance_counter.h"
|
|
Packit Service |
c5cf8c |
#elif MPL_TIMER_KIND == MPL_TIMER_KIND__WIN86_CYCLE || MPL_TIMER_KIND == MPL_TIMER_KIND__WIN64_CYCLE
|
|
Packit Service |
c5cf8c |
#include "mpl_timer_win86_cycle.h"
|
|
Packit Service |
c5cf8c |
#elif MPL_TIMER_KIND == MPL_TIMER_KIND__GCC_IA64_CYCLE
|
|
Packit Service |
c5cf8c |
#include "mpl_timer_gcc_ia64_cycle.h"
|
|
Packit Service |
c5cf8c |
#elif MPL_TIMER_KIND == MPL_TIMER_KIND__DEVICE
|
|
Packit Service |
c5cf8c |
#include "mpl_timer_device.h"
|
|
Packit Service |
c5cf8c |
#elif MPL_TIMER_KIND == MPL_TIMER_KIND__MACH_ABSOLUTE_TIME
|
|
Packit Service |
c5cf8c |
#include "mpl_timer_mach_absolute_time.h"
|
|
Packit Service |
c5cf8c |
#elif MPL_TIMER_KIND == MPL_TIMER_KIND__PPC64_CYCLE
|
|
Packit Service |
c5cf8c |
#include "mpl_timer_ppc64_cycle.h"
|
|
Packit Service |
c5cf8c |
#endif
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/*
|
|
Packit Service |
c5cf8c |
* Prototypes. These are defined here so that inlined timer calls can
|
|
Packit Service |
c5cf8c |
* use them, as well as any profiling and timing code that is built into
|
|
Packit Service |
c5cf8c |
* MPL
|
|
Packit Service |
c5cf8c |
*/
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
#if defined MPLI_WTIME_IS_A_FUNCTION
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/*@
|
|
Packit Service |
c5cf8c |
MPL_wtime - Return a time stamp
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
Output Parameter:
|
|
Packit Service |
c5cf8c |
. timeval - A pointer to an 'MPL_wtime_t' variable.
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
Notes:
|
|
Packit Service |
c5cf8c |
This routine returns an `opaque` time value. This difference between two
|
|
Packit Service |
c5cf8c |
time values returned by 'MPL_wtime' can be converted into an elapsed time
|
|
Packit Service |
c5cf8c |
in seconds with the routine 'MPL_wtime_diff'.
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
This routine is defined this way to simplify its implementation as a macro.
|
|
Packit Service |
c5cf8c |
For example, the for Intel x86 and gcc,
|
|
Packit Service |
c5cf8c |
.vb
|
|
Packit Service |
c5cf8c |
#define MPL_wtime(timeval) \
|
|
Packit Service |
c5cf8c |
__asm__ __volatile__("rdtsc" : "=A" (*timeval))
|
|
Packit Service |
c5cf8c |
.ve
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
For some purposes, it is important
|
|
Packit Service |
c5cf8c |
that the timer calls change the timing of the code as little as possible.
|
|
Packit Service |
c5cf8c |
This form of a timer routine provides for a very fast timer that has
|
|
Packit Service |
c5cf8c |
minimal impact on the rest of the code.
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
From a semantic standpoint, this format emphasizes that any particular
|
|
Packit Service |
c5cf8c |
timer value has no meaning; only the difference between two values is
|
|
Packit Service |
c5cf8c |
meaningful.
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
Module:
|
|
Packit Service |
c5cf8c |
Timer
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
Question:
|
|
Packit Service |
c5cf8c |
MPI-2 allows 'MPI_Wtime' to be a macro. We should make that easy; this
|
|
Packit Service |
c5cf8c |
version does not accomplish that.
|
|
Packit Service |
c5cf8c |
@*/
|
|
Packit Service |
c5cf8c |
int MPL_wtime(MPL_time_t * timeval);
|
|
Packit Service |
c5cf8c |
#endif /* MPLI_WTIME_IS_A_FUNCTION */
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/*@
|
|
Packit Service |
c5cf8c |
MPL_wtime_diff - Compute the difference between two time stamps
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
Input Parameters:
|
|
Packit Service |
c5cf8c |
. t1, t2 - Two time values set by 'MPL_wtime' on this process.
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
Output Parameter:
|
|
Packit Service |
c5cf8c |
. diff - The different in time between t2 and t1, measured in seconds.
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
Note:
|
|
Packit Service |
c5cf8c |
If 't1' is null, then 't2' is assumed to be differences accumulated with
|
|
Packit Service |
c5cf8c |
'MPL_wtime_acc', and the output value gives the number of seconds that
|
|
Packit Service |
c5cf8c |
were accumulated.
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
Question:
|
|
Packit Service |
c5cf8c |
Instead of handling a null value of 't1', should we have a separate
|
|
Packit Service |
c5cf8c |
routine 'MPL_wtime_todouble' that converts a single timestamp to a
|
|
Packit Service |
c5cf8c |
double value?
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
Module:
|
|
Packit Service |
c5cf8c |
Timer
|
|
Packit Service |
c5cf8c |
@*/
|
|
Packit Service |
c5cf8c |
int MPL_wtime_diff(MPL_time_t * t1, MPL_time_t * t2, double *diff);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/*@
|
|
Packit Service |
c5cf8c |
MPL_wtime_acc - Accumulate time values
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
Input Parameters:
|
|
Packit Service |
c5cf8c |
. t1,t2,t3 - Three time values. 't3' is updated with the difference between
|
|
Packit Service |
c5cf8c |
't2' and 't1': '*t3 += (t2 - t1)'.
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
Notes:
|
|
Packit Service |
c5cf8c |
This routine is used to accumulate the time spent with a block of code
|
|
Packit Service |
c5cf8c |
without first converting the time stamps into a particular arithmetic
|
|
Packit Service |
c5cf8c |
type such as a 'double'. For example, if the 'MPL_wtime' routine accesses
|
|
Packit Service |
c5cf8c |
a cycle counter, this routine (or macro) can perform the accumulation using
|
|
Packit Service |
c5cf8c |
integer arithmetic.
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
To convert a time value accumulated with this routine, use 'MPL_wtime_diff'
|
|
Packit Service |
c5cf8c |
with a 't1' of zero.
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
Module:
|
|
Packit Service |
c5cf8c |
Timer
|
|
Packit Service |
c5cf8c |
@*/
|
|
Packit Service |
c5cf8c |
int MPL_wtime_acc(MPL_time_t * t1, MPL_time_t * t2, MPL_time_t * t3);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/*@
|
|
Packit Service |
c5cf8c |
MPL_wtime_todouble - Converts a timestamp to a double
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
Input Parameter:
|
|
Packit Service |
c5cf8c |
. timeval - 'MPL_time_t' time stamp
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
Output Parameter:
|
|
Packit Service |
c5cf8c |
. seconds - Time in seconds from an arbitrary (but fixed) time in the past
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
Notes:
|
|
Packit Service |
c5cf8c |
This routine may be used to change a timestamp into a number of seconds,
|
|
Packit Service |
c5cf8c |
suitable for 'MPI_Wtime'.
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
@*/
|
|
Packit Service |
c5cf8c |
int MPL_wtime_todouble(MPL_time_t * timeval, double *seconds);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/*@
|
|
Packit Service |
c5cf8c |
MPL_wtick - Provide the resolution of the 'MPL_wtime' timer
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
Return value:
|
|
Packit Service |
c5cf8c |
Resolution of the timer in seconds. In many cases, this is the
|
|
Packit Service |
c5cf8c |
time between ticks of the clock that 'MPL_wtime' returns. In other
|
|
Packit Service |
c5cf8c |
words, the minimum significant difference that can be computed by
|
|
Packit Service |
c5cf8c |
'MPL_wtime_diff'.
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
Note that in some cases, the resolution may be estimated. No application
|
|
Packit Service |
c5cf8c |
should expect either the same estimate in different runs or the same
|
|
Packit Service |
c5cf8c |
value on different processes.
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
Module:
|
|
Packit Service |
c5cf8c |
Timer
|
|
Packit Service |
c5cf8c |
@*/
|
|
Packit Service |
c5cf8c |
int MPL_wtick(double *);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/*@
|
|
Packit Service |
c5cf8c |
MPL_wtime_init - Initialize the timer
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
Note:
|
|
Packit Service |
c5cf8c |
This routine should perform any steps needed to initialize the timer.
|
|
Packit Service |
c5cf8c |
In addition, it should set the value of the attribute 'MPI_WTIME_IS_GLOBAL'
|
|
Packit Service |
c5cf8c |
if the timer is known to be the same for all processes in 'MPI_COMM_WORLD'
|
|
Packit Service |
c5cf8c |
(the value is zero by default).
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
Module:
|
|
Packit Service |
c5cf8c |
Timer
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
@*/
|
|
Packit Service |
c5cf8c |
int MPL_wtime_init(void);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/*
|
|
Packit Service |
c5cf8c |
* For timers that do not have defined resolutions, compute the resolution
|
|
Packit Service |
c5cf8c |
* by sampling the clock itself.
|
|
Packit Service |
c5cf8c |
*
|
|
Packit Service |
c5cf8c |
*/
|
|
Packit Service |
c5cf8c |
static double tickval = -1.0;
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
static void init_wtick(void) ATTRIBUTE((unused));
|
|
Packit Service |
c5cf8c |
static void init_wtick(void)
|
|
Packit Service |
c5cf8c |
{
|
|
Packit Service |
c5cf8c |
double timediff;
|
|
Packit Service |
c5cf8c |
MPL_time_t t1, t2;
|
|
Packit Service |
c5cf8c |
int cnt;
|
|
Packit Service |
c5cf8c |
int icnt;
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
tickval = 1.0e6;
|
|
Packit Service |
c5cf8c |
for (icnt = 0; icnt < 10; icnt++) {
|
|
Packit Service |
c5cf8c |
cnt = 1000;
|
|
Packit Service |
c5cf8c |
MPL_wtime(&t1;;
|
|
Packit Service |
c5cf8c |
do {
|
|
Packit Service |
c5cf8c |
MPL_wtime(&t2;;
|
|
Packit Service |
c5cf8c |
MPL_wtime_diff(&t1, &t2, &timediff);
|
|
Packit Service |
c5cf8c |
if (timediff > 0)
|
|
Packit Service |
c5cf8c |
break;
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
while (cnt--);
|
|
Packit Service |
c5cf8c |
if (cnt && timediff > 0.0 && timediff < tickval) {
|
|
Packit Service |
c5cf8c |
MPL_wtime_diff(&t1, &t2, &tickval);
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
#endif /* !defined(MPL_TIMER_H_INCLUDED) */
|