title: Monte Carlo Optimization with CUDA
body: <p>I am dealing with some slowness issues regarding my Monte Carlo simulation that I have developed in CUDA. I have observed very poor performances with my GTX 680 (compute capability 3.0) and I don’t know what is wrong in my way of implementing a Monte Carlo simulation. I tried to ‘unroll’ my loop by doing several paths within my main loop without observing any significant improvements.</p>
  
  <p>I have defined my kernel as following:
         SimulationVolInterp = parallel.gpu.CUDAKernel('sh_cuda_MC.ptx', 'sh_cuda_MC.cu', 'MCSharedMemory'); 
       SimulationVolInterp.ThreadBlockSize = 2^9;
       SimulationVolInterp.GridSize = 2^5;</p>
  
  <p>Here is my kernel function :</p>
  
  <pre><code>__global__ void MC(double* vol_int, double* matrice,const double* randomWalk, int nbreSimulation, int nPaths, double S0, double strike, double T, double drift,  const double* strikes_vec, const double* volatility_mat, int l_strikes_vec) {
  
      //double mydt = (index - nbreSimulation)/nbreSimulation*dt + dt;
      double dt = T/nPaths;
      unsigned int tid = threadIdx.x + blockDim.x * blockIdx.x; 
     // unsigned int stride = blockDim.x*gridDim.x;
      unsigned int index = tid;   
      int workingCol = 0; 
      unsigned int previousMove;  
      if (index &lt; nbreSimulation) {
          matrice[index] = S0;  
          for (workingCol=1; workingCol&lt; nPaths; workingCol++) {
              previousMove = index; 
              index += nbreSimulation;
              vol_int[index] = 0.25;
              matrice[index] = matrice[previousMove]*exp((drift - vol_int[index] *vol_int[index] *0.5)*dt + randomWalk[index]*vol_int[index] *sqrt(dt));
          }
     }
  }    
  </code></pre>
  
  <p>For example,  2^12 simulations x 2^11 steps takes 7 sec, it is quite huge right?!
  My classic Monte Carlo on Matlab takes less than one sec… </p>
  
  <p>Could someone help me on this point?</p>
  
  <p>Many thanks</p>