random number generation

What are the current best practices for threadsafe, on-the-fly random number generation in OpenACC kernels?


Hi Ron,

Unfortunately OpenACC does not define a way to call a random number generator from an individual compute region. We’re working on adding a the ability to call a cuRand device function but this wont be available for a few months and would be target specific.

The portable way to do this is to pre-compute a vector of random numbers then use them in the compute region. This can be done using a host side RNG or on the device using a parallel RNG like Mercenne Twister. This article is a bit old and uses the PGI Accelerator Model instead of OpenACC, but may be useful if you need an example algorithm.

Best Regards,

Thanks, Mat.

For our apps, we’re currently pre-computing random numbers on the host, and it’s working well; we don’t require so many random numbers that the device memory is exceeded.

Some of our larger applications could require over 1.5e9 random numbers (over 12 GB of doubles) over the course of the simulation, and we will probably consider using cuRand. We mostly run on NVIDIA GPUs, anyway.

A target-agnostic solution would be really interesting, if it is ever introduced.