Intel® oneAPI Math Kernel Library
Ask questions and share information with other developers who use Intel® Math Kernel Library.
6975 Discussions

## How to use vslSkipAheadStream and vsRngGaussian

Beginner
355 Views

Can I use vslSkipAheadStream together with an VSL_BRNG_MT19937 generator and vsRngGaussian?

I have written som small test program which creates one original stream and two skip ahead streams and compare the result. The first stream is identically to the original but the second is not-. Should I be able to do this or am I doing something wrong.

int seed = 12345;
int N = 100;
VSLStreamStatePtr original_stream;
float original_buffer;

vslNewStream(&original_stream, VSL_BRNG_MT19937, seed);

vsRngGaussian(
VSL_RNG_METHOD_GAUSSIAN_BOXMULLER,
original_stream,
N,
original_buffer,
0,
1.0f);

VSLStreamStatePtr streams[2];
int NS = 50;
float stream_buffer;

for (int i = 0;i < 2;i++) {
vslNewStream(&streams, VSL_BRNG_MT19937, seed);

vsRngGaussian(
VSL_RNG_METHOD_GAUSSIAN_BOXMULLER,
streams,
NS,
&stream_buffer[i * NS],
0,
1.0f);
}
for (int i = 0; i < N; i++) {
std::cout << i << " - " << original_buffer << " : " << stream_buffer << std::endl;
}

We want to ensure that our MC simulation always uses the same global set of random numbers independently of the number of threads we are using.

3 Replies
Employee
355 Views

Hi Patrik,

The Box-Muller method for generation of Gaussian random numbers requires 2 uniform variates, so 50 Gaussian numbers require 100 uniforms. In Intel MKL skip-ahead() routine advances over the state of the basic random number generator/sequence of uniform numbers produced by the basic random number generator, not over the sequence produced by the distribution generator. So, in your example please skip 100 uniforms for the second stream: vslSkipAheadStream(streams, i * NS*2 ) and let me know how it works on your side.

Thanks, Andrey

Beginner
355 Views

Hi Andrey,

Thank you very much it solved my problem. Could you please point me to where I can find the information.

Regards,

Patrik

Employee
355 Views

Hi Patrik,

Vector Statistics Notes available at https://software.intel.com/en-us/mkl-vsnotes describe Intel MKL random number generators and their properties, usage model, and testing results. In particular, please have a look at https://software.intel.com/en-us/node/590421 describing Box-Muller method of Gaussian RNG, and at https://software.intel.com/en-us/node/590367 describing support of the parallel Monte Carlo simulations with Intel MKL RNG. Additional information about Intel MKL RNG interfaces is available in Intel MKL Manual, Section Random Number Generators, https://software.intel.com/en-us/node/521842. In particular, skip-ahead details can be found at https://software.intel.com/en-us/node/521867#08C2BC85-AA07-4A5B-98B7-BAF6D02D2A08

Please, let me know, if you have more questions.

Thanks,

Andrey