Skip to content

Commit

Permalink
[feat] disabling issaveref if issave2pt is false
Browse files Browse the repository at this point in the history
  • Loading branch information
fangq committed Nov 6, 2024
1 parent 6dbcc0f commit eaafb0b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/mcx_core.cu
Original file line number Diff line number Diff line change
Expand Up @@ -2821,7 +2821,7 @@ void mcx_run_simulation(Config* cfg, GPUInfo* gpu) {
/** Updating host simulation configuration \c cfg, only allow the master thread to modify cfg, others are read-only */
#pragma omp master
{
if (cfg->exportfield == NULL) {
if (cfg->exportfield == NULL && cfg->issave2pt) {
if (cfg->seed == SEED_FROM_FILE && cfg->replaydet == -1) {
cfg->exportfield = (float*)calloc(sizeof(float) * dimxyz, gpu[gpuid].maxgate * (1 + (cfg->outputtype == otRF)) * cfg->detnum);
} else {
Expand Down
4 changes: 4 additions & 0 deletions src/mcx_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -3698,6 +3698,10 @@ void mcx_validatecfg(Config* cfg, float* detps, int dimdetps[2], int seedbyte) {
+ SAVE_W0(cfg->savedetflag);
hostdetreclen += cfg->polmedianum ? (4 * SAVE_IQUV(cfg->savedetflag)) : 0; // for polarized photon simulation

if (!cfg->issave2pt && cfg->issaveref) {
cfg->issaveref = 0;
}

if (!cfg->issrcfrom0) {
cfg->srcpos.x--;
cfg->srcpos.y--;
Expand Down
12 changes: 8 additions & 4 deletions src/mcxlab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ void mexFunction(int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs[]) {
}

/** Initialize all buffers necessary to store the output variables */
if (nlhs >= 1) {
if (nlhs >= 1 && cfg.issave2pt) {
int fieldlen = cfg.dim.x * cfg.dim.y * cfg.dim.z * (int)((cfg.tend - cfg.tstart) / cfg.tstep + 0.5) * cfg.srcnum;

if (cfg.replay.seed != NULL && cfg.replaydet == -1) {
Expand Down Expand Up @@ -412,10 +412,11 @@ void mexFunction(int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs[]) {

fieldlen = fielddim[0] * fielddim[1] * fielddim[2] * fielddim[3] * fielddim[4] * fielddim[5];

if (cfg.issaveref) {
if (cfg.issaveref && cfg.exportfield) {
int highdim = fielddim[3] * fielddim[4] * fielddim[5];
int voxellen = cfg.dim.x * cfg.dim.y * cfg.dim.z;
float* dref = (float*)malloc(fieldlen * sizeof(float));

memcpy(dref, cfg.exportfield, fieldlen * sizeof(float));

for (int voxelid = 0; voxelid < voxellen; voxelid++) {
Expand All @@ -438,13 +439,16 @@ void mexFunction(int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs[]) {
free(dref);
}

if (cfg.issave2pt) {
if (cfg.issave2pt && cfg.exportfield) {
mxSetFieldByNumber(plhs[0], jstruct, 0, mxCreateNumericArray(((fielddim[5] > 1) ? 6 : (4 + (fielddim[4] > 1))), fielddim, mxSINGLE_CLASS, mxREAL));
memcpy((float*)mxGetPr(mxGetFieldByNumber(plhs[0], jstruct, 0)), cfg.exportfield,
fieldlen * sizeof(float));
}

free(cfg.exportfield);
if (cfg.exportfield) {
free(cfg.exportfield);
}

cfg.exportfield = NULL;

/** also return the run-time info in outut.runtime */
Expand Down

0 comments on commit eaafb0b

Please sign in to comment.