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

Matteo Fasiolo matteo.fasiolo at gmail.com
Mon Apr 28 01:30:24 CEST 2014


Dear Rcpp developers,

 I am working on a small package (here <https://github.com/mfasiolo/mvn>)
that should provide efficient tools
for the multivariate normal distribution using Rcpp/RcppArmadillo and
OpenMP.

Creating functions that evaluate the multivariate normal density efficiently
was fairly straightforward, but I am struggling with parallel random number
generation with OpenMP.

As I understand, doing things such as:

NumericMatrix out(n, d);
#pragma omp for schedule(static)
for(int kk = 0; kk < d; kk++) out( _, kk) = rnorm(n);

is not going to work, because rnorm() is not thread safe
(in fact this code crashed R). On the other hand R level parallelism
using clusterApply, mclapply etc appears to be too slow to be of any
use for this purpose.

Is anybody aware of any package providing a parallel C++ rng which my
package might link to? I have read this
post<http://www.lindonslog.com/programming/parallel-random-number-generation-trng/>
about
Tina's rng, which
seems to work with OpenMP and Rcpp. How hard would it be to have
such a library included in my package (if at all possible)?

Sorry for the possibly silly questions and thanks for any suggestion.

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


More information about the Rcpp-devel mailing list