Saving and Restoring Random Streams
Typically, to get one more correct decimal digit in Monte Carlo, you need to
increase the sample by the factor of 100. That makes Monte Carlo applications
computationally expensive. Some of them take days or weeks while others may take
several months of computations. For such applications, saving intermediate results
to a file is essential to be able to continue computation using that result in case
the application is terminated intentionally or abnormally.
In the case of BRNGs, saving intermediate results means that BRNG state and other
descriptive data, if any, should be saved to a binary file. Since BRNG state is not
directly accessible for the user, who operates with the random stream descriptor
only, VS provides routines to save/restore random stream descriptive data to and
from binary files:
errstatus = vslSaveStreamF( stream, fname ) errstatus = vslLoadStreamF( &stream, fname )
The binary file name is specified by the
fname
parameter. In the vslSaveStreamF
function, a valid random stream to be written is
specified by a stream input parameter. In vslLoadStreamF
, the stream is the output parameter that specifies
a random stream that has been created on the basis of the binary file data. Each of
these functions returns the error status of the operation. A non-negative value
indicates an error.In addition to saving and restoring random stream descriptive data to and from
binary files, VS provides the routines to save and restore the stream descriptive
data to and from memory:
errstatus = vslSaveStreamM( stream, memptr ); errstatus = vslLoadStreamM( &stream, memptr );
Memory buffer is specified by the
memptr
pointer. To compute size of memory sufficient to hold
random stream descriptive data, use VS service routine:memsize = vslGetStreamSize( stream );
This routine returns the amount of memory in bytes necessary for random stream
descriptive data.
Non-deterministic random number generators support service functions for saving and
restoring random streams in a regular way. If you restore the state of the generator
using
LoadStreamF
or LoadStreamM
routines on the hardware that does
not support the corresponding non-deterministic source, the functions return an
error message.