openmm / openmm

OpenMM is a toolkit for molecular simulation using high performance GPU code.
1.47k stars 511 forks source link

Improved random number generator #3716

Open peastman opened 2 years ago

peastman commented 2 years ago

Currently we use two random number generators: Mersenne Twister for Reference and CPU platforms, and KISS for CUDA and OpenCL. Those are fine generators, but they're no longer state of the art. We should consider moving to something better. I suggest PCG64 DXSM, which is an improved version of the PCG64 algorithm that Numpy uses as its default generator. It has better statistical properties than either of the above two, and is much faster than MT.

Here's a paper describing the theory behind PCG generators: https://www.cs.hmc.edu/tr/hmc-cs-2014-0905.pdf

Here's a reference implementation: https://github.com/imneme/pcg-cpp

jaketanderson commented 2 years ago

My C++ is awful so I can't help implement this, but out of curiosity: how big of an effect does the speed of rng have on the speed of simulation? Since this is a proposed change I assume it's a non-negligible difference...

peastman commented 2 years ago

It's not likely to make a big difference. Generating random numbers currently accounts for less than 1% of the time in typical cases. This is more just a matter of keeping up with the best available algorithms as a point of principle.

jchodera commented 1 year ago

Dave Cerutti mentioned this really nice set of random number generators with pleasant properties for GPUs: xoshiro

RaulPPelaez commented 1 year ago

I have always used Saru for GPU rng (https://uammd.readthedocs.io/en/latest/RandomNumbers.html), it is described in this article: https://doi.org/10.1016/j.cpc.2012.12.003 It has a state of just two 32 bit integers and is fast to seed and advance. It also passes every major random test battery. It is the generator used in HOOMD (https://doi.org/10.1016/j.jcp.2011.05.021) .