Skip to content

Commit

Permalink
[bug] support photon-sharing in DMMC on CPU, fix #97
Browse files Browse the repository at this point in the history
  • Loading branch information
fangq committed Sep 21, 2024
1 parent 73926c8 commit 2a7e9dd
Showing 1 changed file with 18 additions and 15 deletions.
33 changes: 18 additions & 15 deletions src/mmc_raytrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -1405,6 +1405,8 @@ float branchless_badouel_raytet(ray* r, raytracer* tracer, mcconfig* cfg, visito
medium* prop;
int* enb, *ee = (int*)(tracer->mesh->elem + eid * tracer->mesh->elemlen);
float mus;
int psize = (int)cfg->srcparam1.w * (int)cfg->srcparam2.w; // total number of pixels in each pattern
int pidx; // pattern index

if (cfg->implicit == 1 && r->inroi && tracer->mesh->edgeroi && fabs(tracer->mesh->edgeroi[eid * 6]) < EPS) {
r->inroi = 0;
Expand Down Expand Up @@ -1522,9 +1524,6 @@ float branchless_badouel_raytet(ray* r, raytracer* tracer, mcconfig* cfg, visito
#pragma omp atomic
tracer->mesh->weight[r->oldidx] += r->oldweight;
} else if (cfg->srctype == stPattern) {
int psize = (int)cfg->srcparam1.w * (int)cfg->srcparam2.w; // total number of pixels in each pattern
int pidx; // pattern index

for (pidx = 0; pidx < cfg->srcnum; pidx++) {
#pragma omp atomic
tracer->mesh->weight[r->oldidx * cfg->srcnum + pidx] += r->oldweight * cfg->srcpattern[pidx * psize + r->posidx];
Expand All @@ -1542,9 +1541,6 @@ float branchless_badouel_raytet(ray* r, raytracer* tracer, mcconfig* cfg, visito
#pragma omp atomic
tracer->mesh->weight[newidx] += r->oldweight;
} else if (cfg->srctype == stPattern) {
int psize = (int)cfg->srcparam1.w * (int)cfg->srcparam2.w; // total number of pixels in each pattern
int pidx; // pattern index

for (pidx = 0; pidx < cfg->srcnum; pidx++) {
#pragma omp atomic
tracer->mesh->weight[newidx * cfg->srcnum + pidx] += r->oldweight * cfg->srcpattern[pidx * psize + r->posidx];
Expand Down Expand Up @@ -1574,11 +1570,16 @@ float branchless_badouel_raytet(ray* r, raytracer* tracer, mcconfig* cfg, visito
r->oldidx = (r->oldidx == 0xFFFFFFFF) ? newidx : r->oldidx;

if (newidx != r->oldidx) {
if (cfg->isatomic)
if (cfg->srctype != stPattern || cfg->srcnum == 1) {
#pragma omp atomic
tracer->mesh->weight[r->oldidx] += r->oldweight;
else {
tracer->mesh->weight[r->oldidx] += r->oldweight;
} else if (cfg->srctype == stPattern) {
for (pidx = 0; pidx < cfg->srcnum; pidx++) {
for (pidx = 0; pidx < cfg->srcnum; pidx++) {
#pragma omp atomic
tracer->mesh->weight[r->oldidx * cfg->srcnum + pidx] += r->oldweight * cfg->srcpattern[pidx * psize + r->posidx];
}
}
}

r->oldidx = newidx;
Expand All @@ -1588,11 +1589,16 @@ float branchless_badouel_raytet(ray* r, raytracer* tracer, mcconfig* cfg, visito
}

if (r->faceid == -2 || !r->isend) {
if (cfg->isatomic)
if (cfg->srctype != stPattern || cfg->srcnum == 1) {
#pragma omp atomic
tracer->mesh->weight[newidx] += r->oldweight;
else {
tracer->mesh->weight[newidx] += r->oldweight;
} else if (cfg->srctype == stPattern) {
for (pidx = 0; pidx < cfg->srcnum; pidx++) {
for (pidx = 0; pidx < cfg->srcnum; pidx++) {
#pragma omp atomic
tracer->mesh->weight[newidx * cfg->srcnum + pidx] += r->oldweight * cfg->srcpattern[pidx * psize + r->posidx];
}
}
}

r->oldweight = 0.f;
Expand All @@ -1612,9 +1618,6 @@ float branchless_badouel_raytet(ray* r, raytracer* tracer, mcconfig* cfg, visito
tracer->mesh->weight[ee[out[faceidx][i]] - 1 + tshift] += ww;
}
} else if (cfg->srctype == stPattern) {
int psize = (int)cfg->srcparam1.w * (int)cfg->srcparam2.w; // total number of pixels in each pattern
int pidx; // pattern index

for (pidx = 0; pidx < cfg->srcnum; pidx++) {
for (i = 0; i < 3; i++) {
#pragma omp atomic
Expand Down

0 comments on commit 2a7e9dd

Please sign in to comment.