1
1

ompi/timings: preparing to production state

Adds:
- enabling/disabling of timings throught environment variable `OMPI_TIMING_ENABLE`
- output format: [file name]:[function name]:[description]: avg/min/max
- dynamically extending array of results for case then inited size was exhausted
- catch and collect errors
- cleanup

Note:
For use feature need to configure with `--enable-timings`
and set env `OMPI_TIMING_ENABLE = 1`

Signed-off-by: Boris Karasev <karasev.b@gmail.com>
Этот коммит содержится в:
Boris Karasev 2017-03-29 20:01:05 +06:00
родитель e3acf2a339
Коммит 36a0e71f2d
3 изменённых файлов: 341 добавлений и 245 удалений

Просмотреть файл

@ -950,6 +950,7 @@ int ompi_mpi_init(int argc, char **argv, int requested, int *provided)
} }
opal_mutex_unlock(&ompi_mpi_bootstrap_mutex); opal_mutex_unlock(&ompi_mpi_bootstrap_mutex);
ompi_hook_base_mpi_init_error(argc, argv, requested, provided); ompi_hook_base_mpi_init_error(argc, argv, requested, provided);
OMPI_TIMING_FINALIZE;
return ret; return ret;
} }
@ -976,6 +977,7 @@ int ompi_mpi_init(int argc, char **argv, int requested, int *provided)
* and clear timing structure */ * and clear timing structure */
OMPI_TIMING_NEXT("barrier-finish"); OMPI_TIMING_NEXT("barrier-finish");
OMPI_TIMING_OUT; OMPI_TIMING_OUT;
OMPI_TIMING_FINALIZE;
opal_mutex_unlock(&ompi_mpi_bootstrap_mutex); opal_mutex_unlock(&ompi_mpi_bootstrap_mutex);

Просмотреть файл

