Skip to content
Prev 7507 / 10988 Next

[Rcpp-devel] Parallel random numbers using Rcpp and OpenMP

Hi all,

 many thanks for your detailed replies, I see that there are many options
out there.

As a first step I think I will try out the C++11 option that Matt
suggested, as it seems
relatively simple. In particular I might do something like:

#pragma omp parallel
    {
    std::mt19937_64 engine(
static_cast<uint64_t>(seeds[omp_get_thread_num()] ) );
    std::uniform_real_distribution<double> zeroToOne(0.0, 1.0);

    #pragma omp for
        for (int i = 0; i < 1000; i++) {
            double a = zeroToOne(engine);
        }
    }

were seeds is a NumericVector coming from R. That's probably not ideal, but
it might
give reasonable and reproducible results.

Thanks,

Matteo
On Mon, Apr 28, 2014 at 9:39 AM, Matt D. <matdzb at gmail.com> wrote:

            
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20140428/ea6298f3/attachment.html>