Issues with MCX and 'pattern' srctype

225 views
Skip to first unread message

Nicholas Dana

unread,
Apr 18, 2016, 2:58:53 PM4/18/16
to mcx-users
I've been using MCX to estimate fluences for some photoacoustic and diffuse reflectance applications, but I'm getting some consistent crashes when using the 'pattern' srctype.

My current implementation uses a previous flux output (at a shorter wavelength) to generate a slice (i.e. pattern image) that corresponds to what fluorescent sources would be in the tissue at that slice. I then scale this image to [0-1] and define cfg.srcpos, cfg.srcparam1 and cfg.srcparam2 based on where I generated the slice from. I also modify the cfg.prop to reflect the optical properties at a different wavelength and keep the cfg.nphoton low for testing purposes. All other cfg parameters stay the same. When I attempt to run it thus, I invariably get a MATLAB crash and a lengthy error detail.

When I modify the script slightly to use a 'gaussian' source type to mimic the image generated from above and define cfg.srcpos & cfg.srcparam1 appropriately, it executes fine and I get a flux output in line with expectations.

I've attached my code with the 'pattern' srctype section commented out, and the 'gaussian' section filled in. I've also posted the error I received when I use the 'pattern' srctype below, . I've checked and rechecked the cfg.srcpattern parameter to make sure it is sized and scaled properly. Any experience a similar problem and solve it? It also seems to crash at the same time after calling mcxlab, which is right before it displays 'mcx.srcparam2'. Any help is greatly appreciated.

------------------------------------------------------------------------
          Access violation detected at Mon Apr 18 13:56:00 2016
------------------------------------------------------------------------

Configuration:
  Crash Decoding     : Disabled
  Default Encoding   : windows-1252
  Graphics card 1    : DemoForge ( 0x0 ) Mirage Driver Version 2.0.105.0
  Graphics card 2    : NVIDIA ( 0x10de ) NVIDIA Quadro K600 Version 10.18.13.5390
  MATLAB Architecture: win64
  MATLAB Root        : C:\Program Files\MATLAB\R2014b
  MATLAB Version     : 8.4.0.150421 (R2014b)
  Operating System   : Microsoft Windows 7 Enterprise 
  Processor ID       : x86 Family 6 Model 60 Stepping 3, GenuineIntel
  Software OpenGL    : 0
  Virtual Machine    : Java 1.7.0_11-b21 with Oracle Corporation Java HotSpot(TM) 64-Bit Server VM mixed mode
  Window System      : Version 6.1 (Build 7601: Service Pack 1)

Fault Count: 1


Abnormal termination:
Access violation

Register State (from fault):
  RAX = 000000000003d090  RBX = 0000000004026df0
  RCX = 000000000007afb0  RDX = 000000000000000a
  RSP = 0000000004026b70  RBP = 000000000e8b6000
  RSI = 000000000001ebec  RDI = 000000003a3d7360
 
   R8 = 00000000100e0080   R9 = 00000000000002a0
  R10 = 0000000000010000  R11 = 00000000000001d0
  R12 = 000000003a3d7090  R13 = 0000000000000001
  R14 = 0000000000000000  R15 = 0000000000000001
 
  RIP = 000000000fc021b0  EFL = 00010287
 
   CS = 0033   FS = 0053   GS = 002b

