Skip to content

Commit

Permalink
[bug] fix multi-source replay bug, close #215
Browse files Browse the repository at this point in the history
  • Loading branch information
fangq committed Mar 13, 2024
1 parent 9250a0d commit abdee14
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions src/mcx_core.cu
Original file line number Diff line number Diff line change
Expand Up @@ -1049,17 +1049,6 @@ __device__ inline int launchnewphoton(MCXpos* p, MCXdir* v, Stokes* s, MCXtime*
MCXSrc* launchsrc = &(gcfg->src);
ppath[gcfg->w0offset - 1] = 0.f;

if (gcfg->extrasrclen && gcfg->srcid != 1) {
if (gcfg->srcid > 1) {
launchsrc = (MCXSrc*)(gproperty + gcfg->maxmedia + 1 + gcfg->detnum + ((gcfg->srcid - 2) * 4));
} else { // gcfg->srcid = 0 or -1: simulate all sources; = 0 merge all solutions; = -1 separately store each source
ppath[gcfg->w0offset - 1] = (int)(rand_uniform01(t) * JUST_BELOW_ONE * (gcfg->extrasrclen + 1)) + 1; // borrow initial weight section of photon-sharing for storing launch src id

if ((int)ppath[gcfg->w0offset - 1] > 1) {
launchsrc = (MCXSrc*)(gproperty + gcfg->maxmedia + 1 + gcfg->detnum + ((int)(ppath[gcfg->w0offset - 1] - 2) * 4));
}
}
}

/**
* Early termination of simulation when the detphoton buffer is filled if issavedet is set to 3
Expand Down Expand Up @@ -1153,8 +1142,6 @@ __device__ inline int launchnewphoton(MCXpos* p, MCXdir* v, Stokes* s, MCXtime*
return 1; // all photos complete
}

ppath += gcfg->partialdata;

/**
* If this is a replay of a detected photon, initilize the RNG with the stored seed here.
*/
Expand All @@ -1166,6 +1153,20 @@ __device__ inline int launchnewphoton(MCXpos* p, MCXdir* v, Stokes* s, MCXtime*
}
}

if (gcfg->extrasrclen && gcfg->srcid != 1) {
if (gcfg->srcid > 1) {
launchsrc = (MCXSrc*)(gproperty + gcfg->maxmedia + 1 + gcfg->detnum + ((gcfg->srcid - 2) * 4));
} else { // gcfg->srcid = 0 or -1: simulate all sources; = 0 merge all solutions; = -1 separately store each source
ppath[gcfg->w0offset - 1] = (int)(rand_uniform01(t) * JUST_BELOW_ONE * (gcfg->extrasrclen + 1)) + 1; // borrow initial weight section of photon-sharing for storing launch src id

if ((int)ppath[gcfg->w0offset - 1] > 1) {
launchsrc = (MCXSrc*)(gproperty + gcfg->maxmedia + 1 + gcfg->detnum + ((int)(ppath[gcfg->w0offset - 1] - 2) * 4));
}
}
}

ppath += gcfg->partialdata;

/**
* Attempt to launch a new photon until success
*/
Expand Down

0 comments on commit abdee14

Please sign in to comment.