@ -4,123 +4,212 @@
#include "opal/util/timings.h" #include "opal/util/timings.h"
/* TODO: we need access to MPI_* functions */ /* TODO: we need access to MPI_* functions */
#if (0 && OPAL_ENABLE_TIMING) #if (OPAL_ENABLE_TIMING)
/* TODO: replace with opal_timing function */ typedef struct {
static inline double OMPI_TIMING_GET_TS(void) char desc[OPAL_TIMING_STR_LEN];
{ double ts;
struct timespec ts; char *file;
double ret; char *prefix;
clock_gettime(CLOCK_MONOTONIC, &ts); } ompi_timing_val_t;
ret = ts.tv_sec + 1E-9 * ts.tv_nsec;
return ret; typedef struct {
ompi_timing_val_t *val;
int use;
struct ompi_timing_list_t *next;
} ompi_timing_list_t;
typedef struct ompi_timing_t {
double ts;
const char *prefix;
int size;
int cnt;
int error;
int enabled;
opal_timing_ts_func_t get_ts;
ompi_timing_list_t *timing;
ompi_timing_list_t *cur_timing;
} ompi_timing_t;
#define OMPI_TIMING_INIT(_size) \
ompi_timing_t OMPI_TIMING; \
OMPI_TIMING.prefix = __FUNCTION__; \
OMPI_TIMING.size = _size; \
OMPI_TIMING.get_ts = opal_timing_ts_func(OPAL_TIMING_AUTOMATIC_TIMER); \
OMPI_TIMING.cnt = 0; \
OMPI_TIMING.error = 0; \
OMPI_TIMING.ts = OMPI_TIMING.get_ts(); \
OMPI_TIMING.enabled = 0; \
{ \
char *ptr; \
ptr = getenv("OMPI_TIMING_ENABLE"); \
if (NULL != ptr) { \
OMPI_TIMING.enabled = atoi(ptr); \
} \
if (OMPI_TIMING.enabled) { \
setenv("OPAL_TIMING_ENABLE", "1", 1); \
OMPI_TIMING.timing = (ompi_timing_list_t*)malloc(sizeof(ompi_timing_list_t)); \
memset(OMPI_TIMING.timing, 0, sizeof(ompi_timing_list_t)); \
OMPI_TIMING.timing->val = (ompi_timing_val_t*)malloc(sizeof(ompi_timing_val_t) * _size); \
OMPI_TIMING.cur_timing = OMPI_TIMING.timing; \
} \
}
#define OMPI_TIMING_ITEM_EXTEND ({ \
if (OMPI_TIMING.enabled) { \
OMPI_TIMING.cur_timing->next = (struct ompi_timing_list_t*)malloc(sizeof(ompi_timing_list_t)); \
OMPI_TIMING.cur_timing = (ompi_timing_list_t*)OMPI_TIMING.cur_timing->next; \
memset(OMPI_TIMING.cur_timing, 0, sizeof(ompi_timing_list_t)); \
OMPI_TIMING.cur_timing->val = malloc(sizeof(ompi_timing_val_t) * OMPI_TIMING.size); \
} \
})
#define OMPI_TIMING_FINALIZE ({ \
if (OMPI_TIMING.enabled) { \
ompi_timing_list_t *t = OMPI_TIMING.timing, *tmp; \
while ( NULL != t) { \
tmp = t; \
t = t->next; \
free(tmp->val); \
free(tmp); \
} \
OMPI_TIMING.timing = NULL; \
OMPI_TIMING.cur_timing = NULL; \
OMPI_TIMING.cnt = 0; \
} \
})
#define OMPI_TIMING_NEXT(fmt, ...) ({ \
if (!OMPI_TIMING.error && OMPI_TIMING.enabled) { \
char *f = strrchr(__FILE__, '/') + 1; \
int len = 0; \
if (OMPI_TIMING.cur_timing->use >= OMPI_TIMING.size){ \
OMPI_TIMING_ITEM_EXTEND; \
} \
len = snprintf(OMPI_TIMING.cur_timing->val[OMPI_TIMING.cur_timing->use].desc, \
OPAL_TIMING_STR_LEN, fmt, ##__VA_ARGS__); \
if (len >= OPAL_TIMING_STR_LEN) { \
OMPI_TIMING.error = 1; \
} \
OMPI_TIMING.cur_timing->val[OMPI_TIMING.cur_timing->use].file = f; \
OMPI_TIMING.cur_timing->val[OMPI_TIMING.cur_timing->use].prefix = __FUNCTION__; \
OMPI_TIMING.cur_timing->val[OMPI_TIMING.cur_timing->use++].ts = \
OMPI_TIMING.get_ts() - OMPI_TIMING.ts; \
OMPI_TIMING.cnt++; \
OMPI_TIMING.ts = OMPI_TIMING.get_ts(); \
} \
})
#define OMPI_TIMING_APPEND(filename,func,desc,ts) { \
if (OMPI_TIMING.cur_timing->use >= OMPI_TIMING.size){ \
OMPI_TIMING_ITEM_EXTEND; \
} \
int len = snprintf(OMPI_TIMING.cur_timing->val[OMPI_TIMING.cur_timing->use].desc, \
OPAL_TIMING_STR_LEN, "%s", desc); \
if (len >= OPAL_TIMING_STR_LEN) { \
OMPI_TIMING.error = 1; \
} \
OMPI_TIMING.cur_timing->val[OMPI_TIMING.cur_timing->use].prefix = func; \
OMPI_TIMING.cur_timing->val[OMPI_TIMING.cur_timing->use].file = filename; \
OMPI_TIMING.cur_timing->val[OMPI_TIMING.cur_timing->use++].ts = \
OMPI_TIMING.get_ts() - OMPI_TIMING.ts; \
OMPI_TIMING.cnt++; \
OMPI_TIMING.ts = OMPI_TIMING.get_ts(); \
} }
/* TODO: #define OMPI_TIMING_IMPORT_OPAL_PREFIX(_prefix, func) { \
* - create a structure to hold this variables if (!OMPI_TIMING.error && OMPI_TIMING.enabled) { \
* - use dyncamically extendable arrays int cnt = OPAL_TIMING_ENV_CNT(func); \
*/ int i; \
#define OMPI_TIMING_INIT(inum) \ OMPI_TIMING.error = OPAL_TIMING_ENV_ERROR_PREFIX(_prefix, func); \
double OMPI_TIMING_ts = OMPI_TIMING_GET_TS(); \ for(i = 0; i < cnt; i++){ \
const char *OMPI_TIMING_prefix = __FUNCTION__; \ char *desc, *filename; \
int OMPI_TIMING_cnt = 0; \ double ts = OPAL_TIMING_ENV_GETDESC_PREFIX(_prefix, &filename, func, i, &desc); \
int OMPI_TIMING_inum = inum; \ OMPI_TIMING_APPEND(filename, func, desc, ts); \
double OMPI_TIMING_in[inum] = { 0.0 }; \ } \
double OMPI_TIMING_max[inum] = { 0.0 }; \ } \
double OMPI_TIMING_min[inum] = { 0.0 }; \
double OMPI_TIMING_avg[inum] = { 0.0 }; \
char *OMPI_TIMING_desc[inum] = { 0 }; \
/* TODO: provide printf-like interfase allowing to build a string
* at runtime, like OPAL_TIMING_NEXT()
*/
#define OMPI_TIMING_NEXT(desc) { \
char *ptr = strrchr(__FILE__, '/'); \
if( NULL == ptr ){ \
ptr = __FILE__; \
} else { \
ptr++; \
} \
if( OMPI_TIMING_inum <= OMPI_TIMING_cnt ){ \
printf("OMPI_TIMING [%s:%d %s]: interval count overflow!!\n", \
ptr, __LINE__, __FUNCTION__); \
abort(); \
} \
OMPI_TIMING_in[OMPI_TIMING_cnt] = OMPI_TIMING_GET_TS() - OMPI_TIMING_ts; \
OMPI_TIMING_desc[OMPI_TIMING_cnt++] = desc; \
OMPI_TIMING_ts = OMPI_TIMING_GET_TS(); \
} }
#define OMPI_TIMING_APPEND(desc,ts) { \ #define OMPI_TIMING_IMPORT_OPAL(func) \
char *ptr = strrchr(__FILE__, '/'); \ OMPI_TIMING_IMPORT_OPAL_PREFIX("", func)
if( NULL == ptr ){ \
ptr = __FILE__; \
} else { \
ptr++; \
} \
if( OMPI_TIMING_inum <= OMPI_TIMING_cnt ){ \
printf("OMPI_TIMING [%s:%d %s]: interval count overflow!!\n", \
ptr, __LINE__, __FUNCTION__); \
abort(); \
} \
OMPI_TIMING_in[OMPI_TIMING_cnt] = ts; \
OMPI_TIMING_desc[OMPI_TIMING_cnt++] = desc; \
}
#define OMPI_TIMING_IMPORT_OPAL(func) { \
char *enabled; \
int cnt = OPAL_TIMING_ENV_CNT(func); \
if( 0 < cnt ) { \
char ename[256]; \
sprintf(ename, "OMPI_TIMING_%s", OMPI_TIMING_prefix); \
setenv(ename, "1", 1); \
} \
int i; \
for(i = 0; i < cnt; i++){ \
char *desc; \
double ts = OPAL_TIMING_ENV_GETDESC(prefix, i, &desc); \
OMPI_TIMING_APPEND(desc, ts); \
} \
}
#define OMPI_TIMING_OUT { \
int i, size, rank; \ #define OMPI_TIMING_OUT ({ \
MPI_Comm_size(MPI_COMM_WORLD, &size); \ if (OMPI_TIMING.enabled) { \
MPI_Comm_rank(MPI_COMM_WORLD, &rank); \ int i, size, rank; \
char ename[1024]; \ MPI_Comm_size(MPI_COMM_WORLD, &size); \
sprintf(ename, "OMPI_TIMING_%s", OMPI_TIMING_prefix); \ MPI_Comm_rank(MPI_COMM_WORLD, &rank); \
char *ptr = getenv(ename); \ int error = 0; \
\ \
if( NULL != ptr ) { \ MPI_Reduce(&OMPI_TIMING.error, &error, 1, \
OMPI_TIMING_ts = OMPI_TIMING_GET_TS(); \ MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD); \
MPI_Reduce(OMPI_TIMING_in, OMPI_TIMING_avg, OMPI_TIMING_cnt, MPI_DOUBLE, \ \
MPI_SUM, 0, MPI_COMM_WORLD); \ if (error) { \
MPI_Reduce(OMPI_TIMING_in, OMPI_TIMING_min, OMPI_TIMING_cnt, MPI_DOUBLE, \ if (0 == rank) { \
MPI_MIN, 0, MPI_COMM_WORLD); \ printf("==OMPI_TIMING== error: something went wrong, timings doesn't work\n"); \
MPI_Reduce(OMPI_TIMING_in, OMPI_TIMING_max, OMPI_TIMING_cnt, MPI_DOUBLE, \ } \
MPI_MAX, 0, MPI_COMM_WORLD); \ } \
\ else { \
if( 0 == rank ){ \ double *avg = (double*)malloc(sizeof(double) * OMPI_TIMING.cnt); \
printf("------------------ %s ------------------\n", \ double *min = (double*)malloc(sizeof(double) * OMPI_TIMING.cnt); \
OMPI_TIMING_prefix); \ double *max = (double*)malloc(sizeof(double) * OMPI_TIMING.cnt); \
for(i=0; i< OMPI_TIMING_cnt; i++){ \ char **desc = (char**)malloc(sizeof(char*) * OMPI_TIMING.cnt); \
OMPI_TIMING_avg[i] /= size; \ char **prefix = (char**)malloc(sizeof(char*) * OMPI_TIMING.cnt); \
printf("[%s:%s]: %lf / %lf / %lf\n", \ char **file = (char**)malloc(sizeof(char*) * OMPI_TIMING.cnt); \
OMPI_TIMING_prefix,OMPI_TIMING_desc[i], \ \
OMPI_TIMING_avg[i], OMPI_TIMING_min[i], OMPI_TIMING_max[i]); \ if( OMPI_TIMING.cnt > 0 ) { \
} \ OMPI_TIMING.ts = OMPI_TIMING.get_ts(); \
printf("[%s:overhead]: %lf \n", OMPI_TIMING_prefix, \ ompi_timing_list_t *timing = OMPI_TIMING.timing; \
OMPI_TIMING_GET_TS() - OMPI_TIMING_ts); \ i = 0; \
} \ do { \
} \ int use; \
} for (use = 0; use < timing->use; use++) { \
MPI_Reduce(&timing->val[use].ts, avg + i, 1, \
MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD); \
MPI_Reduce(&timing->val[use].ts, min + i, 1, \
MPI_DOUBLE, MPI_MIN, 0, MPI_COMM_WORLD); \
MPI_Reduce(&timing->val[use].ts, max + i, 1, \
MPI_DOUBLE, MPI_MAX, 0, MPI_COMM_WORLD); \
desc[i] = timing->val[use].desc; \
prefix[i] = timing->val[use].prefix; \
file[i] = timing->val[use].file; \
i++; \
} \
timing = (ompi_timing_list_t*)timing->next; \
} while (timing != NULL); \
\
if( 0 == rank ){ \
if (OMPI_TIMING.timing->next) { \
printf("==OMPI_TIMING== warning: added the extra timings allocation that might misrepresent the results.\n" \
"==OMPI_TIMING== Increase the inited size of timings to avoid extra allocation during runtime.\n"); \
} \
\
printf("------------------ %s ------------------\n", \
OMPI_TIMING.prefix); \
for(i=0; i< OMPI_TIMING.cnt; i++){ \
avg[i] /= size; \
printf("[%s:%s:%s]: %lf / %lf / %lf\n", \
file[i], prefix[i], desc[i], avg[i], min[i], max[i]); \
} \
printf("[%s:overhead]: %lf \n", OMPI_TIMING.prefix, \
OMPI_TIMING.get_ts() - OMPI_TIMING.ts); \
} \
} \
free(avg); \
free(min); \
free(max); \
free(desc); \
free(prefix); \
free(file); \
} \
} \
})
#else #else
#define OMPI_TIMING_INIT(inum) #define OMPI_TIMING_INIT(size)
#define OMPI_TIMING_NEXT(desc) #define OMPI_TIMING_NEXT(fmt, ...)
#define OMPI_TIMING_APPEND(desc,ts) #define OMPI_TIMING_APPEND(desc,ts)
@ -128,6 +217,8 @@ static inline double OMPI_TIMING_GET_TS(void)
#define OMPI_TIMING_IMPORT_OPAL(func) #define OMPI_TIMING_IMPORT_OPAL(func)
#define OMPI_TIMING_FINALIZE
#endif #endif
#endif #endif

