[Rd] OpenMP and random number generation

Prof Brian Ripley ripley at stats.ox.ac.uk
Wed Feb 22 13:23:54 CET 2012

On 22/02/2012 08:23, Mathieu Ribatet wrote:
> Dear all,
> Now that R has OpenMP facilities,

Hmm, not exactly new.

> I'm trying to use it for my own package but I'm still wondering if it
is safe to use random number generation within a OpenMP block. I looked 
at the R writing extension document  both on the OpenMP and Random 
number generation but didn't find any information about that.
> Could someone tell me if it is safe or not please ?

Using threads in compiled code called from R (e.g. pthreads or OpenMP) 
is 'for experts only': we do not document which parts of R are or are 
not thread-safe except via making the sources available.  If you need to 
ask then it is not safe for you, and in particular it would be unsafe to 
call Get/PutRNGstate.

> Best,
> Mathieu
> -----------------------------------------------------------------
> I3M, UMR CNRS 5149
> Universite Montpellier II,
> 4 place Eugene Bataillon
> 34095 Montpellier cedex 5   France
> http://www.math.univ-montp2.fr/~ribatet
> Tel: + 33 (0)4 67 14 41 98

Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

More information about the R-devel mailing list