Stack Trace (from fault):
[  0] 0x000000000fc021b0 C:\Users\nd5583\Box Sync\Data\mcx\mcxlab\mcxlab.mexw64+00008624
[  1] 0x000000000fc02875 C:\Users\nd5583\Box Sync\Data\mcx\mcxlab\mcxlab.mexw64+00010357 mexFunction+00000357
[  2] 0x00000000fc5f3701 C:\Program Files\MATLAB\R2014b\bin\win64\libmex.dll+00079617 mexRunMexFile+00000129
[  3] 0x00000000fc5f2762 C:\Program Files\MATLAB\R2014b\bin\win64\libmex.dll+00075618 inSwapMexfileReader+00000690
[  4] 0x00000000fc5f2248 C:\Program Files\MATLAB\R2014b\bin\win64\libmex.dll+00074312 mexUnlock+00006008
[  5] 0x0000000004cf05e3 C:\Program Files\MATLAB\R2014b\bin\win64\m_dispatcher.dll+00067043 Mfh_file::dispatch_fh+00000659
[  6] 0x0000000004cf0aee C:\Program Files\MATLAB\R2014b\bin\win64\m_dispatcher.dll+00068334 Mfunction_handle::dispatch+00000766
[  7] 0x0000000004e02b2f C:\Program Files\MATLAB\R2014b\bin\win64\m_interpreter.dll+00273199 inGetNameInSymbolTable+00017071
[  8] 0x0000000004eeb6f7 C:\Program Files\MATLAB\R2014b\bin\win64\m_interpreter.dll+01226487 inFullEvalFcn+00011159
[  9] 0x0000000004e05592 C:\Program Files\MATLAB\R2014b\bin\win64\m_interpreter.dll+00284050 inGetNameInSymbolTable+00027922
[ 10] 0x0000000004e01b4f C:\Program Files\MATLAB\R2014b\bin\win64\m_interpreter.dll+00269135 inGetNameInSymbolTable+00013007
[ 11] 0x0000000004e01ab1 C:\Program Files\MATLAB\R2014b\bin\win64\m_interpreter.dll+00268977 inGetNameInSymbolTable+00012849
[ 12] 0x0000000004e2406f C:\Program Files\MATLAB\R2014b\bin\win64\m_interpreter.dll+00409711 inPathNotification::function_delete_notification+00098591
[ 13] 0x0000000004e227af C:\Program Files\MATLAB\R2014b\bin\win64\m_interpreter.dll+00403375 inPathNotification::function_delete_notification+00092255
[ 14] 0x0000000004e21359 C:\Program Files\MATLAB\R2014b\bin\win64\m_interpreter.dll+00398169 inPathNotification::function_delete_notification+00087049
[ 15] 0x0000000004cf07a4 C:\Program Files\MATLAB\R2014b\bin\win64\m_dispatcher.dll+00067492 Mfh_file::dispatch_fh+00001108
[ 16] 0x0000000004cf0aee C:\Program Files\MATLAB\R2014b\bin\win64\m_dispatcher.dll+00068334 Mfunction_handle::dispatch+00000766
[ 17] 0x0000000004e02b2f C:\Program Files\MATLAB\R2014b\bin\win64\m_interpreter.dll+00273199 inGetNameInSymbolTable+00017071
[ 18] 0x0000000004eeb6f7 C:\Program Files\MATLAB\R2014b\bin\win64\m_interpreter.dll+01226487 inFullEvalFcn+00011159
[ 19] 0x0000000004e05592 C:\Program Files\MATLAB\R2014b\bin\win64\m_interpreter.dll+00284050 inGetNameInSymbolTable+00027922
[ 20] 0x0000000004e01b4f C:\Program Files\MATLAB\R2014b\bin\win64\m_interpreter.dll+00269135 inGetNameInSymbolTable+00013007
[ 21] 0x0000000004e01ab1 C:\Program Files\MATLAB\R2014b\bin\win64\m_interpreter.dll+00268977 inGetNameInSymbolTable+00012849
[ 22] 0x0000000004e2406f C:\Program Files\MATLAB\R2014b\bin\win64\m_interpreter.dll+00409711 inPathNotification::function_delete_notification+00098591
[ 23] 0x0000000004e227af C:\Program Files\MATLAB\R2014b\bin\win64\m_interpreter.dll+00403375 inPathNotification::function_delete_notification+00092255
[ 24] 0x0000000004e21359 C:\Program Files\MATLAB\R2014b\bin\win64\m_interpreter.dll+00398169 inPathNotification::function_delete_notification+00087049
[ 25] 0x0000000004cf07a4 C:\Program Files\MATLAB\R2014b\bin\win64\m_dispatcher.dll+00067492 Mfh_file::dispatch_fh+00001108
[ 26] 0x0000000004cf0aee C:\Program Files\MATLAB\R2014b\bin\win64\m_dispatcher.dll+00068334 Mfunction_handle::dispatch+00000766
[ 27] 0x0000000004e54a88 C:\Program Files\MATLAB\R2014b\bin\win64\m_interpreter.dll+00608904 inPathNotification::function_delete_notification+00297784
[ 28] 0x0000000004e54a04 C:\Program Files\MATLAB\R2014b\bin\win64\m_interpreter.dll+00608772 inPathNotification::function_delete_notification+00297652
[ 29] 0x0000000004e549c5 C:\Program Files\MATLAB\R2014b\bin\win64\m_interpreter.dll+00608709 inPathNotification::function_delete_notification+00297589
[ 30] 0x0000000004e54992 C:\Program Files\MATLAB\R2014b\bin\win64\m_interpreter.dll+00608658 inPathNotification::function_delete_notification+00297538
[ 31] 0x0000000004e54947 C:\Program Files\MATLAB\R2014b\bin\win64\m_interpreter.dll+00608583 inPathNotification::function_delete_notification+00297463
[ 32] 0x0000000004dcd69d C:\Program Files\MATLAB\R2014b\bin\win64\m_interpreter.dll+00054941 inEvalExp+00001309
[ 33] 0x0000000004ef525d C:\Program Files\MATLAB\R2014b\bin\win64\m_interpreter.dll+01266269 inEvalCmdWithLocalReturn+00000285
[ 34] 0x0000000004ef5181 C:\Program Files\MATLAB\R2014b\bin\win64\m_interpreter.dll+01266049 inEvalCmdWithLocalReturn+00000065
[ 35] 0x000000000636e31d C:\Program Files\MATLAB\R2014b\bin\win64\libmwbridge.dll+00058141 mnGetPrompt+00001517
[ 36] 0x000000000636ed09 C:\Program Files\MATLAB\R2014b\bin\win64\libmwbridge.dll+00060681 mnParser+00000745
[ 37] 0x00000000fd0dd834   C:\Program Files\MATLAB\R2014b\bin\win64\mcr.dll+00383028 mcrInstance::mnParser_on_interpreter_thread+00000036
[ 38] 0x00000000fd0a68e7   C:\Program Files\MATLAB\R2014b\bin\win64\mcr.dll+00157927 mcr::runtime::setInterpreterThreadToCurrent+00019751
[ 39] 0x00000000fd0a6923   C:\Program Files\MATLAB\R2014b\bin\win64\mcr.dll+00157987 mcr::runtime::setInterpreterThreadToCurrent+00019811
[ 40] 0x00000000fd0a7121   C:\Program Files\MATLAB\R2014b\bin\win64\mcr.dll+00160033 mcr::runtime::setInterpreterThreadToCurrent+00021857
[ 41] 0x00000000fab5d3a6   C:\Program Files\MATLAB\R2014b\bin\win64\uiw.dll+00512934 UIW_AttachThreadInput+00001270
[ 42] 0x00000000fab5cc35   C:\Program Files\MATLAB\R2014b\bin\win64\uiw.dll+00511029 wsd_to_MSW+00004373
[ 43] 0x00000000fab5ccb9   C:\Program Files\MATLAB\R2014b\bin\win64\uiw.dll+00511161 wsd_to_MSW+00004505
[ 44] 0x00000000775d8802                     C:\WINDOWS\system32\USER32.dll+00165890 GetMenuBarInfo+00000626
[ 45] 0x00000000775bf5e7                     C:\WINDOWS\system32\USER32.dll+00062951 SystemParametersInfoW+00000247
[ 46] 0x00000000775c4869                     C:\WINDOWS\system32\USER32.dll+00084073 IsProcessDPIAware+00000453
[ 47] 0x000000007781ba75                      C:\WINDOWS\SYSTEM32\ntdll.dll+00309877 KiUserCallbackDispatcher+00000031
[ 48] 0x00000000775c90ca                     C:\WINDOWS\system32\USER32.dll+00102602 PeekMessageW+00000186
[ 49] 0x00000000775c50de                     C:\WINDOWS\system32\USER32.dll+00086238 GetKeyState+00000238
[ 50] 0x00000000775c3a47                     C:\WINDOWS\system32\USER32.dll+00080455 PeekMessageA+00000087
[ 51] 0x00000000fab0a26b   C:\Program Files\MATLAB\R2014b\bin\win64\uiw.dll+00172651 UIW_ShowMenuItem+00003995
[ 52] 0x00000000fab5dce2   C:\Program Files\MATLAB\R2014b\bin\win64\uiw.dll+00515298 UIW_SuspendAttachThreadInput+00000466
[ 53] 0x0000000100118223 C:\Program Files\MATLAB\R2014b\bin\win64\libmwservices.dll+01212963 services::system_events::PpeDispatchHook::dispatchOne+00032291
[ 54] 0x0000000100123c95 C:\Program Files\MATLAB\R2014b\bin\win64\libmwservices.dll+01260693 sysq::addProcessPendingEventsUnitTestHook+00005813
[ 55] 0x0000000100123d50 C:\Program Files\MATLAB\R2014b\bin\win64\libmwservices.dll+01260880 sysq::addProcessPendingEventsUnitTestHook+00006000
[ 56] 0x0000000100125b75 C:\Program Files\MATLAB\R2014b\bin\win64\libmwservices.dll+01268597 sysq::getCondition+00004629
[ 57] 0x00000001001274ba C:\Program Files\MATLAB\R2014b\bin\win64\libmwservices.dll+01275066 svWS_ProcessPendingEvents+00000138
[ 58] 0x00000000fd0a783d   C:\Program Files\MATLAB\R2014b\bin\win64\mcr.dll+00161853 mcr::runtime::setInterpreterThreadToCurrent+00023677
[ 59] 0x00000000fd0a84aa   C:\Program Files\MATLAB\R2014b\bin\win64\mcr.dll+00165034 mcr::runtime::setInterpreterThreadToCurrent+00026858
[ 60] 0x00000000fd0a0135   C:\Program Files\MATLAB\R2014b\bin\win64\mcr.dll+00131381 mcr_process_events+00007477
[ 61] 0x00000000fd0a1a12   C:\Program Files\MATLAB\R2014b\bin\win64\mcr.dll+00137746 mcr_process_events+00013842
[ 62] 0x0000000008128f2d C:\Program Files\MATLAB\R2014b\bin\win64\MVMLocal.dll+00167725 mvm_server::inproc::LocalFactory::terminate+00048285
[ 63] 0x00000000fa8ef1ea   C:\Program Files\MATLAB\R2014b\bin\win64\mvm.dll+00782826 mvm::detail::initLocalMvmHack+00000490
[ 64] 0x00000000fa8ef7a8   C:\Program Files\MATLAB\R2014b\bin\win64\mvm.dll+00784296 mvm::detail::SessionImpl::privateSession+00000376
[ 65] 0x00000000fa8ef9f8   C:\Program Files\MATLAB\R2014b\bin\win64\mvm.dll+00784888 mvm::detail::SessionImpl::privateSession+00000968
[ 66] 0x0000000140005ddd C:\Program Files\MATLAB\R2014b\bin\win64\matlab.exe+00024029
[ 67] 0x0000000140007870 C:\Program Files\MATLAB\R2014b\bin\win64\matlab.exe+00030832
[ 68] 0x00000000776c59bd                   C:\WINDOWS\system32\kernel32.dll+00088509 BaseThreadInitThunk+00000013
[ 69] 0x00000000777fa2e1                      C:\WINDOWS\SYSTEM32\ntdll.dll+00172769 RtlUserThreadStart+00000033


