[R-sig-hpc] R package with multi-threaded C
carnivorescience at gmail.com
Sat May 9 20:38:16 CEST 2015
I am trying to develop a R package that calls a multi-threaded C function and I am struggling on how to do this properly. The C program I originally wrote (prior to thinking about building it into a R package) uses Grand Central Dispatch library (for multi-threading on a Mac) and GSL (for RNG). Importantly, each thread has its own seed (the program runs Monte Carlo simulations).
Now that I am looking at modifying this to be included in a R package, I am not sure how to proceed with having a parallel and portable C code using the RNG seed from R. In the book R Programming for Bioinformatics by Gentleman (2008), it says p. 201:
"The decision to have these functions (GetRNGstate and SetRNGstate) manipulate a global variable, .Random.seed, is slightly unfortunate as it makes it somewhat more difficult to manage several different random number streams simultaneously."
Has anyone been able to do this or is there a package implementing something similar? I could always have the C code single-threaded but then simulations are going to be quite long so I am really keen on a multi-thread approach.
Guillaume Chapron, PhD
Grimsö Wildlife Research Station
Swedish University of Agricultural Sciences
SE - 73091 Riddarhyttan, Sweden
More information about the R-sig-hpc