help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: sampling from two instances of a random number generator


From: David Bateman
Subject: Re: sampling from two instances of a random number generator
Date: Wed, 28 May 2008 01:25:03 +0200
User-agent: Thunderbird 2.0.0.12 (X11/20080306)

Leo Razoumov wrote:
> On 5/26/08, Søren Hauberg <address@hidden> wrote:
>> søn, 25 05 2008 kl. 20:12 -0400, skrev Leo Razoumov:
>>
>>> Two basic problems with this approach:
>>  > (1) Each time the whole RNG state is saved and copied. For Marsenne
>>  > Twister RNG used in Octave it is 625B. This slows things down.
>>
>> The approach will be somewhat slower, but are you claiming that 625 B of
>>  memory use is a problem in an Octave script?
> 
> I am claiming that each time you call myrand from your example 625B
> are copied from "static_state" to the global state followed by another
> 625B copied from global state back to "static_state". All-in-all 1250B
> of useless copying per each random number generated (assuming that I
> draw one number at a time). This will slow things down for sure.

Then cache a pool a random samples from each of the generators and use
that to reduce the number of switches of generator state. The only
question here is the tradeoff of memory use and performance.


> 
>>  > (2) Still there is only one global RNG state. In  a multi-threaded
>>  > environment it can cause serious problems if several threads are
>>  > trying to update the same state. Requires explicit and careful
>>  > synchronization, etc.
>>
>>
>> How is that relevant? Octave doesn't support threads...
>>
> 
> Octave interpreter does not. But Octave is also a library and can be
> linked to applications that are multi-threaded.

liboctave makes no claims to be thread safe either, and so there is no
guarantee that this will work either.

If you really feel that this is an issue, then take the code
liboctave/radmtzig.c, replace the static state variable with an pointer
to a set of states and then wrap this in an oct-file to get the behavior
you want, I'd estimate this at about 1 or 2 hours work if I was to do
it, and surely much less time than has been used discussing this.

However, I don't think its wise to change the behavior of octave to
allow multiple states, as this will certainly cause compatibility issues.

D.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]