commit 81b041b45a2fa0bdfe2da2cbceb9c4ffb1c0e76c
parent 37610f3fef066377ebfd7bd7faf2178e80009b32
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Wed, 15 Jul 2015 11:31:17 +0200
Change the profile of the smc_type create function
Provide the solving context as an argument of the smc_type create
function. This could be useful when the smc_type should be dynamically
allocated with respect to a size that would be known only at runtime.
Diffstat:
3 files changed, 11 insertions(+), 7 deletions(-)
diff --git a/src/smc.h b/src/smc.h
@@ -62,7 +62,7 @@ struct ssp_rng;
/* Generic type descriptor */
struct smc_type {
- void* (*create)(struct mem_allocator* allocator);
+ void* (*create)(struct mem_allocator* allocator, void* ctx);
void (*destroy)(struct mem_allocator* allocator, void* data);
void (*set)(void* result, const void* value);
diff --git a/src/smc_integrator.c b/src/smc_integrator.c
@@ -58,6 +58,7 @@ static res_T
estimator_create
(struct smc_device* dev,
const struct smc_type* type,
+ void* ctx,
struct smc_estimator** out_estimator)
{
struct smc_estimator* estimator = NULL;
@@ -74,7 +75,7 @@ estimator_create
ref_init(&estimator->ref);
#define TYPE_CREATE(Dst) { \
- (Dst) = type->create(dev->allocator); \
+ (Dst) = type->create(dev->allocator, ctx); \
if(!(Dst)) { \
res = RES_MEM_ERR; \
goto error; \
@@ -172,7 +173,7 @@ smc_solve
accums_sqr = (void**) (raw + 2 * sizeof(void*) * nthreads);
nsamples = (size_t*)(raw + 3 * sizeof(void*) * nthreads);
#define TYPE_CREATE(Dst) { \
- (Dst) = integrator->type->create(dev->allocator); \
+ (Dst) = integrator->type->create(dev->allocator, ctx); \
if(!(Dst)) { \
res = RES_MEM_ERR; \
goto error; \
@@ -188,7 +189,7 @@ smc_solve
#undef TYPE_CREATE
/* Create the estimator */
- res = estimator_create(dev, integrator->type, &estimator);
+ res = estimator_create(dev, integrator->type, ctx, &estimator);
if(res != RES_OK) goto error;
/* Parallel evaluation of the simulation */
@@ -256,7 +257,8 @@ smc_solve_N
/* Create the estimators */
FOR_EACH(i, 0, (int64_t)count) {
- res = estimator_create(dev, integrator->type, estimators + i);
+ res = estimator_create
+ (dev, integrator->type, (char*)ctx + (size_t)i*sizeof_ctx, estimators+i);
if(res != RES_OK) goto error;
}
@@ -264,7 +266,8 @@ smc_solve_N
nthreads = device_get_threads_count(dev);
vals = MEM_CALLOC(dev->allocator, nthreads, sizeof(void*));
FOR_EACH(i, 0, (int64_t)nthreads) {
- vals[i] = integrator->type->create(dev->allocator);
+ vals[i] = integrator->type->create
+ (dev->allocator, (char*)ctx + (size_t)i*sizeof_ctx);
if(!vals[i]) {
res = RES_MEM_ERR;
goto error;
diff --git a/src/smc_type_real.h b/src/smc_type_real.h
@@ -42,9 +42,10 @@
* Function definition
******************************************************************************/
static void*
-SMC_REAL_FUNC__(create)(struct mem_allocator* allocator)
+SMC_REAL_FUNC__(create)(struct mem_allocator* allocator, void* ctx)
{
ASSERT(allocator);
+ (void)ctx;
return MEM_ALLOC(allocator, sizeof(SMC_TYPE_REAL));
}