This error was detected while a MEX-file was running. If the MEX-file
is not an official MathWorks function, please examine its source code
for errors. Please consult the External Interfaces Guide for information
on debugging MEX-files.

If this problem is reproducible, please submit a Service Request via:

A technical support engineer might contact you with further information.

Thank you for your help.** This crash report has been saved to disk as C:\Users\nd5583\AppData\Local\Temp\matlab_crash_dump.4692-1 **

mcTest.m

Nicholas Dana

unread,
Apr 18, 2016, 2:59:49 PM4/18/16
to mcx-users
Typo in above, the 'gaussian' srctype is commented out in the code attached.

Qianqian Fang

unread,
Apr 19, 2016, 12:50:49 AM4/19/16
to mcx-...@googlegroups.com
On 04/18/2016 02:58 PM, Nicholas Dana wrote:
I've been using MCX to estimate fluences for some photoacoustic and diffuse reflectance applications, but I'm getting some consistent crashes when using the 'pattern' srctype.

My current implementation uses a previous flux output (at a shorter wavelength) to generate a slice (i.e. pattern image) that corresponds to what fluorescent sources would be in the tissue at that slice. I then scale this image to [0-1] and define cfg.srcpos, cfg.srcparam1 and cfg.srcparam2 based on where I generated the slice from. I also modify the cfg.prop to reflect the optical properties at a different wavelength and keep the cfg.nphoton low for testing purposes. All other cfg parameters stay the same. When I attempt to run it thus, I invariably get a MATLAB crash and a lengthy error detail.

