Skip to content

Commit

Permalink
manually resolve merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
ShijieYan committed Oct 7, 2019
1 parent 9a2ad2a commit 261fe69
Show file tree
Hide file tree
Showing 9 changed files with 145 additions and 57 deletions.
38 changes: 28 additions & 10 deletions src/mcx_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
const char shortopt[]={'h','E','f','n','A','t','T','s','a','g','b','D','G',
'd','r','S','e','U','R','l','L','I','-','u','C','M',
'i','V','O','-','F','q','x','P','k','v','m','-','-',
'J','o','H','-','W','\0'};
'J','o','H','-','W','X','\0'};

/**
* Long command line options
Expand All @@ -96,11 +96,10 @@ const char *fullopt[]={"--help","--seed","--input","--photon","--autopilot",
"--momentum","--outputformat","--saveseed","--saveexit",
"--replaydet","--voidtime","--version","--mc","--atomic",
"--debugphoton","--compileropt","--optlevel","--maxdetphoton",
"--buffer","--workload",""};
"--buffer","--workload","--saveref",""};

extern char pathsep;


/**
* Debug flags
* R: debug random number generator
Expand Down Expand Up @@ -210,6 +209,7 @@ void mcx_initcfg(mcconfig *cfg){
cfg->unitinmm=1.f;
cfg->srctype=0;
cfg->isspecular=0;
cfg->issaveref=0;
cfg->outputtype=otFlux;
cfg->outputformat=ofASCII;
cfg->ismomentum=0;
Expand All @@ -234,6 +234,10 @@ void mcx_initcfg(mcconfig *cfg){
cfg->his.version=1;
cfg->his.unitinmm=1.f;
cfg->his.normalizer=1.f;
cfg->his.respin=1;
cfg->his.srcnum=cfg->srcnum;
cfg->his.savedetflag=0;

memcpy(cfg->his.magic,"MCXH",4);

memset(&(cfg->srcpos),0,sizeof(float3));
Expand Down Expand Up @@ -424,7 +428,7 @@ void mcx_savenii(OutputType *dat, size_t len, char* name, int type32bit, int out
* @param[in] cfg: simulation configuration
*/

