1
votes

In a single for loop, I use a single random seed to generate all the "random numbers". They are very random as I take one from the stream at a time, without any gap.

However, in parfor, each worker uses a different random seed, therefore, the numbers obtained may have interference with each other. Therefore, they are not really random as they do not come from a single seed.

Also, for my case, I do not know how many random numbers each worker needs beforehand. How can I solve this problem?

1
Whoa. this one is going to be hard. What I'd do: Make all workers use the same seed, but use different numbers on a big array the create. Imagine they need just 1 each, then make all the e.g. 80 workers create 80 random numbers each and use just one. Or pass a sliced variable to the workers with random numbers. Yes, both methods have limitations, but you are dealing with a problem that it can be unsolvableAnder Biguri
Look up distributed-seeding. There are many ways. Use MT with different configurations (there are something like ~600); there is an extra paper (with strong arguments about non-interference) for this (and customized code). Use a PRNG with jumping capabilities (e.g. jump by 2^40 samples). Leap-frogging and many more.sascha
@Ander Biguri Thanks. but each worker does not only use 1 random number. I do not know how many random numbers each worker needs beforehand.Ka-Wa Yip
@sascha do u mean by using MT different configurations on each worker, the random numbers of one worker do not have interference with those of another?Ka-Wa Yip

1 Answers

0
votes

In parfor, the workers use different streams from a random number generator that is specifically designed to be used in parallel. Therefore, you can rely on the random numbers generated inside parfor having reasonable statistical qualities. More here: http://www.mathworks.com/help/distcomp/control-random-number-streams.html