Commit 595c718a authored by Hendryk Bockelmann's avatar Hendryk Bockelmann
Browse files

add dynamic reallocate of timer space if exceeded while sct_new_timer

parent 015b6364
......@@ -105,9 +105,8 @@ static int icontext = -1;
static int icontext_stack[SCT_MAX_CONTEXT_DEPTH+1];
static int icontext_stack_pos = 0;
// index range for pool data: [0 .. timer_max] == [0 .. timer_size-1]
// index range for pool data: [0 ... timer_size-1]
static int timer_size = 0;
static int timer_max = -1;
// usage of callstats
static int callstats = -1;
......@@ -620,14 +619,12 @@ int sct_new_context(const char* name, sct_comm_type comm) {
con->s[it].tmin = SCT_MAX_TVAL;
con->s[it].active_under = -2;
#ifdef HAVE_LIBPAPI
if (eventcounters) {
// allocate event arrays
sct_internal_alloc_event_arrays(&(con->s[it]), eset->en);
// init arrays of min values
for (int i=0; i<sct_get_event_num(); i++) {
con->s[it].emin[i] = SCT_MAX_EVAL;
con->s[it].rmin[i] = SCT_MAX_TVAL;
}
// allocate event arrays
sct_internal_alloc_event_arrays(&(con->s[it]), sct_get_event_num());
// init arrays of min values
for (int i=0; i<sct_get_event_num(); i++) {
con->s[it].emin[i] = SCT_MAX_EVAL;
con->s[it].rmin[i] = SCT_MAX_TVAL;
}
#endif
}
......@@ -678,15 +675,14 @@ int sct_new_context(const char* name, sct_comm_type comm) {
con->p[tid][it].tmin = SCT_MAX_TVAL;
#ifdef HAVE_LIBPAPI
// allocate event arrays
sct_internal_alloc_event_arrays(&(con->p[tid][it]), sct_get_event_num());
// init arrays of min values
for (int i=0; i<sct_get_event_num(); i++) {
con->p[tid][it].emin[i] = SCT_MAX_EVAL;
con->p[tid][it].rmin[i] = SCT_MAX_TVAL;
// allocate event arrays
sct_internal_alloc_event_arrays(&(con->p[tid][it]), sct_get_event_num());
// init arrays of min values
for (int i=0; i<sct_get_event_num(); i++) {
con->p[tid][it].emin[i] = SCT_MAX_EVAL;
con->p[tid][it].rmin[i] = SCT_MAX_TVAL;
}
#endif
}
}
}
......@@ -1107,13 +1103,12 @@ int sct_init(const int tsize, const char* default_context_name,
// first call:
sct_mach_init();
// set timer_max:
// set current timer_size:
timer_size = tsize;
#ifdef _OPENMP
// enforce some thread-data separation:
if (timer_size<16) timer_size = 16;
#endif
timer_max = timer_size -1;
set_prg_start_time();
......@@ -1277,11 +1272,93 @@ int sct_new_timer(const char* name) {
#ifdef DEBUG
fprintf(stderr,"sct_new_timer: name=%s, it=%i\n",name,timer_num);
#endif
if (timer_num == timer_size) {
// we run out of pre-allocated resources and need to realloc our pools
sct_warn("inititial timer_size too small - need to realloc resources", __FILE__, __LINE__);
// enlarge meta data pool
if ( !(meta_pool = realloc(meta_pool, 2*timer_size*sizeof(sct_meta_type))) )
sct_abort("memory reallocation failed", __FILE__, __LINE__);
// enlarge mark pool
#ifdef _OPENMP
#pragma omp parallel
#endif
{
int tid = omp_get_thread_num();
static_pr_thread_id = tid;
if ( !(mark_pool = realloc(mark_pool, 2*timer_size*sizeof(sct_mark_type))) )
sct_abort("memory reallocation failed", __FILE__, __LINE__);
#ifdef HAVE_LIBPAPI
for (int i=timer_size; i<2*timer_size; i++) {
if ( !(mark_pool[i].em = calloc(sct_get_event_num(), sizeof(eval_type))) )
sct_abort("memory allocation failed", __FILE__, __LINE__);
}
#endif
}
// enlarge contexts
for(int icon = 0; icon < context_num; icon++) {
sct_context_type *con = &context_pool[icon];
// serial measurement data:
if ( !(con->s = realloc(con->s, 2*timer_size*sizeof(sct_stats_type))) )
sct_abort("memory reallocation failed", __FILE__, __LINE__);
for (int i=timer_size; i<2*timer_size; i++) {
con->s[i].tmin = SCT_MAX_TVAL;
con->s[i].active_under = -2;
#ifdef HAVE_LIBPAPI
// allocate event arrays
sct_internal_alloc_event_arrays(&(con->s[i]), sct_get_event_num());
// init arrays of min values
for (int j=0; j<sct_get_event_num(); j++) {
con->s[i].emin[j] = SCT_MAX_EVAL;
con->s[i].rmin[j] = SCT_MAX_TVAL;
}
#endif
}
#ifdef _OPENMP
// threadprivate space, minor dimension:
#pragma omp parallel
{
int tid;
if ( (tid = sct_get_pr_thread_id()) >= sct_get_pr_thread_count())
sct_abort("internal error", __FILE__, __LINE__);
#pragma omp critical
{
if ( !(con->p[tid] = realloc(con->p[tid], 2*timer_size*sizeof(sct_stats_type))) )
sct_abort("memory reallocation failed", __FILE__, __LINE__);
for (int i=timer_size; i<2*timer_size; i++) {
con->p[tid][i].tmin = SCT_MAX_TVAL;
con->p[tid][i].active_under = -2;
#ifdef HAVE_LIBPAPI
// allocate event arrays
sct_internal_alloc_event_arrays(&(con->p[tid][i]), sct_get_event_num());
// init arrays of min values
for (int j=0; j<sct_get_event_num(); j++) {
con->p[tid][i].emin[j] = SCT_MAX_EVAL;
con->p[tid][i].rmin[j] = SCT_MAX_TVAL;
}
#endif
}
}
}
#endif
}
// set new timer_size
timer_size *= 2;
}
// new timer
it = timer_num;
timer_num++;
if (it>=timer_size) sct_abort("timer_size too small", __FILE__, __LINE__);
// meta
meta_pool[it].name = sct_string_new(name);
meta_pool[it].used = 1;
......@@ -1769,7 +1846,7 @@ found_common_ancestor:
sct_warn("number of simultaneously active timers caused realloc of stack", __FILE__, __LINE__);
if ( !(s->stack = realloc(s->stack, 2 * s->n * sizeof(int))) )
sct_abort("memory allocation failed", __FILE__, __LINE__);
sct_abort("memory reallocation failed", __FILE__, __LINE__);
s->n *= 2;
#ifdef _OPENMP
......
......@@ -43,8 +43,8 @@ static double simple_walltime() {
static void init0() {
gettimeofday(&timeval0, NULL);
sct_init(timer_max, "test_serial", 0);
//sct_set_callstats(0);
// enforce a smaller number of timer_max to check realloc of resources
sct_init(timer_max/2, "test_serial", 0);
for (int i = 0; i < timer_max; i++) {
timer[i] = 0;
......
Supports Markdown
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