Просмотреть файл

@ -28,6 +28,7 @@ typedef enum {
typedef double (*opal_timing_ts_func_t)(void); typedef double (*opal_timing_ts_func_t)(void);
#define OPAL_TIMING_STR_LEN 256 #define OPAL_TIMING_STR_LEN 256
typedef struct { typedef struct {
char id[OPAL_TIMING_STR_LEN], cntr_env[OPAL_TIMING_STR_LEN]; char id[OPAL_TIMING_STR_LEN], cntr_env[OPAL_TIMING_STR_LEN];
int enabled, error; int enabled, error;
@ -38,54 +39,46 @@ typedef struct {
opal_timing_ts_func_t opal_timing_ts_func(opal_timer_type_t type); opal_timing_ts_func_t opal_timing_ts_func(opal_timer_type_t type);
#define OPAL_TIMING_ENV_START_TYPE(func, type, prefix) ({ \
opal_timing_env_t h; \
char *ptr = NULL; \
char *_prefix = prefix; \
int n; \
if( NULL == prefix ){ \
_prefix = ""; \
} \
h.error = 0; \
n = snprintf(h.id, OPAL_TIMING_STR_LEN, "%s%s", _prefix, func); \
if( n > OPAL_TIMING_STR_LEN ){ \
h.error = 1; \
} \
n = sprintf(h.cntr_env,"OMPI_TIMING_%s%s_CNT", prefix, h.id); \
if( n > OPAL_TIMING_STR_LEN ){ \
h.error = 1; \
} \
ptr = getenv(h.id); \
if( NULL == ptr || strcmp(ptr, "1")){ \
h.enabled = 0; \
} \
h.get_ts = opal_timing_ts_func(type); \
ptr = getenv("OPAL_TIMING_ENABLE"); \
if (NULL != ptr) { \
h.enabled = atoi(ptr); \
} \
h.cntr = 0; \
ptr = getenv(h.id); \
if( NULL != ptr ){ \
h.cntr = atoi(ptr); \
} \
h.ts = h.get_ts(); \
if ( 0 != h.error ){ \
h.enabled = 0; \
} \
h; \
})
/* TODO: turn as much as possible into macro's #define OPAL_TIMING_ENV_INIT(name) \
* once debugged opal_timing_env_t name ## _val, *name = &(name ## _val); \
*/
static inline opal_timing_env_t
OPAL_TIMING_ENV_START_TYPE(char *func, opal_timer_type_t type, char *prefix)
{
opal_timing_env_t h;
int n;
/* TODO: remove this when tested! */
h.enabled = 0;
return h;
if( NULL == prefix ){
prefix = "";
}
h.error = 0;
n = snprintf(h.id, OPAL_TIMING_STR_LEN, "%s%s", prefix, func);
if( n > OPAL_TIMING_STR_LEN ){
/* TODO: output truncated:
* disable this timing and set the error
* sign
*/
}
/* TODO same length check here */
sprintf(h.cntr_env,"%s_CNT", h.id);
h.get_ts = opal_timing_ts_func(type);
h.ts = h.get_ts();
h.enabled = 1;
char *ptr = getenv(h.id);
if( NULL == ptr || strcmp(ptr, "1")){
h.enabled = 0;
}
ptr = getenv(h.cntr_env);
h.cntr = 0;
if( NULL != ptr ){
h.cntr = atoi(ptr);
}
return h;
}
#define OPAL_TIMING_ENV_INIT(name) \
opal_timing_env_t name ## _val, *name = &(name ## _val); \
*name = OPAL_TIMING_ENV_START_TYPE(__FUNCTION__, OPAL_TIMING_AUTOMATIC_TIMER, ""); *name = OPAL_TIMING_ENV_START_TYPE(__FUNCTION__, OPAL_TIMING_AUTOMATIC_TIMER, "");
/* We use function names for identification /* We use function names for identification
@ -94,104 +87,115 @@ OPAL_TIMING_ENV_START_TYPE(char *func, opal_timer_type_t type, char *prefix)
* conflict. * conflict.
* Use prefix to do a finer-grained identification if needed * Use prefix to do a finer-grained identification if needed
*/ */
#define OPAL_TIMING_ENV_INIT_PREFIX(prefix, name) \ #define OPAL_TIMING_ENV_INIT_PREFIX(prefix, name) \
opal_timing_env_t name ## _val, *name = &(name ## _val); \ opal_timing_env_t name ## _val, *name = &(name ## _val); \
name = OPAL_TIMING_ENV_START_TYPE(__FUNCTION__, OPAL_TIMING_AUTOMATIC_TIMER, prefix); *name = OPAL_TIMING_ENV_START_TYPE(__FUNCTION__, OPAL_TIMING_AUTOMATIC_TIMER, prefix);
#define OPAL_TIMING_ENV_NEXT(h, fmt, ...) ({ \
/* TODO: according to https://en.wikipedia.org/wiki/C99 int n; \
* varadic macroses are part of C99 and C11. Is it safe to use them here? char buf1[OPAL_TIMING_STR_LEN], buf2[OPAL_TIMING_STR_LEN]; \
*/ double time; \
static inline void char *filename; \
OPAL_TIMING_ENV_NEXT(opal_timing_env_t *h, char *fmt, ... ) if( h->enabled ){ \
{ /* enabled codepath */ \
if( !h->enabled ){ time = h->get_ts() - h->ts; \
return; n = snprintf(buf1, OPAL_TIMING_STR_LEN, "OMPI_TIMING_%s_DESC_%d", h->id, h->cntr); \
} if ( n > OPAL_TIMING_STR_LEN ){ \
/* enabled codepath */ h->error = 1; \
va_list ap; } \
int n; n = snprintf(buf2, OPAL_TIMING_STR_LEN, fmt, ## __VA_ARGS__ ); \
char buf[256], buf2[256]; if ( n > OPAL_TIMING_STR_LEN ){ \
double time = h->get_ts() - h->ts; h->error = 1; \
} \
sprintf(buf, "%s_DESC_%d", h->id, h->cntr); setenv(buf1, buf2, 1); \
/* TODO: check that write succeded */ n = snprintf(buf1, OPAL_TIMING_STR_LEN, "OMPI_TIMING_%s_VAL_%d", h->id, h->cntr); \
if ( n > OPAL_TIMING_STR_LEN ){ \
va_start(ap, fmt); h->error = 1; \
n= vsnprintf(buf2, 256, fmt, ap); } \
/* TODO: check that write succeded */ n = snprintf(buf2, OPAL_TIMING_STR_LEN, "%lf", time); \
va_end(ap); if ( n > OPAL_TIMING_STR_LEN ){ \
h->error = 1; \
setenv(buf, buf2, 1); } \
setenv(buf1, buf2, 1); \
sprintf(buf, "%s_VAL_%d", h->id, h->cntr); filename = strrchr(__FILE__, '/') + 1; \
/* TODO: check that write succeded */ n = snprintf(buf1, OPAL_TIMING_STR_LEN, "OMPI_TIMING_%s_FILE_%d", h->id, h->cntr); \
sprintf(buf2, "%lf", time); if ( n > OPAL_TIMING_STR_LEN ){ \
/* TODO: check that write succeded */ h->error = 1; \
setenv(buf, buf2, 1); } \
n = snprintf(buf2, OPAL_TIMING_STR_LEN, "%s", filename); \
h->cntr++; if ( n > OPAL_TIMING_STR_LEN ){ \
sprintf(buf, "%d", h->cntr); h->error = 1; \
setenv(h->cntr_env, buf, 1); } \
setenv(buf1, buf2, 1); \
/* We don't include env operations into the consideration. h->cntr++; \
* Hopefully this will help to make measurements more accurate. sprintf(buf1, "%d", h->cntr); \
*/ setenv(h->cntr_env, buf1, 1); \
h->ts = h->get_ts(); /* We don't include env operations into the consideration.
} * Hopefully this will help to make measurements more accurate.
*/ \
h->ts = h->get_ts(); \
} \
if (h->error) { \
n = snprintf(buf1, OPAL_TIMING_STR_LEN, "OMPI_TIMING_%s_ERROR", h->id);\
if ( n > OPAL_TIMING_STR_LEN ){ \
h->error = 1; \
} \
n = snprintf(buf2, OPAL_TIMING_STR_LEN, "%d", h->error); \
if ( n > OPAL_TIMING_STR_LEN ){ \
h->error = 1; \
} \
setenv(buf1, buf2, 1); \
} \
})
/* This function supposed to be called from the code that will /* This function supposed to be called from the code that will
* do the postprocessing, i.e. OMPI timing portion that will * do the postprocessing, i.e. OMPI timing portion that will
* do the reduction of accumulated values * do the reduction of accumulated values
*/ */
/* TODO: turn into a macro */ #define OPAL_TIMING_ENV_CNT_PREFIX(prefix, func) ({ \
static inline int OPAL_TIMING_ENV_CNT_PREFIX(char *prefix, char *func) char ename[OPAL_TIMING_STR_LEN]; \
{ int cnt = 0; \
char ename[256]; char *ptr = NULL; \
sprintf(ename, "%s%s_CNT", prefix, func); int n = snprintf(ename, OPAL_TIMING_STR_LEN, "OMPI_TIMING_%s%s_CNT", prefix, func); \
char *ptr = getenv(ename); if ( n <= OPAL_TIMING_STR_LEN ){ \
if( !ptr ){ ptr = getenv(ename); \
return 0; if( NULL != ptr ){ cnt = atoi(ptr); }; \
} } \
return atoi(ptr); cnt; \
} })
#define OPAL_TIMING_ENV_CNT(func) \ #define OPAL_TIMING_ENV_ERROR_PREFIX(prefix, func) ({ \
OPAL_TIMING_ENV_CNT_PREFIX("", char *func) char ename[OPAL_TIMING_STR_LEN]; \
int error = 0; \
char *ptr = NULL; \
int n = snprintf(ename, OPAL_TIMING_STR_LEN, "OMPI_TIMING_%s%s_ERROR", prefix, func); \
if ( n <= OPAL_TIMING_STR_LEN ){ \
ptr = getenv(ename); \
if( NULL != ptr ){ error = atoi(ptr); }; \
} \
error; \
})
/* TODO: make a macro */ #define OPAL_TIMING_ENV_CNT(func) \
static inline double OPAL_TIMING_ENV_CNT_PREFIX("", func)
OPAL_TIMING_ENV_GETDESC_PREFIX(char *prefix, char *func, int i, char **desc)
{
char vname[256];
double ts;
sprintf(vname, "%s_INT_%d_DESC", prefix, i);
*desc = getenv(vname);
sprintf(vname, "%s_INT_%d_VAL",prefix, i);
char *ptr = getenv(vname);
sscanf(ptr,"%lf", &ts);
return ts;
}
#define OPAL_TIMING_ENV_GETDESC(func, index, desc) \ #define OPAL_TIMING_ENV_GETDESC_PREFIX(prefix, filename, func, i, desc) ({ \
OPAL_TIMING_ENV_GETDESC_PREFIX("", func, index, desc) char vname[OPAL_TIMING_STR_LEN]; \
double ts = 0.0; \
sprintf(vname, "OMPI_TIMING_%s%s_FILE_%d", prefix, func, i); \
*filename = getenv(vname); \
sprintf(vname, "OMPI_TIMING_%s%s_DESC_%d", prefix, func, i); \
*desc = getenv(vname); \
sprintf(vname, "OMPI_TIMING_%s%s_VAL_%d", prefix, func, i); \
char *ptr = getenv(vname); \
if ( NULL != ptr ) { \
sscanf(ptr,"%lf", &ts); \
} \
ts; \
})
#define OSHTMNG_ENV_APPEND(prefix) { \ #define OPAL_TIMING_ENV_GETDESC(file, func, index, desc) \
char *enabled; \ OPAL_TIMING_ENV_GETDESC_PREFIX("", file, func, index, desc)
int cnt = OSHTMNG_ENV_COUNT(prefix); \
enabled = getenv(prefix); \
if( NULL != enabled && !strcmp(enabled, "1") ) { \
char ename[256]; \
sprintf(ename, "OSHTMNG_%s", OSHTMNG_prefix); \
setenv(ename, "1", 1); \
} \
int i; \
for(i = 0; i < cnt; i++){ \
char *desc; \
double ts = OSHTMNG_ENV_GETBYIDX(prefix, i, &desc); \
OSHTMNG_END1(desc, ts); \
} \
}
#else #else
@ -201,9 +205,6 @@ OPAL_TIMING_ENV_GETDESC_PREFIX(char *prefix, char *func, int i, char **desc)
#define OPAL_TIMING_ENV_INIT_PREFIX(prefix) #define OPAL_TIMING_ENV_INIT_PREFIX(prefix)
/* TODO: according to https://en.wikipedia.org/wiki/C99
* varadic macroses are part of C99 and C11. Is it safe to use them here?
*/
#define OPAL_TIMING_ENV_NEXT(h, fmt, ... ) #define OPAL_TIMING_ENV_NEXT(h, fmt, ... )
#define OPAL_TIMING_ENV_CNT_PREFIX(prefix, func) #define OPAL_TIMING_ENV_CNT_PREFIX(prefix, func)
@ -214,6 +215,8 @@ OPAL_TIMING_ENV_GETDESC_PREFIX(char *prefix, char *func, int i, char **desc)
#define OPAL_TIMING_ENV_GETDESC(func, index, desc) #define OPAL_TIMING_ENV_GETDESC(func, index, desc)
#define OPAL_TIMING_ENV_ERROR_PREFIX(prefix, func)
#endif #endif
#endif #endif