[petsc-users] Speed of random generator
Barry Smith
bsmith at mcs.anl.gov
Sun Jun 19 13:43:14 CDT 2016
> On Jun 19, 2016, at 6:53 AM, Timothée Nicolas <timothee.nicolas at gmail.com> wrote:
>
> Hi all,
>
> I am trying to generate a lot of random numbers to use in a Fokker-Planck simulation. The particles receive random kicks from a normal distribution with a specified statistics. I have some issues here:
>
> - The manual says to NOT use PetscRandomCreate for Monte Carlo simulations because it wouldn't have the same statistics across processors. I assume it would in principle apply to my Fokker-Planck simulation described above too, right?
There are two issues here.
1) if you run in parallel each process has its own random number generator seed and sequence of random numbers (if you don't change the seed then the same random numbers may be generated on all processes, a very bad thing). There is no connection between the seed and the sequences on different processes so does one know that the required statistics between processes is correct?
2) we are not experts at random number generators, we provide PetscRandom for "simple minded" needs of random numbers.
Since proper random numbers are needed for your simulation we expect YOU, and not us, to be the experts on random numbers. What we provide for random numbers is likely not suited for your needs. You need to manage your random number processing using something other than what we provide. So find out what the Monte Carlo community does to satisfy their needs and do something similar.
Barry
Don't use PetscRandomRegister() just use some appropriate random number generator independent of PETSc.
>
> - If I want to generate the random numbers more carefully, it says I have to use PetscRandomRegister, and to check src/sys/random/impls/rand/rand.c for an example, but src/sys/random does not exist in my distribution (obtained with git). How do I find this?
>
> - There is a speed issue. On my computer, the generator
> is about 10 times slower than the method numpy.random.rand() of python. Is it expected ? This is alleviated by parallelization, but since I moved to FORTRAN from python in hope of accelerating my code, this is too bad. I consider moving to petsc4py, would it be a good choice?
We provide our own completely portable random number generator by default, this could be slower than system provided ones.
>
> Thanks in advance
>
> Timothee
More information about the petsc-users
mailing list