Skip to content

Commit

Permalink
remove all matlab mex compilation warnings on windows, add installati…
Browse files Browse the repository at this point in the history
…on instruction
  • Loading branch information
fangq committed Apr 3, 2020
1 parent c8884a4 commit 50fbcc7
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 20 deletions.
23 changes: 19 additions & 4 deletions src/buildmmc.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,27 @@ function buildmmc(varargin)
% 'filelist': a user-defined list of source file names
%
% Dependency (Windows only):
% 1.To compile mmclab in MATLAB R2017a or earlier on Windows, you must
% 1.If you have MATLAB R2017b or later, you may skip this step.
% To compile mmclab in MATLAB R2017a or earlier on Windows, you must
% pre-install the MATLAB support for MinGW-w64 compiler
% https://www.mathworks.com/matlabcentral/fileexchange/52848-matlab-support-for-mingw-w64-c-c-compiler
% 2.After installation of MATLAB MinGW support, you must type "mex -setup"
% in MATLAB and select "MinGW64 Compiler (C)".
% 3.Once you select the MingW C compiler, you should run "mex -setup"
%
% Note: it appears that installing the above Add On is no longer working
% and may give an error at the download stage. In this case, you should
% install MSYS2 from https://www.msys2.org/. Once you install MSYS2,
% run MSYS2.0 MinGW 64bit from Start menu, in the popup terminal window,
% type
%
% pacman -Syu
% pacman -S base-devel gcc git mingw-w64-x86_64-opencl-headers
%
% Then, start MATLAB, and in the command window, run
%
% setenv('MW_MINGW64_LOC','C:\msys64\usr');
%
% 2.After installation of MATLAB MinGW support, you must type
% "mex -setup C" in MATLAB and select "MinGW64 Compiler (C)".
% 3.Once you select the MingW C compiler, you should run "mex -setup C++"
% again in MATLAB and select "MinGW64 Compiler (C++)" to compile C++.
% 4.File C:\Windows\System32\OpenCL.dll must exist. You can obtain this
% file by installing your graphics driver or install CUDA/AMD GPU SDK
Expand Down
8 changes: 4 additions & 4 deletions src/mcx_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
** \section sref Reference:
** \li \c (\b Fang2010) Qianqian Fang, <a href="http://www.opticsinfobase.org/abstract.cfm?uri=boe-1-1-165">
** "Mesh-based Monte Carlo Method Using Fast Ray-Tracing
** in Pl¨¹cker Coordinates,"</a> Biomed. Opt. Express, 1(1) 165-175 (2010).
** in Pl¡§1cker Coordinates,"</a> Biomed. Opt. Express, 1(1) 165-175 (2010).
** \li \c (\b Fang2012) Qianqian Fang and David R. Kaeli,
** <a href="https://www.osapublishing.org/boe/abstract.cfm?uri=boe-3-12-3223">
** "Accelerating mesh-based Monte Carlo method on modern CPU architectures,"</a>
Expand Down Expand Up @@ -807,12 +807,12 @@ void mcx_loadconfig(FILE *in, mcconfig *cfg){

if(in==stdin)
MMC_FPRINTF(stdout,"Please specify the total number of photons: [1000000]\n\t");
MMC_ASSERT(fscanf(in,"%lu", &(nphoton) )==1);
MMC_ASSERT(fscanf(in,"%I64u", &(nphoton) )==1);
if(cfg->nphoton==0) cfg->nphoton=nphoton;
comm=fgets(comment,MAX_PATH_LENGTH,in);

if(in==stdin)
MMC_FPRINTF(stdout,">> %lu\nPlease specify the random number generator seed: [123456789]\n\t",cfg->nphoton);
MMC_FPRINTF(stdout,">> %I64u\nPlease specify the random number generator seed: [123456789]\n\t",cfg->nphoton);
if(cfg->seed==0x623F9A9E)
MMC_ASSERT(fscanf(in,"%d", &(cfg->seed) )==1);
else
Expand Down Expand Up @@ -972,7 +972,7 @@ void mcx_loadconfig(FILE *in, mcconfig *cfg){
void mcx_saveconfig(FILE *out, mcconfig *cfg){
int i;

MMC_FPRINTF(out,"%lu\n", (cfg->nphoton) );
MMC_FPRINTF(out,"%I64u\n", (cfg->nphoton) );
MMC_FPRINTF(out,"%d\n", (cfg->seed) );
MMC_FPRINTF(out,"%f %f %f\n", (cfg->srcpos.x),(cfg->srcpos.y),(cfg->srcpos.z) );
MMC_FPRINTF(out,"%f %f %f\n", (cfg->srcdir.x),(cfg->srcdir.y),(cfg->srcdir.z) );
Expand Down
2 changes: 1 addition & 1 deletion src/mmc_cl_host.c
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ is more than what your have specified (%d), please use the -H option to specify
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",
MMC_FPRINTF(cfg->flog,"simulated %I64u photons (%I64u) with %d devices (ray-tet %.0f)\nMCX simulation speed: %.2f photon/ms\n",
cfg->nphoton,cfg->nphoton,workdev, reporter.raytet,(double)cfg->nphoton/toc);
MMC_FPRINTF(cfg->flog,"total simulated energy: %.2f\tabsorbed: %5.5f%%\n(loss due to initial specular reflection is excluded in the total)\n",
cfg->energytot,(cfg->energytot-cfg->energyesc)/cfg->energytot*100.f);
Expand Down
4 changes: 2 additions & 2 deletions src/mmc_cl_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,8 @@ cl_platform_id mcx_list_gpu(mcconfig *cfg,unsigned int *activedev,cl_device_id *
printf(" Stream Processor:\t%d\n",cuinfo.core);
}
printf(" Vendor name :\t%s\n",VendorList[cuinfo.vendor]);
printf(" Auto-thread :\t%ld\n",cuinfo.autothread);
printf(" Auto-block :\t%ld\n",cuinfo.autoblock);
printf(" Auto-thread :\t%d\n",(uint)cuinfo.autothread);
printf(" Auto-block :\t%d\n",(uint)cuinfo.autoblock);
}
if(activedevlist!=NULL){
if(cfg->deviceid[cuid++]=='1'){
Expand Down
12 changes: 8 additions & 4 deletions src/mmclab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
** \section sref Reference:
** \li \c (\b Fang2010) Qianqian Fang, <a href="http://www.opticsinfobase.org/abstract.cfm?uri=boe-1-1-165">
** "Mesh-based Monte Carlo Method Using Fast Ray-Tracing
** in Pl¨¹cker Coordinates,"</a> Biomed. Opt. Express, 1(1) 165-175 (2010).
** in Pl¡§1cker Coordinates,"</a> Biomed. Opt. Express, 1(1) 165-175 (2010).
** \li \c (\b Fang2012) Qianqian Fang and David R. Kaeli,
** <a href="https://www.osapublishing.org/boe/abstract.cfm?uri=boe-3-12-3223">
** "Accelerating mesh-based Monte Carlo method on modern CPU architectures,"</a>
Expand Down Expand Up @@ -91,7 +91,9 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]){
int ifield, jstruct;
int ncfg, nfields;
dimtype fielddim[5];
#ifdef MATLAB_MEX_FILE
int usewaitbar=1;
#endif
int errorflag=0;
cl_uint workdev;

Expand Down Expand Up @@ -181,10 +183,12 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]){
if(nlhs>=3)
plhs[2] = mxCreateStructMatrix(ncfg,1,1,outputtag);

#ifdef MATLAB_MEX_FILE
if(mexEvalString("mmclab_waitbar_handle=figure('visible','off');")) // waitbar is not supported with nojvm after matlab R2013a
usewaitbar=0;
else
mexEvalString("close(mmclab_waitbar_handle);");
#endif

/**
* Loop over each element of the struct if it is an array, each element is a simulation
Expand Down Expand Up @@ -538,7 +542,7 @@ void mmc_set_field(const mxArray *root,const mxArray *item,int idx, mcconfig *cf
cfg->srcpattern=(float*)malloc(arraydim[0]*arraydim[1]*cfg->srcnum*sizeof(float));
for(k=0;k<arraydim[0]*arraydim[1]*cfg->srcnum;k++)
cfg->srcpattern[k]=val[k];
printf("mmc.srcpattern=[%d %d %d];\n",arraydim[0],arraydim[1],cfg->srcnum);
printf("mmc.srcpattern=[%d %d %d];\n",(int)arraydim[0],(int)arraydim[1],cfg->srcnum);
}else if(strcmp(name,"method")==0){
int len=mxGetNumberOfElements(item);
const char *methods[]={"plucker","havel","badouel","elem","grid",""};
Expand Down Expand Up @@ -594,7 +598,7 @@ void mmc_set_field(const mxArray *root,const mxArray *item,int idx, mcconfig *cf
memcpy(cfg->photonseed,mxGetData(item),arraydim[0]*arraydim[1]);
cfg->seed=SEED_FROM_FILE;
cfg->nphoton=arraydim[1];
printf("mmc.nphoton=%d;\n",cfg->nphoton);
printf("mmc.nphoton=%I64d;\n",cfg->nphoton);
}
}else if(strcmp(name,"replayweight")==0){
arraydim=mxGetDimensions(item);
Expand Down Expand Up @@ -645,7 +649,7 @@ void mmc_set_field(const mxArray *root,const mxArray *item,int idx, mcconfig *cf
mexErrMsgTxt("the workload list can not be longer than 256");
for(dimtype i=0;i<arraydim[0]*arraydim[1];i++)
cfg->workload[i]=val[i];
printf("mmc.workload=<<%d>>;\n",arraydim[0]*arraydim[1]);
printf("mmc.workload=<<%I64d>>;\n",arraydim[0]*arraydim[1]);
}else if(strcmp(name,"isreoriented")==0){
/*internal flag, don't need to do anything*/
}else{
Expand Down
10 changes: 5 additions & 5 deletions src/tettracing.c
Original file line number Diff line number Diff line change
Expand Up @@ -1254,7 +1254,7 @@ void onephoton(size_t id,raytracer *tracer,tetmesh *mesh,mcconfig *cfg,
}
// if(r.eid!=ID_UNDEFINED && mesh->med[mesh->type[oldeid-1]].n == cfg->nout ) break;
if(r.pout.x!=MMC_UNDEFINED && (cfg->debuglevel&dlMove))
MMC_FPRINTF(cfg->flog,"P %f %f %f %d %lu %e\n",r.pout.x,r.pout.y,r.pout.z,r.eid,id,r.slen);
MMC_FPRINTF(cfg->flog,"P %f %f %f %d %I64u %e\n",r.pout.x,r.pout.y,r.pout.z,r.eid,id,r.slen);

r.slen=(*tracercore)(&r,tracer,cfg,visit);
if(cfg->issavedet && r.Lmove>0.f && mesh->type[r.eid-1]>0)
Expand All @@ -1275,7 +1275,7 @@ void onephoton(size_t id,raytracer *tracer,tetmesh *mesh,mcconfig *cfg,
}
if(r.eid<=0 || r.pout.x==MMC_UNDEFINED) {
if(r.eid!=ID_UNDEFINED && (cfg->debuglevel&dlMove))
MMC_FPRINTF(cfg->flog,"B %f %f %f %d %lu %e\n",r.p0.x,r.p0.y,r.p0.z,r.eid,id,r.slen);
MMC_FPRINTF(cfg->flog,"B %f %f %f %d %I64u %e\n",r.p0.x,r.p0.y,r.p0.z,r.eid,id,r.slen);
if(r.eid!=ID_UNDEFINED){
if(cfg->debuglevel&dlExit)
MMC_FPRINTF(cfg->flog,"E %f %f %f %f %f %f %f %d\n",r.p0.x,r.p0.y,r.p0.z,
Expand All @@ -1289,9 +1289,9 @@ void onephoton(size_t id,raytracer *tracer,tetmesh *mesh,mcconfig *cfg,
mesh->dref[((-r.eid)-1) + tshift]+=r.weight;
}
}else if(r.faceid==-2 && (cfg->debuglevel&dlMove)){
MMC_FPRINTF(cfg->flog,"T %f %f %f %d %lu %e\n",r.p0.x,r.p0.y,r.p0.z,r.eid,id,r.slen);
MMC_FPRINTF(cfg->flog,"T %f %f %f %d %I64u %e\n",r.p0.x,r.p0.y,r.p0.z,r.eid,id,r.slen);
}else if(r.eid && r.faceid!=-2 && cfg->debuglevel&dlEdge)
MMC_FPRINTF(cfg->flog,"X %f %f %f %d %lu %e\n",r.p0.x,r.p0.y,r.p0.z,r.eid,id,r.slen);
MMC_FPRINTF(cfg->flog,"X %f %f %f %d %I64u %e\n",r.p0.x,r.p0.y,r.p0.z,r.eid,id,r.slen);

if(cfg->issavedet && r.eid<=0){
int i;
Expand All @@ -1309,7 +1309,7 @@ void onephoton(size_t id,raytracer *tracer,tetmesh *mesh,mcconfig *cfg,
}
break; /*photon exits boundary*/
}
if(cfg->debuglevel&dlMove) MMC_FPRINTF(cfg->flog,"M %f %f %f %d %lu %e\n",r.p0.x,r.p0.y,r.p0.z,r.eid,id,r.slen);
if(cfg->debuglevel&dlMove) MMC_FPRINTF(cfg->flog,"M %f %f %f %d %I64u %e\n",r.p0.x,r.p0.y,r.p0.z,r.eid,id,r.slen);
if(cfg->minenergy>0.f && r.weight < cfg->minenergy && (cfg->tend-cfg->tstart)*visit->rtstep<=1.f){ /*Russian Roulette*/
if(rand_do_roulette(ran)*cfg->roulettesize<=1.f){
r.weight*=cfg->roulettesize;
Expand Down

0 comments on commit 50fbcc7

Please sign in to comment.