hi Nicholas

a quick comparison between your script and the  built-in 'pattern'
source testing script in mcxlab/examples/demo_mcxlab_srctype.m:

https://github.com/fangq/mcx/blob/master/mcxlab/examples/demo_mcxlab_srctype.m#L116-L152

I found your srcparam1 and srcparam2 have reverted
dimensions of your input pattern array (pat). I am not sure if
this will cause a crash, but perhaps it is worth swapping
srcparam1 and srcparam2 definitions and see what happens.

Also, if you know how to recompile mcx, I strongly recommend
upgrading to the latest git version. There have been many
updates since the last release, and I am working on making
a new release, hopefully make it ready in the next few days.

I am happy to debug this problem, if you can send me
your mcxOut.mat file and your cfg.prop values.

Qianqian


--
You received this message because you are subscribed to the Google Groups "mcx-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mcx-users+...@googlegroups.com.
To post to this group, send email to mcx-...@googlegroups.com.
Visit this group at https://groups.google.com/group/mcx-users.
For more options, visit https://groups.google.com/d/optout.

Nicholas Dana

unread,
Apr 19, 2016, 2:00:03 PM4/19/16
to mcx-users
Dr. Fang,

Thank you for your quick reply. Based on your suggestion, I swapped srcparam1 and srcparam2, as well as modifying which corners they point to, as so: 

