Hi,
I have a program that is called several times as part of a simulation. When the simulation begins, the program is called from a script with parameterINITIAL_SEED (and other parameters). My program initializes a stream with that seed:
vslNewStream( &my_vsl_stream,VSL_BRNG_MT19937, INITIAL_SEED);
Thenproduces some results involving random numbers, writes results to disk, and ends.
The next time is called, I want it to start generating numbers from the point the stream was left during the previous execution, let's call it NEXT_SEED:
vslNewStream( &my_vsl_stream,VSL_BRNG_MT19937, NEXT_SEED);
How can I get that number before finishing execution so that it can be written to a file, and then passed by the script the next time and be used as the seed of the generator?
I found a functionGetStreamStateBrng but it doesn't seem to do what I want, or maybe it does. Any clue about it?
Thanks in advance
Link Copied
Hello,
You might want tocheckservice RNG functionalityfor saving/restoring random stream descriptive data to/from file
vslSaveStreamF( stream, fname );
vslLoadStreamF( &stream, fname );
Its description is available inRandom Number Generators\Service Routines Section, which isinStatistical Functions Chapter of MKL Manual.
Please, let me know if this answers your question.
Best,
Andrey
OK, it seems to be working.
I'm included a sample program to test this. It first initializes a stream with SEED = 10, and produces 5 numbers and saves the info of the stream. Then initializes a second stream with that info. Then it generates another 5 numbers which are different from the initial 5. Finally, it initializes a third stream with the same SEED=10 but generates 10 numbers. The first 5 are the same as the 5 generated with the first stream, while the remaining 5 are the same as the ones generated with the second stream.
Thus, it's working as expected
#include#include #include "mkl_vsl.h" #include "errcheck.inc" // this is included somewhere in the MKL's examples directory #define SEED 10 #define BRNG VSL_BRNG_MT19937 #define METHOD 0 #define N 5*2 double r ; int main() { VSLStreamStatePtr stream1, stream2, stream3; int i, errcode; //////////////////////////////////// errcode = vslNewStream( &stream1, BRNG, SEED ); CheckVslError( errcode ); errcode = vdRngUniform( METHOD, stream1, (N / 2), r, 0.0, 1.0 ); CheckVslError( errcode ); std::copy (r, r + (N / 2), std::ostream_iterator (std::cout, "\t")); std::cout << std::endl; errcode = vslSaveStreamF( stream1, "C:\\temp\\somefile.bin" ); CheckVslError( errcode ); errcode = vslDeleteStream( &stream1 ); CheckVslError( errcode ); //////////////////////////////////// errcode = vslLoadStreamF( &stream2, "C:\\temp\\somefile.bin" ); CheckVslError( errcode ); errcode = vdRngUniform( METHOD, stream2, (N / 2), r, 0.0, 1.0 ); CheckVslError( errcode ); std::copy (r, r + (N / 2), std::ostream_iterator (std::cout, "\t")); std::cout << std::endl; errcode = vslDeleteStream( &stream2 ); CheckVslError( errcode ); //////////////////////////////////// errcode = vslNewStream( &stream3, BRNG, SEED ); CheckVslError( errcode ); errcode = vdRngUniform( METHOD, stream3, N, r, 0.0, 1.0 ); CheckVslError( errcode ); std::copy (r, r + N, std::ostream_iterator (std::cout, "\t")); std::cout << std::endl; errcode = vslDeleteStream( &stream3 ); CheckVslError( errcode ); //////////////////////////////////// return 0; }
For more complete information about compiler optimizations, see our Optimization Notice.