Parallel computing Monte Carlo

11 views (last 30 days)
cedric W
cedric W on 25 Sep 2018
Commented: Joss Knight on 11 Oct 2018
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 Comments
cedric W
cedric W on 25 Sep 2018
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 on 25 Sep 2018
Yes..it will if you have one deserving..read about gpuDevice, gpuArrays etc.

Sign in to comment.

Accepted Answer

Joss Knight
Joss Knight on 30 Sep 2018
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 Comments
cedric W
cedric W on 11 Oct 2018
Edited: cedric W on 11 Oct 2018
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 on 11 Oct 2018
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.

Sign in to comment.

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!