cfg.srcpos = [0 0 ii];
cfg.srcparam1 = [0  size(cfg.vol,2) 0 size(pat,2)];
cfg.srcparam2 = [size(cfg.vol,1) size(cfg.vol,2) 0 size(pat,1)];

The crash still occurred in the same fashion for all cases, as before. Below are my cfg.prop values

cfg.prop = [
    0.0000    0.0010    1.0000    1.0000
    0.0000    0.0100    1.0000    1.0000
    0.1585    0.4358    0.9100    1.4000
    1.0000    0.1000         0    1.5000];

I should say that I'm using a very small voxel size (10 um) as I'm simulating short wavelength light. Originally I had had some issues with defining the cfg.unitinmm = 0.01. A work around I found was to let the model interpret the voxel size as default, but scale the absorption & scattering to reflect grid units, as opposed to millimeters. This is how I've come up with the numbers I have. As such, my vol is large (500x500x500) and mcxOut.mat is large also. I've included a link to it on dropbox for you to download if you will. I can, of course, modify the solution space to use a smaller volume for testing purposes, but this is the same output as was generated previously and which worked when using the 'gaussian' srctype. 


As far as version, I'm using mcxlab 0.9.7-2, from 2014/09/26. This is the most recent version I'm seeing on sourceforge. I see that http://mcx.space/#mmc has a link button that suggests there is v2016.4 of MCX, but I don't see such a version at sourceforge (am I missing something?). If there is a newer version, I can try recompiling.

Thanks in advance!

Nicholas Dana

