[R] random numbers
Ross Boylan
ross at biostat.ucsf.edu
Sat Jun 30 22:09:39 CEST 2007
On Sat, 2007-06-30 at 14:50 -0500, Dirk Eddelbuettel wrote:
> On 30 June 2007 at 12:12, Ross Boylan wrote:
> | I call C++ code from R to generate simulated data. I'm doing this on a
> | cluster, and use rmpi and rsprng. While rsprng randomizes R-level
> | random numbers (e.g., from runif), it has no effect on the C code, which
> | is completely SPRNG and MPI ignorant.
> |
> | Currently I generate a seed to pass into the C code, using
> | as.integer(runif(1, max=.Machine$integer.max)-.Machine$integer.max/2)
> | It seems to work.
> |
> | Any comments on this approach? Here are some issues I see:
>
> I may be missing something but given that rsprng is running on your cluster,
> you are bound to also have sprng itself -- so why don't you use that from C
> or C++ for this purpose?
>
> Hth, Dirk
Doing so would add considerable complexity, at least as far as I know.
Sometimes I run within an MPI session and sometimes not. My
understanding is that SPRNG will not work if MPI is absent. I think
someone on the SPRNG list told me that there wasn't a good way to handle
this at run-time. Unfortunately, a lot of SPRNG options seem to be
compile-time settings.
Using SPRNG would also complicate my build process, as I'd need autoconf
magic to support it.
Part of the issue is that I want something I can redistribute, not just
something that will work for me on a one-off basis.
One simple solution would be to build several versions of the library.
A not so simple solution would be to build various random number
generators as separate libraries, and dynamically load the appropriate
one.
More information about the R-help
mailing list