[Numpy-discussion] numpy random uniform seed?
Robert Kern
robert.kern at gmail.com
Tue Oct 29 13:14:06 EDT 2013
On Tue, Oct 29, 2013 at 5:02 PM, Ao Liu <frankliuao at gmail.com> wrote:
>
> Hi,
>
> I've been using np.random.uniform and mpi4py.
>
> I found that the random number each processor (or rank) generated are the
same, so I was wondering how random.uniform chose its seeds. Theoretically,
those ranks shouldn't have anything to do with others. The only possibility
that I can think of is that they all used the computer time as the seed, so
the random numbers were the same.
numpy.random grabs random bytes from /dev/urandom on UNIX-type systems and
the equivalent Crypto API on Windows. I suspect that MPI is forking the
main process after the global RandomState instance has already been
initialized, thus copying the state into each process.
You should not use the convenience aliases in numpy.random when doing any
kind of parallel programming. Instead, you should instantiate
numpy.random.RandomState() in each subprocess and call its methods. If you
really don't care about controlling the seed, then
numpy.random.RandomState() with no arguments should be sufficient. The OS
will take care of giving each of those instantiations unique states.
--
Robert Kern
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20131029/3fd14ecb/attachment.html>
More information about the NumPy-Discussion
mailing list