sobol generator extension in mkl

sobol generator extension in mkl

I am trying to utilize the recently published new initial direction vectors and polynomials with mkl and have had problems for a while now.
Unlike the mkl rng's this one needs the sample size when specifying the initial vector for the first dimension.
So I chose to override the first dimension. As a simple test, I try to look into the correlation of 2 (0 based) dimensions.
My understanding is that the samples obtained from mkl are ordered by dimension (i.e, first all the dimensions of the first point, then all of the second etc). Is this correct?
This is a code snippet. The inputs are the file where the info resides and the dimensions whose correlation we are seeking.
I did not know what to use for the degree of the first polynomial, but both choices, 1 and 2 ( i.e. 1 and x )give the same results. Is it ignored? (apologies for the naiveness, it has been really a long time since I looked at sobol generation and nowdays I only use these things).
The webste with the numbers is
Thank you very much for your help.

Downloadtext/x-c++src main.cpp7.72 KB
Downloadtext/plain fkuo_direction_numbers.txt1.82 MB
8 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

Hello Petros,

It looks I missed your questions in the flow of the posts published on Intel MKL web forum. Let's return to your questions.

1. Intel MKL version of SOBOL QRNG returns array of quasi-random variates. In this array the first quasi-random vector comes first, the second vector comes second, etc. The elements ofeach quasi-random vectorfollow the natural order: first coordinate comes first, second coordinate comes second, etc.
For example, let us assume thatSOBOL QRNG is initialized withdimension equal to 2:

errcode = vslNewStream( &stream, VSL_BRNG_SOBOL, 2);

If we want to generate 6 double precision uniformly distributed quasi-random numbers (that is, 3 vectors of 2 elements each) we call Uniform generator:

errcode = vdRngUniform( VSL_RNG_METHOD_UNIFORM_STD, stream, 6, r, 0.0,1.0 );

Upon successfull completion of the generation
r[0] and r[1] will contain first and secondcomponents of 1st quasi-random vector,
r[2] and r[3] will containfirst and second componentsof 2nd quasi-random vector,
r[4] and r[5] will containfirst and second components of 3dquasi-random vector

2. To answer your second question let me review your code first.
Meanwhile, I have the quick question for you: what are the reasons to override initialization of the 1st dimension and not to use the default one?


Hello Petros,
I had a look at the code you have provided and has a few comments:

1. Initialization of the Intel MKL version of SOBOL QRNG with user-defined polynomials and initial direction numbers looks good with slight correction mentioned in the item 2 below.

2. If you do not override the 1st dimension with your parameters the library will set initial direction numbers to 1. Generally, you do not need to override theinitialization for the first dimension if only you do not have any special requirements forthis. If you need to overridethe initialization for the first dimension you might want to provide the polynomial and initial direction numbers for this dimension; number of initial direction numbers should be equal tomaxDegree like inother dimensions.

3.You would need to take into accountthe specific pack format of the quasi-random numbers (described in my other post)in your procedure for computation of correlation between dimensions and properlydetermine the position of the next samples (the shiftshould be equalto dimension instead of its increment):

pcolI += dimension;
pcolJ += dimension;

Hope, this helps.
Please, let me know if you have more questionson the initialization of Intel MKL SOBOLQRNG with user-defined parametersor other questions onStatistical Component of MKL.


Thank you very much for coming back to me.
Just stumbled upon your response , for the first time now, will look into it tomorrow and get back to you.

Hi Andrey,
I think you hit the nail on the head.
When I was initializing the pointers to iterate through the column points I was not taking into account the fortran storage type for the matrix used to store the mkl call output.
Itseems thatI do not need to redefine the first dimension.
As far as the packing convention goes, I think that it goes like this:
when I try to fill uniformly an N dimensional space I generate MCsize points each one having N coordinates, which are written by mkl sequencially to the provided buffer.
If this is correct, then I think my issue is resolved.
Thank you very much for all your help,

Hi Petros,
Yes, your understanding is correct. Great to know the issue is resolved.
Please, feel free to ask any questions on Statistical Component of Intel MKL including Random Number Generators and Summary Stats algorithms, and we will be happy to help.

Hi Petros,

Do you have a working version of your source code that you could send me?  I would like to see how you managed to initialise the Sobol stream with Joe-Kou initial direction numbers and primitive polynomials.  Did you have to supply the first dimension numbers? or did you use the default first dimension inside MKL?  The code that you have above seems to override the first dimension, but in your comments above you said that it is not necessary to do this.  Thank you in advance for your help.  


Faramarz.  I can be contacted directly at

Hello Faramarz,

I attach the sample which shows how to initialize Intel(R) MKL Sobol QRNG with Joe-Kuo initial direction numbers and primitive polynomials. The first dimension isn't overrided in the code. The example uses the data file "soboluserdirnums-joe-kuo_1.dat" which was taken from (, and re-formatted to simplify reading data from it.

We are planning to add RNG example illustrating how to initialize Sobol stream with the table of Joe-Kuo direction numbers into one of the future MKL releases.




Downloadapplication/zip soboluserdirnums-joe-kuo-1.zip792.66 KB

Leave a Comment

Please sign in to add a comment. Not a member? Join today