void mcx_savedata(OutputType *dat, size_t len, mcconfig *cfg){
void mcx_savedata(OutputType *dat, size_t len, mcconfig *cfg,int isref){
FILE *fp;
char name[MAX_PATH_LENGTH];
char fname[MAX_PATH_LENGTH];
Expand All @@ -440,17 +444,17 @@ void mcx_savedata(OutputType *dat, size_t len, mcconfig *cfg){
else
sprintf(name,"%s",cfg->session);

if(cfg->outputformat==ofNifti || cfg->outputformat==ofAnalyze){
if(!isref && (cfg->outputformat==ofNifti || cfg->outputformat==ofAnalyze)){
mcx_savenii(dat, len, name, NIFTI_TYPE_FLOAT64, cfg->outputformat, cfg);
return;
}
sprintf(fname,"%s.%s",name,outputformat[(int)cfg->outputformat]);
sprintf(fname,"%s%s.%s",name,(isref ? "_dref" : ""),(isref ? "bin" : outputformat[(int)cfg->outputformat]));
fp=fopen(fname,"wb");

if(fp==NULL){
mcx_error(-2,"can not save data to disk",__FILE__,__LINE__);
}
if(cfg->outputformat==ofTX3){
if(!isref && cfg->outputformat==ofTX3){
fwrite(&glformat,sizeof(unsigned int),1,fp);
fwrite(&(cfg->dim.x),sizeof(int),3,fp);
}
Expand Down Expand Up @@ -712,7 +716,7 @@ int mcx_loadjson(cJSON *root, mcconfig *cfg){
if(!flagset['d']) cfg->issavedet=FIND_JSON_KEY("DoPartialPath","Session.DoPartialPath",Session,cfg->issavedet,valueint);
if(!flagset['V']) cfg->isspecular=FIND_JSON_KEY("DoSpecular","Session.DoSpecular",Session,cfg->isspecular,valueint);
if(!flagset['m']) cfg->ismomentum=FIND_JSON_KEY("DoDCS","Session.DoDCS",Session,cfg->ismomentum,valueint);
if(!flagset['X']) cfg->issaveexit=FIND_JSON_KEY("DoSaveExit","Session.DoSaveExit",Session,cfg->issaveexit,valueint);
if(!flagset['x']) cfg->issaveexit=FIND_JSON_KEY("DoSaveExit","Session.DoSaveExit",Session,cfg->issaveexit,valueint);
if(!flagset['q']) cfg->issaveseed=FIND_JSON_KEY("DoSaveSeed","Session.DoSaveSeed",Session,cfg->issaveseed,valueint);
if(!flagset['C']) cfg->basisorder=FIND_JSON_KEY("BasisOrder","Session.BasisOrder",Session,cfg->basisorder,valueint);
if(!cfg->outputformat) cfg->outputformat=mcx_keylookup((char *)FIND_JSON_KEY("OutputFormat","Session.OutputFormat",Session,"ascii",valuestring),outputformat);
Expand Down Expand Up @@ -1344,6 +1348,10 @@ void mcx_parsecmd(int argc, char* argv[], mcconfig *cfg){
i=mcx_readarg(argc,argv,i,&(cfg->issaveexit),"bool");
if (cfg->issaveexit) cfg->issavedet=1;
break;
case 'X':
i=mcx_readarg(argc,argv,i,&(cfg->issaveref),"char");
if (cfg->issaveref) cfg->issaveref=1;
break;
case 'C':
i=mcx_readarg(argc,argv,i,&(cfg->basisorder),"bool");
break;
Expand Down Expand Up @@ -1533,7 +1541,7 @@ void mcx_savedetphoton(float *ppath, void *seeds, int count, int doappend, mccon
*/

void mcx_version(mcconfig *cfg){
MMC_ERROR(MMC_INFO,"MMC $Rev:: $2019.3");
MMC_ERROR(MMC_INFO,"MMC $Rev:: $2019.4");
}

/**
Expand All @@ -1554,7 +1562,7 @@ void mcx_printheader(mcconfig *cfg){
# #\n\
# Research funded by NIH/NIGMS grant R01-GM114365 #\n\
###############################################################################\n\
$Rev:: $2019.3a$Date:: $ by $Author:: $\n\
$Rev:: $2019.4 $Date:: $ by $Author:: $\n\
###############################################################################\n"S_RESET);
}

Expand Down Expand Up @@ -1612,6 +1620,16 @@ where possible parameters include (the first item in [] is the default value)\n\
-S [1|0] (--save2pt) 1 to save the fluence field, 0 do not save\n\
-x [0|1] (--saveexit) 1 to save photon exit positions and directions\n\
setting -x to 1 also implies setting '-d' to 1\n\
-X [0|1] (--saveref) save diffuse reflectance/transmittance on the \n\
exterior surface. The output is stored in a \n\
file named *_dref.dat, and the 2nd column of \n\
the data is resized to [#Nf, #time_gate] where\n\
#Nf is the number of triangles on the surface; \n\
#time_gate is the number of total time gates. \n\
To plot the surface diffuse reflectance, the \n\
output triangle surface mesh can be extracted\n\
by faces=faceneighbors(cfg.elem,'rowmajor');\n\
where 'faceneighbors' is part of Iso2Mesh.\n\
-q [0|1] (--saveseed) 1 save RNG seeds of detected photons for replay\n\
-F format (--outputformat)'ascii', 'bin' (in 'double'), 'mc2' (double) \n\
'hdr' (Analyze) or 'nii' (nifti, double)\n\
Expand Down
5 changes: 3 additions & 2 deletions src/mcx_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ enum TOutputFormat {ofASCII, ofBin, ofNifti, ofAnalyze, ofMC2, ofTX3, ofUBJSON};
enum TOutputDomain {odMesh, odGrid};
enum TDeviceVendor {dvUnknown, dvNVIDIA, dvAMD, dvIntel, dvIntelGPU};
enum TMCXParent {mpStandalone, mpMATLAB};

enum TBoundary {bcNoReflect, bcReflect, bcAbsorbExterior, bcMirror /*, bcCylic*/};

/***************************************************************************//**
\struct MMC_medium mcx_utils.h
Expand Down Expand Up @@ -215,6 +215,7 @@ typedef struct MMC_config{
char isgpuinfo; /**<1 to print gpu info when attach, 0 do not print*/
char isspecular; /**<1 calculate the initial specular ref if outside the mesh, 0 do not calculate*/
char issaveseed; /**<1 save the seed for a detected photon, 0 do not save*/
char issaveref; /**<1 to save diffuse reflectance on surface, 0 no save*/
char isatomic; /**<1 use atomic operations for weight accumulation, 0 do not use*/
char method; /**<0-Plucker 1-Havel, 2-Badouel, 3-branchless Badouel*/
char basisorder; /**<0 to use piece-wise-constant basis for fluence, 1, linear*/
Expand Down Expand Up @@ -258,7 +259,7 @@ typedef struct MMC_config{
#ifdef __cplusplus
extern "C" {
#endif
void mcx_savedata(OutputType *dat,size_t len,mcconfig *cfg);
void mcx_savedata(OutputType *dat,size_t len,mcconfig *cfg,int isref);
void mcx_savenii(OutputType *dat, size_t len, char* name, int type32bit, int outputformatid, mcconfig *cfg);
void mcx_error(const int id,const char *msg,const char *file,const int linenum);
void mcx_loadconfig(FILE *in, mcconfig *cfg);
Expand Down
11 changes: 7 additions & 4 deletions src/mmc_cl_host.c
Original file line number Diff line number Diff line change
Expand Up @@ -241,9 +241,9 @@ void mmc_run_cl(mcconfig *cfg,tetmesh *mesh, raytracer *tracer){
tic=StartTimer();
if(cfg->issavedet){
MMC_FPRINTF(cfg->flog,"- variant name: [%s] compiled with OpenCL version [%d]\n",
"Detective MCXCL",CL_VERSION_1_0);
"MMC-OpenCL",CL_VERSION_1_0);
}else{
MMC_FPRINTF(cfg->flog,"- code name: [Vanilla MCXCL] compiled with OpenCL version [%d]\n",
MMC_FPRINTF(cfg->flog,"- code name: [MMC-OpenCL] compiled with OpenCL version [%d]\n",
CL_VERSION_1_0);
}
MMC_FPRINTF(cfg->flog,"- compiled with: [RNG] %s [Seed Length] %d\n",MCX_RNG_NAME,RAND_SEED_WORD_LEN);
Expand Down Expand Up @@ -497,7 +497,7 @@ is more than what your have specified (%d), please use the -H option to specify
}
if(cfg->issave2pt && cfg->parentid==mpStandalone){
MMC_FPRINTF(cfg->flog,"saving data to file ...\t");
mesh_saveweight(mesh,cfg);
mesh_saveweight(mesh,cfg,0);
MMC_FPRINTF(cfg->flog,"saving data complete : %d ms\n\n",GetTimeMillis()-tic);
fflush(cfg->flog);
}
Expand All @@ -507,7 +507,10 @@ is more than what your have specified (%d), please use the -H option to specify
cfg->his.detected=cfg->detectedcount;
mesh_savedetphoton(cfg->exportdetected,NULL,cfg->detectedcount,(sizeof(RandType)*RAND_BUF_LEN),cfg);
}

if(cfg->issaveref){
MMC_FPRINTF(cfg->flog,"saving surface diffuse reflectance ...");
mesh_saveweight(mesh,cfg,1);
}
// total energy here equals total simulated photons+unfinished photons for all threads
MMC_FPRINTF(cfg->flog,"simulated %ld photons (%ld) with %d devices (ray-tet %.0f)\nMCX simulation speed: %.2f photon/ms\n",
cfg->nphoton,cfg->nphoton,workdev, reporter.raytet,(double)cfg->nphoton/toc);
Expand Down
17 changes: 10 additions & 7 deletions src/mmc_core.cl
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@
#define sincos(a,b) sincosf(a,b)

#else
#define FL4(f) ((float4)(f))
#define FL3(f) ((float3)(f))
#define FL4(f) (f)
#define FL3(f) (f)
#endif

#ifdef MCX_SAVE_DETECTORS
Expand Down Expand Up @@ -458,13 +458,16 @@ float branchless_badouel_raytet(ray *r, __constant MCXParam *gcfg,__constant int
uint i;
} currweight;

if(r->eid<=0)
return -1;

eid=(r->eid-1)<<2;

r->pout.x=MMC_UNDEFINED;
r->faceid=-1;
r->isend=0;

S = (FL4(r->vec.x)*normal[eid]+FL4(r->vec.y)*normal[eid+1]+FL4(r->vec.z)*normal[eid+2]);
S = FL4(r->vec.x)*normal[eid]+FL4(r->vec.y)*normal[eid+1]+FL4(r->vec.z)*normal[eid+2];
T = normal[eid+3] - (FL4(r->p0.x)*normal[eid]+FL4(r->p0.y)*normal[eid+1]+FL4(r->p0.z)*normal[eid+2]);
T = -convert_float4_rte(isgreater(T,FL4(0.f))*2)*FL4(0.5f)*T;
T = T/S;
Expand Down Expand Up @@ -928,7 +931,7 @@ void onephoton(unsigned int id,__local float *ppath, __constant MCXParam *gcfg,_
fixphoton(&r.p0,node,(__constant int *)(elem+(r.eid-1)*gcfg->elemlen));
continue;
}
r.eid=-r.eid;
r.eid=ID_UNDEFINED;
r.faceid=-1;
}
#ifdef MCX_SAVE_DETECTORS
Expand All @@ -947,7 +950,7 @@ void onephoton(unsigned int id,__local float *ppath, __constant MCXParam *gcfg,_
reflectray(gcfg,&r.vec,&oldeid,&r.eid,r.faceid,ran,type,normal,med);
}
#endif
if(r.eid==0) break;
if(r.eid<=0) break;
/*when a photon enters the domain from the background*/
if(type[oldeid-1]==0 && type[r.eid-1]){
//if(gcfg->debuglevel&dlExit)
Expand Down Expand Up @@ -989,14 +992,14 @@ void onephoton(unsigned int id,__local float *ppath, __constant MCXParam *gcfg,_
}
if(r.pout.x==MMC_UNDEFINED){
/*possibily hit an edge or miss*/
r.eid=-r.eid;
r.eid=ID_UNDEFINED;
break;
}
}
if(r.eid<=0 || r.pout.x==MMC_UNDEFINED) {
//if(r.eid==0 && (gcfg->debuglevel&dlMove))
MMC_FPRINTF(("B %f %f %f %d %u %e\n",r.p0.x,r.p0.y,r.p0.z,r.eid,id,r.slen));
if(r.eid==0){
if(r.eid!=ID_UNDEFINED){
//if(gcfg->debuglevel&dlExit)
MMC_FPRINTF(("E %f %f %f %f %f %f %f %d\n",r.p0.x,r.p0.y,r.p0.z,
r.vec.x,r.vec.y,r.vec.z,r.weight,r.eid));
Expand Down
8 changes: 7 additions & 1 deletion src/mmc_host.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ int mmc_run_mp(mcconfig *cfg, tetmesh *mesh, raytracer *tracer){

t0=StartTimer();

mcx_printheader(cfg);

#if defined(MMC_LOGISTIC) || defined(MMC_SFMT)
cfg->issaveseed=0;
#endif
Expand Down Expand Up @@ -295,7 +297,7 @@ int mmc_run_mp(mcconfig *cfg, tetmesh *mesh, raytracer *tracer){
case otFluence:MMCDEBUG(cfg,dlTime,(cfg->flog,"saving fluence ...")); break;
case otEnergy: MMCDEBUG(cfg,dlTime,(cfg->flog,"saving energy deposit ...")); break;
}
mesh_saveweight(mesh,cfg);
mesh_saveweight(mesh,cfg,0);
}
if(cfg->issavedet){
MMCDEBUG(cfg,dlTime,(cfg->flog,"saving detected photons ..."));
Expand All @@ -310,6 +312,10 @@ int mmc_run_mp(mcconfig *cfg, tetmesh *mesh, raytracer *tracer){
if(cfg->issaveseed && master.photonseed)
free(master.photonseed);
}
if(cfg->issaveref){
MMCDEBUG(cfg,dlTime,(cfg->flog,"saving surface diffuse reflectance ..."));
mesh_saveweight(mesh,cfg,1);
}
MMCDEBUG(cfg,dlTime,(cfg->flog,"\tdone\t%d\n",GetTimeMillis()-t0));
visitor_clear(&master);

Expand Down
9 changes: 8 additions & 1 deletion src/mmclab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]){
* The function can return 1-3 outputs (i.e. the LHS)
*/
if(nlhs>=1)
plhs[0] = mxCreateStructMatrix(ncfg,1,1,outputtag);
plhs[0] = mxCreateStructMatrix(ncfg,1,2,datastruct);
if(nlhs>=2)
plhs[1] = mxCreateStructMatrix(ncfg,1,1,outputtag);
if(nlhs>=3)
Expand Down Expand Up @@ -314,6 +314,12 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]){
}
double *output = (double*)mxGetPr(mxGetFieldByNumber(plhs[0],jstruct,0));
memcpy(output,mesh.weight,cfg.srcnum*datalen*cfg.maxgate*sizeof(double));

if(cfg.issaveref){ /** save diffuse reflectance */
fielddim[1]=mesh.nf;
mxSetFieldByNumber(plhs[0],jstruct,1, mxCreateNumericArray(2,&fielddim[1],mxDOUBLE_CLASS,mxREAL));
memcpy((double*)mxGetPr(mxGetFieldByNumber(plhs[0],jstruct,1)),mesh.dref,fielddim[1]*fielddim[2]*sizeof(double));
}
}
if(errorflag)
mexErrMsgTxt("MMCLAB Terminated due to exception!");
Expand Down Expand Up @@ -375,6 +381,7 @@ void mmc_set_field(const mxArray *root,const mxArray *item,int idx, mcconfig *cf
GET_ONE_FIELD(cfg,nout)
GET_ONE_FIELD(cfg,isref3)
GET_ONE_FIELD(cfg,isnormalized)
GET_ONE_FIELD(cfg,issaveref)
GET_ONE_FIELD(cfg,debugphoton)
GET_ONE_FIELD(cfg,minenergy)
GET_ONE_FIELD(cfg,replaydet)
Expand Down
Loading

0 comments on commit 261fe69

Please sign in to comment.