VS RNG Usage ModelIntel® oneMKL RNG Usage Model
VS RNG Usage Model
Intel® oneMKL
RNG Usage Model
A typical algorithm for
random number generators is as follows:
VS
oneMKL
- Create and initialize stream/streams. FunctionsvslNewStream,vslNewStreamEx,vslCopyStream,vslCopyStreamState,vslLeapfrogStream,vslSkipAheadStream,vslSkipAheadStreamEx.
- Call one or more RNGs.
- Process the output.
- Delete the stream or streams with the functionvslDeleteStream.
You may reiterate steps 2-3. Random number streams may be generated for different threads.
The following example demonstrates generation of a random stream that is output of basic generator MT19937. The seed is equal to 777. The stream is used to generate 10,000 normally distributed random numbers in blocks of 1,000 random numbers with parameters
a
= 5 and
sigma
= 2. Delete the streams after completing the generation. The purpose of the example is to calculate the sample mean for normal distribution with the given parameters.
Example of VS RNG Usage
#include <stdio.h> #include "mkl_vsl.h" int main() { double r[1000]; /* buffer for random numbers */ double s; /* average */ VSLStreamStatePtr stream; int i, j; /* Initializing */ s = 0.0; vslNewStream( &stream, VSL_BRNG_MT19937, 777 ); /* Generating */ for ( i=0; i<10; i++ ) { vdRngGaussian( VSL_RNG_METHOD_GAUSSIAN_ICDF, stream, 1000, r, 5.0, 2.0 ); for ( j=0; j<1000; j++ ) { s += r[j]; } } s /= 10000.0; /* Deleting the stream */ vslDeleteStream( &stream ); /* Printing results */ printf( "Sample mean of normal distribution = %f\n", s ); return 0; }
Additionally, examples that demonstrate usage of VS random number generators are available in:
${MKL}/examples/vslc/source