[R-pkg-devel] Multi-threaded C with R's RNG

Dirk Eddelbuettel edd at debian.org
Fri Nov 27 20:20:01 CET 2015

On 27 November 2015 at 19:48, Guillaume Chapron wrote:
| Has anyone written a package with a C code that uses R's RNG but in a multi-threaded way (e.g. to parallelize Monte Carlo simulations)? I do not have the knowledge to figure out myself how to solved this and would need to see an example.

To the best of my knowledge you cannot do thatas the RNG writes state back,
so you would have interaction between multiple threads and R itself --- which
is almost surely going to end in tears.

Multithreading is fine with proper mutexes, and/or via OpenMP, but keep your
data in non-R data structures and stau away from R while you multithread.


http://dirk.eddelbuettel.com | @eddelbuettel | edd at debian.org

More information about the R-package-devel mailing list