diff --git a/include/laik/backend.h b/include/laik/backend.h index b88fd27e..8fda8785 100644 --- a/include/laik/backend.h +++ b/include/laik/backend.h @@ -85,6 +85,8 @@ struct _Laik_Backend { // for elasticity: removal of processes which got started in a previous // resize is finished. They can be marked as dead and resources freed void (*finish_resize)(); + + Laik_Allocator* (*allocator)(); }; diff --git a/src/data.c b/src/data.c index fb077bdc..aa30c09b 100644 --- a/src/data.c +++ b/src/data.c @@ -156,6 +156,18 @@ void laik_switchstat_free(Laik_SwitchStat* ss, uint64_t bytes) static int data_id = 0; +// get backend specific allocator +static Laik_Allocator* allocator(Laik_Instance* inst, Laik_Data* d) +{ + (void)d; + Laik_Allocator* (*create)(); + create = inst->backend->allocator; + + assert(laik_allocator_def); + + return create ? create() : laik_allocator_def; +} + Laik_Data* laik_new_data(Laik_Space* space, Laik_Type* type) { Laik_Data* d = malloc(sizeof(Laik_Data)); @@ -177,7 +189,8 @@ Laik_Data* laik_new_data(Laik_Space* space, Laik_Type* type) d->activePartitioning = 0; d->activeMappings = 0; assert(laik_allocator_def); - d->allocator = laik_allocator_def; // malloc/free + reuse if possible + d->allocator = allocator(space->inst, d); // malloc/free + reuse if possible + assert(d->allocator); d->layout_factory = laik_new_layout_lex; // by default, use lex layouts d->stat = laik_newSwitchStat();