int main (int argc, char *argv[]) { Config mcxconfig; unsigned int activedev=0; float *fluence=NULL,totalenergy=0.f; mcx_initcfg(&mcxconfig); // parse command line options to initialize the configurations mcx_parsecmd(argc,argv,&mcxconfig); // identify gpu number and set one gpu active if(!mcx_set_gpu(&mcxconfig,&activedev)){ mcx_error(-1,"No compute platform was found\n",__FILE__,__LINE__); } if(activedev==0) return 0; mcx_createfluence(&fluence,&mcxconfig); // this launches the MC simulation mcx_run_simulation(&mcxconfig,fluence,&totalenergy); // clean up the allocated memory in the config mcx_clearfluence(&fluence); mcx_clearcfg(&mcxconfig); return 0; }
int main (int argc, char *argv[]) { Config mcxconfig; mcx_initcfg(&mcxconfig); // parse command line options to initialize the configurations mcx_parsecmd(argc,argv,&mcxconfig); // identify gpu number and set one gpu active if(!mcx_set_gpu(&mcxconfig)){ mcx_error(-1,"No GPU device found\n",__FILE__,__LINE__); } // this launches the MC simulation mcx_run_simulation(&mcxconfig); // clean up the allocated memory in the config mcx_clearcfg(&mcxconfig); return 0; }
// MTA NOTE: I HAVE NOT INCORPORATED THE MATLAB FUNCTION INTO AO-MCX void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]){ Config cfg; mxArray *tmp; int ifield, jstruct; int ncfg, nfields; int fielddim[4]; const char *outputtag[]={"data"}; if (nrhs==0){ mcxlab_usage(); return; } printf("Launching MCXLAB - Monte Carlo eXtreme for MATLAB & GNU Octave ...\n"); if (!mxIsStruct(prhs[0])) mexErrMsgTxt("Input must be a structure."); nfields = mxGetNumberOfFields(prhs[0]); ncfg = mxGetNumberOfElements(prhs[0]); if(nlhs>=1) plhs[0] = mxCreateStructMatrix(ncfg,1,1,outputtag); if(nlhs>=2) plhs[1] = mxCreateStructMatrix(ncfg,1,1,outputtag); if(nlhs>=3) plhs[2] = mxCreateStructMatrix(ncfg,1,1,outputtag); for (jstruct = 0; jstruct < ncfg; jstruct++) { /* how many configs */ printf("Running simulations for configuration #%d ...\n", jstruct+1); mcx_initcfg(&cfg); for (ifield = 0; ifield < nfields; ifield++) { /* how many input struct fields */ tmp = mxGetFieldByNumber(prhs[0], jstruct, ifield); if (tmp == NULL) { continue; } mcx_set_field(prhs[0],tmp,ifield,&cfg); } mexEvalString("pause(.001);"); if(cfg.vol==NULL || cfg.medianum==0){ mexErrMsgTxt("You must define 'vol' and 'prop' field."); } if(!mcx_set_gpu(&cfg)){ mexErrMsgTxt("No GPU device found"); } if(nlhs>=1){ fielddim[0]=cfg.dim.x; fielddim[1]=cfg.dim.y; fielddim[2]=cfg.dim.z; fielddim[3]=cfg.maxgate; mxSetFieldByNumber(plhs[0],jstruct,0, mxCreateNumericArray(4,fielddim,mxSINGLE_CLASS,mxREAL)); cfg.exportfield = (float*)mxGetPr(mxGetFieldByNumber(plhs[0],jstruct,0)); } if(nlhs>=2) cfg.exportdetected=(float*)malloc((cfg.medianum+1)*cfg.maxdetphoton*sizeof(float)); mcx_validate_config(&cfg); mcx_run_simulation(&cfg); if(nlhs>=2){ fielddim[0]=(cfg.medianum+1); fielddim[1]=cfg.his.savedphoton; fielddim[2]=0; fielddim[3]=0; if(cfg.his.savedphoton>0){ mxSetFieldByNumber(plhs[1],jstruct,0, mxCreateNumericArray(2,fielddim,mxSINGLE_CLASS,mxREAL)); memcpy((float*)mxGetPr(mxGetFieldByNumber(plhs[1],jstruct,0)),cfg.exportdetected, fielddim[0]*fielddim[1]*sizeof(float)); } free(cfg.exportdetected); } if(nlhs>=3){ fielddim[0]=cfg.dim.x; fielddim[1]=cfg.dim.y; fielddim[2]=cfg.dim.z; fielddim[3]=0; if(cfg.vol){ mxSetFieldByNumber(plhs[2],jstruct,0, mxCreateNumericArray(3,fielddim,mxUINT8_CLASS,mxREAL)); memcpy((unsigned char*)mxGetPr(mxGetFieldByNumber(plhs[2],jstruct,0)),cfg.vol, fielddim[0]*fielddim[1]*fielddim[2]*sizeof(unsigned char)); } } mcx_clearcfg(&cfg); } return; }