Slightly different results on differents MCX and environments

44 views
Skip to first unread message

Ilya Kuznetsov

unread,
Apr 15, 2025, 3:40:48 PMApr 15
to mcx-users
Hi, Prof. Fang!

Thank your very much for MCX tool!
We are trying to move from MATLAB to more 'open' environments and I am testing my code with Octave and pmcx.
I found slightly different results and I would like to check it with you.

I have: MATLAB + Windows
$Rev::0fa060 $ v2025 $Date::2025-02-13 17:38:58 -05$ by $Author::Qianqian Fang$
- code name: [Jumbo Jolt] compiled by nvcc [7.5] for CUDA-arch [350] on [Feb 13 2025]
- compiled with: RNG [xorshift128+] with Seed Length [4]

Octave + WSL2
$Rev::5332f0 $ v2025 $Date::2025-02-16 00:22:41 -05$ by $Author::Qianqian Fang$
- code name: [Jumbo Jolt] compiled by nvcc [9.0] for CUDA-arch [350] on [Feb 23 2025]
- compiled with: RNG [xorshift128+] with Seed Length [4]

PMCX + Windows 
$Rev::0fa060 $ v2025 $Date::2025-02-13 17:38:58 -05$ by $Author::Qianqian Fang$
- code name: [Fermi MCX] compiled by nvcc [10.2] for CUDA-arch [350] on [Feb 13 2025]
- compiled with: RNG [xorshift128+] with Seed Length [4]

  • For Octave and MATLAB I have an identical code, I literraly run the same file.
  • For pmcx I save cfg from MATLAB mat file, convert it to python format and just run pmcx.mcxlab(cfg)
  • seed everywhere is constant and equal 10000000

For MATLAB and PMCX I see identical amount of detected photons, but different amount of E on the detectors (like 4.5773e-06 for MATLAB and 4.047e-06 for PMCX version).

But for MATLAB and Octave I see different amount of detected photons (0.05% difference), but result of simulation (after mcxdref) are closer between MATLAB and Octave.

Could you give advice or share your ideas why the results are different everywhere? 
I thought pmcx and MATLAB versions should get the same results due the same revision and OS (but the codename is strangely different, maybe a typo).

Qianqian Fang

unread,
Apr 16, 2025, 12:42:40 PMApr 16
to mcx-...@googlegroups.com, Ilya Kuznetsov

hi Ilya,

exact reproducibility between simulations, even within the same environment, is not guaranteed for MCX, and accumulation operations on the GPU in general.

please see previous discussions on this topic

https://groups.google.com/g/mcx-users/c/DXJ9C70Sajo/m/TVmGaK0NAQAJ

https://groups.google.com/g/mcx-users/c/pFp8wstktw4/m/KXeRmkcyAwAJ

https://groups.google.com/g/mcx-users/c/E9VgPb4q62M/m/d6G_9Dr7AgAJ


if the simulations runs on different GPUs, or different OSes, the chance of getting nearly identical output is unlikely - by default, mcx determines a total number of threads based on the GPUs core count, and different GPUs will use different number of threads - even the seeds are the same, the results won't be the same; similarly, different GPU driver version also changes the behaviors of thread scheduler and causes the order of operations non-repeatible.


> For MATLAB and PMCX I see identical amount of detected photons, but different amount of E on the detectors (like 4.5773e-06 for MATLAB and 4.047e-06 for PMCX version).

what do you mean by different amount of "E"? detected photon weight? how did you compute this number?


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 view this discussion visit https://groups.google.com/d/msgid/mcx-users/d5e502db-23e7-415b-89eb-fe61bea6a870n%40googlegroups.com.

Ilya Kuznetsov

unread,
Apr 17, 2025, 5:23:33 AMApr 17
to mcx-users
Thanks for your answer,  I understand now.

Regarding amount of E on the detector - I run simulation using cfg.outputtype = 'energy' and then calculate energy on the detector using mcxdref, but I changed mcxdref.m in my project - I don't divide detweightsum./cfg.nphoton by area of the detector. 
This way I am getting amount of energy on each detector, assuming that input energy is 1 joule.

Qianqian Fang

unread,
Apr 30, 2025, 10:48:35 AMApr 30
to mcx-...@googlegroups.com, Ilya Kuznetsov

if you are trying to get the total detected "energy" at a given detector, you do not need to set outputtype to 'energy', because that flag only specifies the volumetric output (flux.data), and has no effect to detected photon data (detp).

I assume you meant mcxcwdref.m instead of mcxdref.m.

Ilya Kuznetsov

unread,
Apr 30, 2025, 4:26:31 PMApr 30
to mcx-users
Thanks!

Yes, I meant mcxcwdref.m.
Reply all
Reply to author
Forward
0 new messages