numpy random uniform seed?
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. Anyone has more ideas and suggestions on how to correct this? Thanks, Best, Ao -- I am Ao.Liu, always hungry and still waiting for what I've always been believing. To know me more, please visit my little tiny personal website: www.frankliuao.com
On Tue, Oct 29, 2013 at 5:02 PM, Ao Liu <frankliuao@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
participants (2)
-
Ao Liu
-
Robert Kern