<html><body><div>It runs in parallel does not mean it works correctly.</div><div><br></div><div>Simply increase seed certainly not avoid overlapping. The best algorithm that use MT19937 in parallel environment without overlapping has a complexity O(log n) AFAIK.</div><div><br></div><div>Second, R's RNG has a single instance within the whole program, which means your program does not work as you thought. There are obvious race conditions in your approach.</div><div><br></div><div>I suggest you google a little bit of how RNG really works before purse how to generate them in parallel. For example section 6 of the R's parallel package's document.</div><div><br></div><div>Best,</div><div><br></div><div>Yan Zhou</div><div><br>On Feb 14, 2013, at 09:40 PM, Simon Zehnder <szehnder@uni-bonn.de> wrote:<br><br></div><div><blockquote type="cite"><div class="msg-quote"><div class="_stretch">Well, in OpenMP it seems to work, if I use inside the #pragma parallel for:<br> <br> Rcpp::Environment base("package:base");<br> Rcpp::Function SetSeed = base["set.seed"];<br> SetSeed(1 + i * nobs_intern * 3);<br> <br> I used OMP_NUMTHREADS = 4 and 8 iterations. <br> <br> Best Simon<br> <br> On Feb 14, 2013, at 10:10 PM, Simon Zehnder <<a href="mailto:szehnder@uni-bonn.de" onclick="return false;">szehnder@uni-bonn.de</a>> wrote:<br> <br> > I made all my simple tests now by using Rcpp::Environment and then Rcpp::Function for "set.seed" when calling R::rnorm. The next step would be to parallelize the iterations via OpenMP. The suggestion of Yan makes quite sense to produce a RNG via std::mt19937. This is also the way I did it when I used Scythe Statistical Library. <br> > As I use now the R RNG it should be able to use it in parallel, if Rcpp::Function is a kind of wrapper which contains the code of "set.seed". But I would rather guess, that it is a call object, that just calls the R function "set.seed" in R, which then would not be threadsafe (as also the RNG would then just be called when using R::rnorm).....<br> > <br> > So I guess falling back to std::mt19937 is not a bad idea. For no overlapping I just increase the seed in every iteration dependent on the iteration and the number of random numbers to generate. <br> > <br> > Best Simon<br> > <br> > <br> > <br> > <br> > On Feb 11, 2013, at 2:16 PM, Chris Jefferson <<a href="mailto:chris@bubblescope.net" onclick="return false;">chris@bubblescope.net</a>> wrote:<br> > <br> >> On 11/02/13 10:23, c s wrote:<br> >>> On Sun, Feb 10, 2013 at 12:32 AM, Yan Zhou <<a href="mailto:zhouyan@me.com" onclick="return false;">zhouyan@me.com</a>> wrote:<br> >>>> To have Armadillo randn use MT19937 is not easy.<br> >>>> Since it use srand() for seed, I guess it also use C rand(),<br> >>>> whose quality is quite questionable.<br> >>> The quality of the rand() function from C depends on the<br> >>> implementation in libc, which varies from system to system.<br> >>> <br> >>> While I'd like to incorporate a Mersenne-Twister random number<br> >>> generator directly in Armadillo, it would either add a dependency on<br> >>> Boost, or on C++11. Boost might not be available on a user's system,<br> >>> and the degree of support for C++11 features varies from compiler to<br> >>> compiler. We also have to bear in mind that R folks currently<br> >>> disallow CRAN packages that use C++11.<br> >> <br> >> If you just want a mersenne-twister random number generator, I will extract it from boost (which is under a fairly free licence).<br> >> <br> >> Chris<br> >> _______________________________________________<br> >> Rcpp-devel mailing list<br> >> <a href="mailto:Rcpp-devel@lists.r-forge.r-project.org" onclick="return false;">Rcpp-devel@lists.r-forge.r-project.org</a><br> >> <a href="https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel">https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel</a><br> > <br> > _______________________________________________<br> > Rcpp-devel mailing list<br> > <a href="mailto:Rcpp-devel@lists.r-forge.r-project.org" onclick="return false;">Rcpp-devel@lists.r-forge.r-project.org</a><br> > <a href="https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel">https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel</a><br> <br> _______________________________________________<br> Rcpp-devel mailing list<br> <a href="mailto:Rcpp-devel@lists.r-forge.r-project.org" onclick="return false;">Rcpp-devel@lists.r-forge.r-project.org</a><br> <a href="https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel">https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel</a><br></div></div></blockquote></div></body></html>