Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

True Random number

Bruce_Weaver
Beginner
959 Views

Hi,

 

How do I access RDRAND from Fortran?  Will it work on Zen processors as well as Intel?

Thanks,

Bruce

Labels (1)
0 Kudos
1 Solution
Gennady_F_Intel
Moderator
889 Views

Yes, you could access to this true generates from Fortran API of MKL.

First check (lspu | grep rdrand) if thins instruction available on this particular system.


Look at the MKL Developer Reference follow this link: https://www.intel.com/content/www/us/en/develop/documentation/onemkl-developer-reference-c/top/statistical-functions/random-number-generators/basic-generators.html where listed all mkl’s basic generators and rdrand as well.

Unfortunately, MKL doesn’t provide an RNG examples show how to make the call for this particular Basic generators, but the calling pipeline would very similar with C code:

 

#define SEED   VSL_BRNG_RDRAND

#define BRNG   VSL_BRNG_NONDETERM

 

//Create and Initialize stream:

VSLStreamStatePtr stream;

//Initialize stream

vslNewStream( &stream, BRNG, SEED );

//generate RNG

vsRngUniform( VSL_RNG_METHOD_UNIFORM_STD, stream, N_GEN_VALS, r, a, b ) // see reference for more details…


-Gennady


View solution in original post

0 Kudos
7 Replies
andrew_4619
Honored Contributor II
931 Views

MKL has that I think. I also believe it  is the  VS C++ libraries so you you write and interface and wrapper function.

0 Kudos
mecej4
Honored Contributor III
922 Views

RDRAND and RDSEED are available on most X86/X64 processors, including Zen. They can be useful during seed generation, and in crypto- applications.

However, a good RNG in the compiler RTL can be an order of magnitude faster, so there is little motivation for using RDRAND instead of an RNG in, say, Monte-Carlo simulations.

0 Kudos
Gennady_F_Intel
Moderator
890 Views

Yes, you could access to this true generates from Fortran API of MKL.

First check (lspu | grep rdrand) if thins instruction available on this particular system.


Look at the MKL Developer Reference follow this link: https://www.intel.com/content/www/us/en/develop/documentation/onemkl-developer-reference-c/top/statistical-functions/random-number-generators/basic-generators.html where listed all mkl’s basic generators and rdrand as well.

Unfortunately, MKL doesn’t provide an RNG examples show how to make the call for this particular Basic generators, but the calling pipeline would very similar with C code:

 

#define SEED   VSL_BRNG_RDRAND

#define BRNG   VSL_BRNG_NONDETERM

 

//Create and Initialize stream:

VSLStreamStatePtr stream;

//Initialize stream

vslNewStream( &stream, BRNG, SEED );

//generate RNG

vsRngUniform( VSL_RNG_METHOD_UNIFORM_STD, stream, N_GEN_VALS, r, a, b ) // see reference for more details…


-Gennady


0 Kudos
Gennady_F_Intel
Moderator
845 Views

We have not heard back from you. This is to kindly inform you that this thread will no longer be monitored by Intel. If you need further assistance, please post a new question.


0 Kudos
Bruce_Weaver
Beginner
841 Views

Thanks all.  Especially Gennady; I hope to try that out this weekend.  I use an inordinate number of random numbers: 90 threads running for a couple weeks using about 3e6 random numbers/20 minutes each.  I'm starting to be concerned about the twister so I want to compare the results with true random numbers.  Hopefully, it will show that the Twister is good enough for what I'm trying to do.  If not, I'll have to figure out how to get around the time issue.

0 Kudos
jimdempseyatthecove
Honored Contributor III
821 Views

Bruce,

>>I use an inordinate number of random numbers: 90 threads running for a couple weeks using about 3e6 random numbers/20 minutes each.

Are you aware that the referenced random number generators can produce a harvest of random numbers in one call as opposed to a single random number per call?

Some of the RNGs are independent per thread and do not internally use a critical section while other RNGs internally use a critical section per call. By electing an RNG that uses a critical section, then in a multi-threaded application you can reduce the logjam at the critical section through the use of harvesting many random numbers for subsequent use by the calling thread.

 

Jim Dempsey

 

0 Kudos
Bruce_Weaver
Beginner
807 Views

Hi Jim,

 

I do call a whole bucket full of random numbers at a time.  I seed my threads independently & they each have their own (identical) random number calling routine.

 

thanks

0 Kudos
Reply