In one sentence my question is how do I carry out MC simulations in parallel using parfor loop without introducing statistical dependecies?
Here are the details. I am using parfor loop to do a Monte Carlo simulation. Basically, I draw some samples from multivariate-Normal random variable and do something with these samples
The thing is that I want my N samples to be independent of each other. Samples seems to be statistically independent when I use 'for loop' instead of 'parfor loop', but the samples seem to be statistically dependent when I use parfor loop.
I have tried to address this problem by two methods
(1) generating random seeds before the parfor loop and then changing the state of random number generator in each loop as follows:
rng_seeds = randi(100000,n,1);
This addresses the problem to some extent but not completely as there is still some statistical dependecy visible in x series. I have attached the sereis of x below for N = 100.
(2) Generate N random samples out of pafor loop and computing x for ith sample in parfor loop as follows
This also has statistical dependecies as shown below.
When I use for loop, the following plot is obtained
Clearly, the series obtained by using for loop is qualitatively very different from the series obtained by using parfor loop.
So, my question is how do I carry out MC simulations in parallel using parfor loop without introducing statistical dependecies?
I have also tried the 'substream' solution now it again does not help. For and parfor loop are still giving different results. I tried the following code with for and parfor loop and the results are very different:
stream = RandStream('mrg32k3a');
Below is the plot for N = 1000. The red line is the one obtained by parfor and the blue line is obtained by for loop.