Commit a2299cd5 authored by Junchao Zhang's avatar Junchao Zhang
Browse files

Add a counter into structure MPIR_T_pvar_timer_t

To record how many times a timer is started, so we can easily
calculate the average time of events.

Signed-off-by: Junchao Zhang<jczhang@mcs.anl.gov> (Reviewed by Bill Gropp)
parent c12bbcd8
......@@ -435,6 +435,13 @@ static inline cvar_table_entry_t * LOOKUP_CVAR_BY_NAME(const char* cvar_name)
addr_, count_, verb_, bind_, flags_, get_value_, get_count_, cat_, desc_))
/* TIMER */
/* A timer actually has a twin, i.e., a counter, which counts how many times
the timer is started/stopped so that we could know the average time
for events measured. In our impl, the twins are exposed to MPI_T through the
same name, but in two MPI_T_PVAR classes (timer and counter) and two data types
(double and unsigned long long) respectively.
*/
#define MPIR_T_PVAR_DOUBLE_TIMER_DECL(MODULE, name_) \
PVAR_GATED_DECL(MODULE, MPIR_T_PVAR_DOUBLE_TIMER_DECL_impl(name_))
......@@ -462,16 +469,12 @@ static inline cvar_table_entry_t * LOOKUP_CVAR_BY_NAME(const char* cvar_name)
#define MPIR_T_PVAR_TIMER_END(MODULE, name_) \
PVAR_GATED_ACTION(MODULE, MPIR_T_PVAR_TIMER_END_impl(name_))
/* This macro actually register twins of a timer and a counter to MPIR_T */
#define MPIR_T_PVAR_TIMER_REGISTER_STATIC(MODULE, dtype_, name_, \
verb_, bind_, flags_, cat_, desc_) \
PVAR_GATED_ACTION(MODULE, MPIR_T_PVAR_TIMER_REGISTER_STATIC_impl(dtype_, name_, \
verb_, bind_, flags_, cat_, desc_))
#define MPIR_T_PVAR_TIMER_REGISTER_DYNAMIC(MODULE, dtype_, name_, \
addr_, count_, verb_, bind_, flags_, get_value_, get_count_, cat_, desc_) \
PVAR_GATED_ACTION(MODULE, MPIR_T_PVAR_TIMER_REGISTER_DYNAMIC_impl(dtype_, name_, \
addr_, count_, verb_, bind_, flags_, get_value_, get_count_, cat_, desc_))
/* HIGHWATERMARK */
#define MPIR_T_PVAR_UINT_HIGHWATERMARK_DECL(MODULE, name_) \
PVAR_GATED_DECL(MODULE, MPIR_T_PVAR_UINT_HIGHWATERMARK_DECL_impl(name_))
......
......@@ -241,8 +241,14 @@ typedef struct {
/* Timer type */
typedef struct {
/* Accumulated time */
MPID_Time_t total;
/* Time when the timer was started recently */
MPID_Time_t curstart;
/* A counter recording how many times the timer is started */
unsigned long long count;
} MPIR_T_pvar_timer_t;
/* An union to represent a watermark value */
......@@ -852,6 +858,7 @@ extern void MPIR_T_PVAR_REGISTER_impl(
#define MPIR_T_PVAR_TIMER_START_VAR_impl(ptr_) \
do { \
MPID_Wtime(&((ptr_)->curstart)); \
(ptr_)->count++; \
} while (0)
#define MPIR_T_PVAR_TIMER_END_VAR_impl(ptr_) \
do { \
......@@ -871,7 +878,7 @@ extern void MPIR_T_PVAR_REGISTER_impl(
/* Customized get_value() for MPIR_T_pvar_timer_t */
static inline
void get_timer_in_double(MPIR_T_pvar_timer_t *timer, void *obj_handle,
void get_timer_time_in_double(MPIR_T_pvar_timer_t *timer, void *obj_handle,
int count, double *buf)
{
int i;
......@@ -887,23 +894,13 @@ void get_timer_in_double(MPIR_T_pvar_timer_t *timer, void *obj_handle,
MPIU_Assert(dtype_ == MPI_DOUBLE); \
MPIR_T_PVAR_TIMER_INIT_impl(name_); \
void *addr_ = &PVAR_TIMER_##name_; \
void *count_addr_ = &(PVAR_TIMER_##name_.count); \
MPIR_T_PVAR_REGISTER_impl(MPI_T_PVAR_CLASS_TIMER, dtype_, #name_, \
addr_, 1, MPI_T_ENUM_NULL, verb_, bind_, flags_, \
(MPIR_T_pvar_get_value_cb *)&get_timer_in_double, NULL, cat_, desc_); \
} while (0)
/* Registration for dynamic pvar w/ or w/o callback. Init is left to users.
* (Probably, the callback still is get_timer_in_double)
*/
#define MPIR_T_PVAR_TIMER_REGISTER_DYNAMIC_impl(dtype_, name_, \
addr_, count_, verb_, bind_, flags_, get_value_, get_count_, cat_, desc_) \
do { \
/* Allowable datatypes only */ \
MPIU_Assert(dtype_ == MPI_DOUBLE); \
MPIU_Assert(addr_ != NULL || get_value_ != NULL); \
MPIR_T_PVAR_REGISTER_impl(MPI_T_PVAR_CLASS_TIMER, dtype_, #name_, \
addr_, count_, MPI_T_ENUM_NULL, verb_, bind_, flags_, \
get_value_, get_count_, cat_, desc_); \
(MPIR_T_pvar_get_value_cb *)&get_timer_time_in_double, NULL, cat_, desc_); \
MPIR_T_PVAR_REGISTER_impl(MPI_T_PVAR_CLASS_COUNTER, MPI_UNSIGNED_LONG_LONG, #name_, \
count_addr_, 1, MPI_T_ENUM_NULL, verb_, bind_, flags_, \
NULL, NULL, cat_, desc_); \
} while (0)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment