Parallel computing Monte Carlo

17 次查看(过去 30 天)
I'm running 1M simulations on a Monte Carlo basis. I'd like to improve the computation speed and I was thinking about parallel computing but wanted to have a guess about what to expect in term of improvment.
I'd like to understand a little more about modifications that have to be made in my code.
I actually have an almost fully vectorized version of MC simulations and therefore I don't run any loop for i=1:10^6 loop.
How should I modify my code for the parallel computing to be efficient ? I guess – since MATLAB’s strength is to work vectorised – I must not introduce a “ parfor i=1:10^6 “ loop. I was thinking about splitting my computation, i.e. vectorising batches of 10^4 simulations (instead of a single 10^6) and then running a parfor loop 10^2 times. Would this method be ok or would it lead to poorer results (I know it's hard to guess without trying, which is something I haven't done yet, but I need a guess to know if I'm going wrong way) ? What could be an efficient solution ?
FYI, I'm running simulations on a test computer, 4 cores, utilization at around 75% of each core when running.
  3 个评论
cedric W
cedric W 2018-9-25
No. At least, not on my test machine. I don't know yet if I'll have one. Does it change a lot?
KSSV
KSSV 2018-9-25
Yes..it will if you have one deserving..read about gpuDevice, gpuArrays etc.

请先登录,再进行评论。

采纳的回答

Joss Knight
Joss Knight 2018-9-30
You seem to have the right idea. For highly vectorized code, parallelization should be done in batches. However, it does depend on what you are doing as to whether you will gain anything using a parallel pool. Many matrix operations in MATLAB are already heavily multi-threaded. Use the system tools to determine whether any of your CPU cores are idle and so available.
  12 个评论
cedric W
cedric W 2018-10-11
编辑:cedric W 2018-10-11
This setup, from what I understood, is going to generate the same simulations on each worker, and this is not the goal.
The aim is to have a run on a worker with twister' algo in example, and a parallel run with a different algo.
Do you agree this is not solving the issue ? Am I also limited to 3 possible algorithms on the GPU as stated here ? https://fr.mathworks.com/help/distcomp/control-random-number-streams.html
Joss Knight
Joss Knight 2018-10-11
No, it'll generate the same set of numbers in a particular iterate each time you run your code, which may be a different worker because of the way parfor scheduling works, but appears to be what you want.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Parallel Computing Toolbox 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by