Dear all, Now that R has OpenMP facilities, 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 ? 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
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 itis 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
Hello, For your information, I plan to release "soon" a package with a fast and multithreaded aware RNG for C++ code in R packages. It is currently part of one of my (not yet accepted) packages and I want to extract it into its own package. I plan to do some quick benchmarks too. Of course I can not define exactly when it will be ready. Best, Karl On Wed, Feb 22, 2012 at 9:23 AM, Mathieu Ribatet < mathieu.ribatet@math.univ-montp2.fr> wrote:> Dear all, > > Now that R has OpenMP facilities, 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 ? > > 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 > > ______________________________________________ > R-devel@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel >[[alternative HTML version deleted]]
Hi.> Now that R has OpenMP facilities, 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.Package CORElearn (i am a coauthor) uses random number generation under OpenMP in C++. This requires to have a separate copy of the generator with its own memory for each thread. Do you want to use it in C or C++? Petr Savicky.