numpy performance and random numbers
sturlamolden
sturlamolden at yahoo.no
Sat Dec 19 16:58:37 EST 2009
On 19 Des, 21:26, Lie Ryan <lie.1... at gmail.com> wrote:
> you can just start two PRNG at two distinct states
No. You have to know for certain that the outputs don't overlap.
If you pick two random states (using any PRNG), you need error-
checking that states are always unique, i.e. that each PRNG never
reaches the starting state of the other(s). If I had to do this, I
would e.g. hash the state to a 32 bit integer. You can deal with
errors by jumping to a different state or simply aborting the
simulation. The problem is that the book-keeping will be costly
compared to the work involved in generating a single pseudorandom
deviate. So while we can construct a parallel PRNG this way, it will
likely run slower than one unique PRNG.
It has been suggested to use short-period MTs with different
characteristic polynomials. This is also available for the nVidia GPU
using CUDA. This is probably the generator I would pick if I wanted to
produce random numbers in parallel. However, here we should be aware
that the math has not been thoroughly proven.
http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/DC/dgene.pdf
http://developer.download.nvidia.com/compute/cuda/2_2/sdk/website/projects/MersenneTwister/doc/MersenneTwister.pdf
There is also a version of MT that use SIMD instructions internally,
which gives a factor-of-two speedup.
I would never use different algorithms. It will introduce a systematic
difference in the simulation.
More information about the Python-list
mailing list