commit 6ce16a640d5ebcac9dc4316ea4e08dd7faee80ab
parent fbc4eaef6d801b77df11e5e0c2f1de9282e08d07
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Thu, 12 Jan 2023 14:42:40 +0100
Add the realisation index to the integrand function
Diffstat:
6 files changed, 40 insertions(+), 13 deletions(-)
diff --git a/src/smc.h b/src/smc.h
@@ -90,7 +90,11 @@ static const struct smc_estimator_status SMC_ESTIMATOR_STATUS_NULL =
struct smc_integrator {
res_T (*integrand)
- (void* value, struct ssp_rng* rng, const unsigned ithread, void* ctx);
+ (void* value,
+ struct ssp_rng* rng,
+ const unsigned ithread,
+ const uint64_t irealisation,
+ void* ctx);
const struct smc_type* type;
size_t max_realisations; /* Maximum # of realisations */
size_t max_failures; /* Cancel integration past # failed samples */
diff --git a/src/smc_estimator.c b/src/smc_estimator.c
@@ -211,7 +211,7 @@ smc_solve
if(ATOMIC_GET(&cancel)) continue;
res_local = integrator->integrand
- (vals[ithread], dev->rngs[ithread], (unsigned)ithread, ctx);
+ (vals[ithread], dev->rngs[ithread], (unsigned)ithread, (uint64_t)i, ctx);
if(res_local != RES_OK) {
#pragma omp critical
@@ -332,7 +332,7 @@ smc_solve_N
if(ATOMIC_GET(&cancel)) break;
res_local = integrator->integrand
- (vals[ithread], dev->rngs[ithread], (unsigned)ithread,
+ (vals[ithread], dev->rngs[ithread], (unsigned)ithread, (uint64_t)i,
(char*)ctx + (size_t)i*sizeof_ctx);
if(res_local != RES_OK) {
diff --git a/src/test_smc_doubleN.c b/src/test_smc_doubleN.c
@@ -45,13 +45,18 @@ enum {
struct alpha { double value; };
static res_T
-cos_x(void* value, struct ssp_rng* rng, const unsigned ithread, void* context)
+cos_x
+ (void* value,
+ struct ssp_rng* rng,
+ const unsigned ithread,
+ const uint64_t irealisation,
+ void* context)
{
double* result = SMC_DOUBLEN(value);
double samp;
struct smc_doubleN_context* ctx = context;
const struct alpha* alpha = ctx->integrand_data;
- (void)ithread;
+ (void)ithread, (void)irealisation;
CHK(value != NULL);
CHK(rng != NULL);
samp = ssp_rng_uniform_double(rng, -PI/4.0, PI/4.0);
diff --git a/src/test_smc_errors.c b/src/test_smc_errors.c
@@ -36,11 +36,15 @@
static res_T
compute_1
- (void* value, struct ssp_rng* rng, const unsigned ithread, void* context)
+ (void* value,
+ struct ssp_rng* rng,
+ const unsigned ithread,
+ const uint64_t irealisation,
+ void* context)
{
/* pretend that 10% of the realizations fail */
int ok = ssp_rng_canonical(rng) > 0.1;
- (void)context, (void)ithread;
+ (void)context, (void)ithread, (void)irealisation;
if(ok) {
SMC_DOUBLE(value) = 1; /* weight is 1 */
} else {
diff --git a/src/test_smc_light_path.c b/src/test_smc_light_path.c
@@ -246,7 +246,11 @@ skydome_lighting(const float wi[3])
static res_T
light_path_integrator
- (void* value, struct ssp_rng* rng, const unsigned ithread, void* data)
+ (void* value,
+ struct ssp_rng* rng,
+ const unsigned ithread,
+ const uint64_t irealisation,
+ void* data)
{
struct integrator_context* ctx = data;
float pix_lower[2], pix_upper[2]; /* Pixel AABB */
@@ -256,7 +260,7 @@ light_path_integrator
float throughput = 1.f;
int idepth;
- (void)ithread;
+ (void)ithread, (void)irealisation;
CHK(value != NULL);
CHK(rng != NULL);
diff --git a/src/test_smc_solve.c b/src/test_smc_solve.c
@@ -35,11 +35,16 @@
#include <math.h>
static res_T
-rcp_x(void* value, struct ssp_rng* rng, const unsigned ithread, void* ctx)
+rcp_x
+ (void* value,
+ struct ssp_rng* rng,
+ const unsigned ithread,
+ const uint64_t irealisation,
+ void* ctx)
{
double* result = value;
double samp;
- (void)ithread;
+ (void)ithread, (void)irealisation;
CHK(value != NULL);
CHK(rng != NULL);
CHK(ctx == NULL);
@@ -49,11 +54,16 @@ rcp_x(void* value, struct ssp_rng* rng, const unsigned ithread, void* ctx)
}
static res_T
-cos_x(void* value, struct ssp_rng* rng, const unsigned ithread, void* ctx)
+cos_x
+ (void* value,
+ struct ssp_rng* rng,
+ const unsigned ithread,
+ const uint64_t irealisation,
+ void* ctx)
{
float* result = value;
double samp;
- (void)ithread;
+ (void)ithread, (void)irealisation;
CHK(value != NULL);
CHK(rng != NULL);
CHK(ctx == (void*)0xC0DE);