Visible to Intel only — GUID: GUID-50EFE620-4696-4249-86E9-93A6C94A199C
Visible to Intel only — GUID: GUID-50EFE620-4696-4249-86E9-93A6C94A199C
VS RNG Usage ModelIntel® oneMKL RNG Usage Model
A typical algorithm for VSoneMKL random number generators is as follows:
Create and initialize stream/streams. Functions vslNewStream, vslNewStreamEx, vslCopyStream, vslCopyStreamState, vslLeapfrogStream, vslSkipAheadStream, vslSkipAheadStreamEx.
Call one or more RNGs.
Process the output.
Delete the stream or streams with the function vslDeleteStream.
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 'mkl_vsl.f90' program MKL_VSL_GAUSSIAN USE MKL_VSL_TYPE USE MKL_VSL real(kind=8) r(1000) ! buffer for random numbers real(kind=8) s ! average real(kind=8) a, sigma ! parameters of normal distribution TYPE (VSL_STREAM_STATE) :: stream integer(kind=4) errcode integer(kind=4) i,j integer brng,method,seed,n n = 1000 s = 0.0 a = 5.0 sigma = 2.0 brng=VSL_BRNG_MT19937 method=VSL_RNG_METHOD_GAUSSIAN_ICDF seed=777 ! ***** Initializing ***** errcode=vslnewstream( stream, brng, seed ) ! ***** Generating ***** do i = 1,10 errcode=vdrnggaussian( method, stream, n, r, a, sigma ) do j = 1, 1000 s = s + r(j) end do end do s = s / 10000.0 ! ***** Deinitialize ***** errcode=vsldeletestream( stream ) ! ***** Printing results ***** print *,"Sample mean of normal distribution = ", s end
Additionally, examples that demonstrate usage of VS random number generators are available in:
${MKL}/examples/vslf/source