2

Are there some other way to get the Gaussian distributed random numbers or are there any libraries for this today?

I have seen the question about Gaussian distributed random numbers in OpenCL

I want to generate many Gaussian distributed random numbers in OpenCL like above url question.

It may do that by two step:

http://cas.ee.ic.ac.uk/people/dt10/research/rngs-gpu-mwc64x.html#source_code it may generate many random uniform number instead of Gaussian distributed random numbers .

And then I can transform uniform random variants into normally distributed ones using https://en.wikipedia.org/wiki/Box%E2%80%93Muller_transform.

It may be time expensive,so are there some other way to get the Gaussian distributed random numbers(it is better using kernel to generate a array random number like cuda function:curandGenerateNormal(....)) or are there any libraries for this today?

pmdj
  • 22,018
  • 3
  • 52
  • 103
ice
  • 29
  • 4
  • Please take some time to read [the help pages](http://stackoverflow.com/help), especially the sections named ["What topics can I ask about here?"](http://stackoverflow.com/help/on-topic) and ["What types of questions should I avoid asking?"](http://stackoverflow.com/help/dont-ask). – Some programmer dude Aug 08 '19 at 09:13
  • @Someprogrammerdude,sorry ,i will do best next time. – ice Aug 08 '19 at 09:19
  • @Someprogrammerdude I think the question is valid, and if you don't think so, perhaps you could suggest ways of improving it. (I'll remove the c and c++ tags though, they're not really appropriate.) – pmdj Aug 08 '19 at 10:22
  • Explicitly asking for libraries or other external resources is off-topic. And this is not a free coding service, we are happy to help with existing code but we're not here to write code from scratch. – Some programmer dude Aug 08 '19 at 12:01
  • @Someprogrammerdude,sorry, some algorithm may not clear expressed by simple language . I mean that are there some other Gaussian distributed random function in other exist program (like https://github.com/ddemidov/vexcl), so I can analysis its algorithm for improve the normally distributed function.I think this question can help some people to know how to improve the efficiency for generating Gaussian distributed random number in opencl. – ice Aug 08 '19 at 12:27

1 Answers1

1

First, I don't think anyone can give you a definitive answer, we can only give you different options and you will need to run performance measurements for your particular use case yourself to find a solution that's optimal for your specific requirements.

Some suggestions:

  • The Box-Muller transform is certainly a decent way to generate gaussian-distributed values, but requires sin, cos, logarithm, and square root computations. You can remove the need for sine and cosine by switching to the Marsaglia polar method. This does come at the cost of requiring you to generate a larger quantity of uniformly distributed values. Depending on how your RNG performs on your GPU, this may still work to your advantage, however.
  • Be careful with linear congruencial RNGs (LCG), they exhibit patterns that sometimes interact badly with transformation algorithms such as Box-Muller. The one you linked is an MWC generator, which is a technique related to linear congruence, so might have similar issues. I would probably try exploring other generators. I haven't had a chance to try it myself yet, but there exists a Mersenne Twister variant for GPUs which I would imagine working well for many applications. One advantage of Mersenne Twister is that it mostly uses bitwise manipulation instructions, which tend to be very fast on GPUs, unlike integer multiplication and division.

There are definitely plenty of libraries out there, but I'll point out that for best performance you'll probably want to keep the random number generating code running in the same OpenCL work-item as the code that uses the samples. Writing out to a memory buffer will put a strain on memory bandwidth, although if your subsequent processing code is heavily ALU/FPU bound this might not matter.

As with any random number generation, testing is key - at the very least, plot a histogram of the samples your code generates and overlay it with the theoretical distribution function you're trying to obtain and visually inspect it to make sure it looks reasonable.

pmdj
  • 22,018
  • 3
  • 52
  • 103
  • thank you very much! now ,I am tring to plot a histogram for analysising the result of the combination of Box-Mulle and MWC . – ice Aug 08 '19 at 11:42