Random number generation and parallelization c++/Qt

Go To StackoverFlow.com

2

I am wondering whether this could be worse parallelizing generation of random numbers. I am using Qt and QtConcurrent here. Is it worth using parallelization instead of generating N number in a row? Which could be critical number of generated numbers? My code is here, non parallelized:

double** sampled = Matrix::allocMatrice(n,m_ndim,true);

Random* generator_ = new Random();
generator_->newSeed();

double* temp_;

for(int k=0;k<n;k++)
{
    for(int j=0;j<m_ndim;j++)
    {
        sampled[k][j] = generator_->run(lower[j],upper[j]); 
    }
}

whre Random is a home made random generator following Marsaglia generation method.

Thanks and regards.

2012-04-04 08:01
by octoback


3

If you want true parallel random number generation, you're almost definitely out of luck. I am aware of no true multithreaded algorithm to generate several random numbers using different threads under the hood efficiently and deterministically.

What I did before and suggest you do now, is set up N different generators (with N different seeds, obviously), and spread the generation over N threads manually. The result will be reproducible, and highly multithreaded.

2012-04-04 08:35
by rubenvb
Ads