# Introductory tutorial for Monte Carlo computations on the GPU?

Monte Carlo simulations for MATLAB sometimes require a huge usage of CPU and in some cases may take a long time. MATLAB has provided some structures in order to enable the parallel processing. But I have been intrested in using the processors of the graphical card (GPU)...

Is there any tutorial for using GPU in order to perform a parallel processing in MATLAB ?

• Is I know, matlab makes hard computing on GPU in case of its presence. Jun 26, 2013 at 5:42

See the MathWorks example Calculating the Mandelbrot Set on a GPU, which explains how you can use the Parallel Computing Toolbox to run simple "embarassingly parallel" jobs on GPUs.

Alternatively, you may be interested in the PyCUDA and PyOpenCL projects, which provide a similar capability to interactively launch GPU kernels.

Nvidia Cuda and AMD APP SDK's contain sample code which may help you get started. I've successfully carried out some work on this in the past, and the performance benefits were about 32x for a simple implementation.

Some of the references listed here may be beneficial, although this was written when GPGPU computing with OpenCL was still in its infancy. There are also some performance metrics compared to CPU.

For sheer speed in pseudo-random number generation you can take a look at the Mersenne Twister for GPU's (MTGP). This implementation exists solely in CUDA, but it may be an easier foray into the use of GPU's than via OpenCL. AMD's SDK Monte Carlo sample contains a variant of the algorithm, so you are not tied to using solely Cuda. It would be best to decide on your requirements first, then choose the most appropriate language to carry out your task.

You could consider using these in their own right, or connecting with MATLAB via the MEX file interface.

GPUs are the wrong approach for Monte Carlo methods if you want to use the standard Markov Chain approach. The reason is that Markov Chains are inherently sequential, whereas GPUs are only appropriate if you can parallelize an algorithm. It is very difficult to design parallel Markov Chain Monte Carlo (MCMC) methods.

• He didn't say Markov Chain Monte Carlo, he just said Monte Carlo. An example of Monte Carlo which is not Markov Chain is estimating the price of exotic options, by feeding in random numbers for changes in interest rates and so on over the next 6 months, and rinse and repeat ten thousand times. You can trivially parallelize this, since each sample of the resulting price is entirely independent of the other samples. Jun 27, 2013 at 8:12
• Right, that's why I had the qualification in my answer. Of course, random sampling from a known distribution is independent and can be done in parallel easily. Jun 27, 2013 at 13:50