unread,
Apr 20, 2016, 6:33:58 PM4/20/16
to mcx-users
So I tried recreating the issue by running mcxlab on a 2nd machine, still Windows 7 with CUDA 4.0. The script either caused Matlab to crash outright, or appeared to execute, but flux.data a 3D array full of nothing but NaN. It seemed to only execute the script without crashing IF I had previously run another mcxlab instance in matlab prior running mcTest.m, though that was intermittent. I tested on previous machine and it exhibited same behavior, sometimes executing but outputting NaN, but usually crashing. The on-screen output of the script looked normal, save that values reported for normalization factor, absorbed energy, etc were garbage due to the NaN values (e.g. normalization factor: #NAN0000x1)

Hope this helps

Qianqian Fang

unread,
Apr 20, 2016, 7:28:25 PM4/20/16
to mcx-...@googlegroups.com
On 04/20/2016 06:33 PM, Nicholas Dana wrote:
So I tried recreating the issue by running mcxlab on a 2nd machine, still Windows 7 with CUDA 4.0. The script either caused Matlab to crash outright, or appeared to execute, but flux.data a 3D array full of nothing but NaN. It seemed to only execute the script without crashing IF I had previously run another mcxlab instance in matlab prior running mcTest.m, though that was intermittent. I tested on previous machine and it exhibited same behavior, sometimes executing but outputting NaN, but usually crashing. The on-screen output of the script looked normal, save that values reported for normalization factor, absorbed energy, etc were garbage due to the NaN values (e.g. normalization factor: #NAN0000x1)

hi Nicholas

as I mentioned earlier, I am working on making a new release (v2016.4)
both Linux and Mac are almost ready, now I am testing on windows.
Once this is done (hopefully by tomorrow), I will upload the precompiled
binaries, as well as the source code (github always has the latest).

I did run your script yesterday. I noticed you used a very large
vol array. This is not efficient for debugging purposes. You also
defined some extra fields that are not supported by mcxlab.
Especially, you defined cfg.vox_size, which is not a valid mcxlab
option. You should use cfg.unitinmm.

after fixing most of these issues, I was able to run your simulation,
I did not get a crash. The results look reasonable (screenshots attached).

Here are my scripts, first for the Gaussian source:

load mcxOut
oldvol=cfg.vol;
cfg.vol=oldvol(1:5:end,1:5:end,1:5:end); % downsample by 5x
cfg.unitinmm=0.05;    % set length unit accordingly
cfg.srcpos=[50 50 1];
cfg.srcparam1=[90/5 0 0 0];
cfg.srcparam2=[0 0 0 0]; 
cfg.detpos=[50 10 1 40];
cfg.respin=1;  % I have a dedicated GPU

fl=mcxlab(cfg);
hs=slice(log10(double(fl.data)),50, 50, 10); set(hs,'linestyle','none')

Launching MCXLAB - Monte Carlo eXtreme for MATLAB & GNU Octave ...
Running simulations for configuration #1 ...
WARNING: redundant field 'WL'
mcx.dim=[100 100 100];
mcx.seed=1732221598;
mcx.nphoton=5e+08;
mcx.srcpos=[50 50 1];
mcx.srcdir=[0 0 1];
mcx.srctype='gaussian';
mcx.srcparam1=[18 0 0 0];
mcx.medianum=4;
mcx.tstart=0;
mcx.tend=5e-09;
mcx.tstep=5e-09;
mcx.autopilot=1;
mcx.gpuid=1;
mcx.respin=1;
mcx.isreflect=0;
mcx.isrefint=0;
WARNING: redundant field 'issavedet'
mcx.detnum=1;
mcx.maxdetphoton=1e+07;
WARNING: redundant field 'vox_size'
mcx.unitinmm=0.05;
mcx.srcparam2=[0 0 0 0];
###############################################################################
#                      Monte Carlo eXtreme (MCX) -- CUDA                      #
#          Copyright (c) 2009-2016 Qianqian Fang <q.fang at neu.edu>          #
#                             http://mcx.space/                               #
#                                                                             #
#         Computational Imaging Laboratory (CIL) [http://fanglab.org]         #
#            Department of Bioengineering, Northeastern University            #
###############################################################################
#    The MCX Project is funded by the NIH/NIGMS under grant R01-GM114365      #
###############################################################################
$Rev::c52b47 $ Last $Date::2016-04-06 01:50:15 -04$ by $Author::Qianqian Fang $
###############################################################################
- variant name: [Fermi] compiled for GPU Capability [100] with CUDA [7000]
- compiled with: RNG [xorshift128+] with Seed Length [4]
- this version CAN save photons at the detectors


GPU=1 (GeForce GTX 980 Ti) threadph=11097 extra=13600 np=500000032 nthread=45056 maxgate=1 repetition=1
initializing streams ...    init complete : 0 ms
requesting 3072 bytes of shared memory
lauching MCX simulation for time window [0.00e+00ns 5.00e+00ns] ...
simulation run# 1 ...     kernel complete:      16481 ms
retrieving fields ...     transfer complete:    16483 ms
data normalization complete : 16484 ms
normalizing raw data ...    normalization factor alpha=159.999985
simulated 500000000 photons (500000000) with 45056 threads (repeat x1)
MCX simulation speed: 30354.54 photon/ms
total simulated energy: 500000032.00    absorbed: 18.48011%
(loss due to initial specular reflection is excluded in the total)
Then for the pattern source:
cfg.srctype='pattern';
ii=80/5;
pat = flux.data(1:5:end,1:5:end,ii*5).*(cfg.vol(:,:,ii)==2);
patmax = max(pat(:));
cfg.srcpattern= pat./patmax;  
cfg.srcpos=[1 1 ii];        
cfg.srcparam1=[size(cfg.vol,1),0 0 size(pat,1)];
cfg.srcparam2=[0 size(cfg.vol,1) 0 size(pat,2)];
fl2=mcxlab(cfg);
hs=slice(log10(double(fl2.data)),50, 50, 10); set(hs,'linestyle','none')

Launching MCXLAB - Monte Carlo eXtreme for MATLAB & GNU Octave ...
Running simulations for configuration #1 ...
WARNING: redundant field 'WL'
mcx.dim=[100 100 100];
mcx.seed=1732221598;
mcx.nphoton=5e+08;
mcx.srcpos=[1 1 16];
mcx.srcdir=[0 0 1];
mcx.srctype='pattern';
mcx.srcparam1=[100 0 0 100];
mcx.medianum=4;
mcx.tstart=0;
mcx.tend=5e-09;
mcx.tstep=5e-09;
mcx.autopilot=1;
mcx.gpuid=1;
mcx.respin=1;
mcx.isreflect=0;
mcx.isrefint=0;
WARNING: redundant field 'issavedet'
mcx.detnum=1;
mcx.maxdetphoton=1e+07;
WARNING: redundant field 'vox_size'
mcx.unitinmm=0.05;
mcx.srcparam2=[0 100 0 100];
mcx.srcpattern=[100 100];
###############################################################################
#                      Monte Carlo eXtreme (MCX) -- CUDA                      #
#          Copyright (c) 2009-2016 Qianqian Fang <q.fang at neu.edu>          #
#                             http://mcx.space/                               #
#                                                                             #
#         Computational Imaging Laboratory (CIL) [http://fanglab.org]         #
#            Department of Bioengineering, Northeastern University            #
###############################################################################
#    The MCX Project is funded by the NIH/NIGMS under grant R01-GM114365      #
###############################################################################
$Rev::c52b47 $ Last $Date::2016-04-06 01:50:15 -04$ by $Author::Qianqian Fang $
###############################################################################
- variant name: [Fermi] compiled for GPU Capability [100] with CUDA [7000]
- compiled with: RNG [xorshift128+] with Seed Length [4]
- this version CAN save photons at the detectors


GPU=1 (GeForce GTX 980 Ti) threadph=11097 extra=13600 np=500000032 nthread=45056 maxgate=1 repetition=1
initializing streams ...    init complete : 1 ms
requesting 3072 bytes of shared memory
lauching MCX simulation for time window [0.00e+00ns 5.00e+00ns] ...
simulation run# 1 ...     kernel complete:      48022 ms
retrieving fields ...     transfer complete:    48024 ms
data normalization complete : 48024 ms
normalizing raw data ...    normalization factor alpha=5879.846680
simulated 500000000 photons (500000000) with 45056 threads (repeat x1)
MCX simulation speed: 10413.85 photon/ms
total simulated energy: 13605796.54    absorbed: 14.32143%
(loss due to initial specular reflection is excluded in the total)


by the way, try to set up a dedicated GPU if you want to take full
advantage of MCX. You can see from my log, if I use a dedicated GPU setting
(a Maxwell, 980Ti), I can get a speed of 30354 photon/ms (for Gaussian src),
but if I use your setting, cfg.respin=3334, I was only able to get 1021 photon/ms.
You got a 30x slow-down using a non-dedicated GPU!

Qianqian
gaussian_profile.png
fluxdata_profile.png

Nicholas Dana

unread,
Apr 20, 2016, 9:22:06 PM4/20/16
to mcx-users
Thanks again for your fast response Dr. Fang. I copied your code exactly and experienced the same issues I had had. 

clear; close all;clc

load mcxOut
oldvol
=cfg.vol;

cfg
.vol=oldvol(1:5:end,1:5:end,1:5:end); % downsample by 5x
cfg
.unitinmm=0.05;    % set length unit accordingly
cfg
.srcpos=[50 50 1];
cfg
.srcparam1=[90/5 0 0 0];
cfg
.srcparam2=[0 0 0 0];  
cfg
.detpos=[50 10 1 40];
cfg
.respin=1;  %
I have a dedicated GPU
cfg
.nphoton = 1e6;


fl
=mcxlab(cfg);
hs
=slice(log10(double(fl.data)),50, 50, 10); set(hs,'linestyle','none')

Launching MCXLAB - Monte Carlo eXtreme for MATLAB & GNU Octave ...
Running simulations for configuration #1 ...
mcx.dim=[100 100 100];
mcx.seed=1.73222e+09;
mcx.nphoton=1e+06;
mcx.srcpos=[50 50 1];
mcx.srcdir=[0 0 1];
mcx.srctype='gaussian';
mcx.srcparam1=[18 0 0 0];
mcx.medianum=4;
mcx.unitinmm=0.05;
mcx.tstart=0;
mcx.tend=5e-09;
mcx.tstep=5e-09;
mcx.autopilot=1;
mcx.gpuid=1;
mcx.respin=1;
mcx.isreflect=0;
mcx.isrefint=0;
mcx.issavedet=0;
mcx.detnum=1;
mcx.maxdetphoton=1e+07;
mcx.srcparam2=[0 0 0 0];
autopilot mode: setting thread number to 12288, block size to 64 and time gates to 1
###############################################################################
#                      Monte Carlo eXtreme (MCX) -- CUDA                      #
#     Copyright (c) 2009-2013 Qianqian Fang <fangq at nmr.mgh.harvard.edu>    #
#                                                                             #
#    Martinos Center for Biomedical Imaging, Massachusetts General Hospital   #
###############################################################################
$MCX $Rev:: 325 $ Last Commit $Date:: 2014-09-23 13:34:57#$ by $Author:: fangq$
###############################################################################
- variant name: [Fermi MCX] compiled for GPU Capability [100] with CUDA [4000]
- compiled with: RNG [Logistic-Lattice] with Seed Length [5]
- this version CAN save photons at the detectors

threadph=81 oddphotons=4672 np=1000000 nthread=12288 repetition=1
initializing streams ... init complete : 1 ms
requesting 0 bytes of shared memory
lauching MCX simulation for time window [0.00e+00ns 5.00e+00ns] ...
simulation run# 1 ... kernel complete:   1235 ms
retrieving fields ... transfer complete: 1250 ms
normalizing raw data ... normalization factor alpha=91940.070313
data normalization complete : 1265 ms
simulated 1000000 photons (1000000) with 12288 threads (repeat x1)
MCX simulation speed: 822.37 photon/ms
exit energy:  8.91699609e+04 + absorbed energy:  9.10830063e+05 = total:   1.00000000e+06

And the output image looks similar to yours, albeit much noisier. Then, with the second portion: 
cfg.srctype='pattern';
ii
=80/5;
pat
= flux.data(1:5:end,1:5:end,ii*5).*(cfg.vol(:,:,ii)==2);
patmax
= max(pat(:));
cfg
.srcpattern= pat./patmax;
cfg
.srcpos=[1 1 ii];
cfg
.srcparam1=[size(cfg.vol,1),0 0 size(pat,1)];
cfg
.srcparam2=[0 size(cfg.vol,1) 0 size(pat,2)];
fl2
=mcxlab(cfg);
hs
=slice(log10(double(fl2.data)),50, 50, 10); set(hs,'linestyle','none')

Launching MCXLAB - Monte Carlo eXtreme for MATLAB & GNU Octave ...
Running simulations for configuration #1 ...
mcx.dim=[100 100 100];
mcx.seed=1.73222e+09;
mcx.nphoton=1e+06;
mcx.srcpos=[1 1 16];
mcx.srcdir=[0 0 1];
mcx.srctype='pattern';
mcx.srcparam1=[100 0 0 100];
mcx.medianum=4;
mcx.unitinmm=0.05;
mcx.tstart=0;
mcx.tend=5e-09;
mcx.tstep=5e-09;
mcx.autopilot=1;
mcx.gpuid=1;
mcx.respin=1;
mcx.isreflect=0;
mcx.isrefint=0;
mcx.issavedet=0;
mcx.detnum=1;
mcx.maxdetphoton=1e+07;
mcx.srcparam2=[0 100 0 100];
mcx.srcpattern=[100 100];
autopilot mode: setting thread number to 12288, block size to 64 and time gates to 1
###############################################################################
#                      Monte Carlo eXtreme (MCX) -- CUDA                      #
#     Copyright (c) 2009-2013 Qianqian Fang <fangq at nmr.mgh.harvard.edu>    #
#                                                                             #
#    Martinos Center for Biomedical Imaging, Massachusetts General Hospital   #
###############################################################################
$MCX $Rev:: 325 $ Last Commit $Date:: 2014-09-23 13:34:57#$ by $Author:: fangq$
###############################################################################
- variant name: [Fermi MCX] compiled for GPU Capability [100] with CUDA [4000]
- compiled with: RNG [Logistic-Lattice] with Seed Length [5]
- this version CAN save photons at the detectors

threadph=81 oddphotons=4672 np=1000000 nthread=12288 repetition=1
initializing streams ... init complete : 0 ms
requesting 0 bytes of shared memory
lauching MCX simulation for time window [0.00e+00ns 5.00e+00ns] ...
simulation run# 1 ... kernel complete:   1453 ms
retrieving fields ... transfer complete: 1456 ms
normalizing raw data ... normalization factor alpha=1.#QNAN0
data normalization complete : 1470 ms
simulated 1000000 photons (1000000) with 12288 threads (repeat x1)
MCX simulation speed: 695.89 photon/ms
exit energy:  1.#QNAN000e+00 + absorbed energy:  1.#QNAN000e+00 = total:   1.#QNAN000e+00

And then Matlab throws an error trying to execute slice. Similar to previously, fl2 is full of NaN. The only difference I see is you're using Cuda 7.0, presumably on Linux. I have the ability to install Ubuntu alongside Windows 7 on this machine, which perhaps I'll look into if the updated versions don't resolve this issue.

Per your recommendation for a dedicated graphics card, this machine has 2 graphics cards, with the secondary card being an Nvidia GT 730. While I can certainly use mcxlab on either card (by specifying gpuid), I still get a kernel launch timeout error, regardless of which card is being used. I've looked in the previous posts edited TdrDelay, which helps, but I still get a timeout even with a dedicated GPU. Perhaps there's another setting I missed?

Thanks again for your help!
...
gaussian_profile_ND.png
Reply all
Reply to author
Forward
0 new messages