From 10dd72a5c8c8426b64df459e54e4a31ba26bdc82 Mon Sep 17 00:00:00 2001 From: Erik Schnetter Date: Thu, 8 Aug 2013 13:12:10 -0400 Subject: LoopControl: Introduce memory pool for lc_params and lc_setup This circumvents a memory allocation bug in the Intel compiler, which keeps the libc "free" space growing without bounds. --- Carpet/LoopControl/src/loopcontrol.cc | 38 +++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/Carpet/LoopControl/src/loopcontrol.cc b/Carpet/LoopControl/src/loopcontrol.cc index f13441499..a4e675af3 100644 --- a/Carpet/LoopControl/src/loopcontrol.cc +++ b/Carpet/LoopControl/src/loopcontrol.cc @@ -222,6 +222,38 @@ struct lc_descr_t { +// The Intel compiler keeps increasing the amount of "free" memory +// allocated by libc. Work around this by allocating memory in large +// batches. +namespace { + + template + class mempool { + const int nobjects = 1000000 / sizeof(T); + T* next; + int nleft; + public: + mempool(): nleft(0) + { + } + void* allocate() + { + if (nleft < 1) { + nleft = nobjects; + next = (T*)new char[nleft * sizeof(T)]; + } + assert(nleft >= 1); + return nleft--, next++; + } + }; + + mempool params_mempool; + mempool setup_mempool; + +} + + + extern "C" CCTK_FCALL void CCTK_FNAME(lc_get_fortran_type_sizes)(ptrdiff_t *type_sizes); @@ -643,7 +675,8 @@ void lc_control_init(lc_control_t *restrict const control, const bool isnew = res.second; assert(isnew == not setup_p); if (isnew) { - setup_p = new lc_setup_t(*descr, setup_key); + void *ptr = setup_mempool.allocate(); + setup_p = new (ptr) lc_setup_t(*descr, setup_key); } assert(not descr->current_setup); descr->current_setup = setup_p; @@ -736,7 +769,8 @@ void lc_control_init(lc_control_t *restrict const control, const bool isnew = res.second; assert(isnew == not params_p); if (isnew) { - params_p = new lc_params_t(setup, params_key); + void *ptr = params_mempool.allocate(); + params_p = new (ptr) lc_params_t(setup, params_key); } assert(not descr->current_params); descr->current_params = params_p; -- cgit v1.2.3