PROFASI  Version 1.5
Public Member Functions | List of all members
prf::MersenneTwister Class Reference

MersenneTwister is the default random number generator for profasi. More...

#include <MersenneTwister.hh>

Inheritance diagram for prf::MersenneTwister:
Inheritance graph
[legend]

Public Member Functions

double shoot ()
 Generates a random number distributed uniformly between 0 and 1.
 
void ResetDefaultState (long seedd)
 Initialize with a given seed.
 
void saveState (std::string sttfile)
 Save complete state for faster recovery.
 
int recoverState (std::string sttfile)
 Recover complete state from file.
 
- Public Member Functions inherited from prf::RandomNumberBase
int createSeed (int inpseed)
 Generate a seed from process id, time ...
 
double shoot (double a, double b)
 As above, but between a and b.
 
double shoot (double width)
 Between 0 and width.
 
int shootBit ()
 Create a random bit, 0 or 1 with equal probabilities.
 
virtual void WriteTo (FILE *cnfil)
 Write to a file.
 
virtual void ReadFrom (FILE *cnfil)
 Read in the state of the generator from a file.
 
virtual void WriteTo_text (FILE *cnfil)
 Write to a file in text form.
 
virtual void ReadFrom_text (FILE *cnfil)
 Read in the state of the generator from a file in text form.
 
virtual void RandomizeState (int irnk=0)
 Randomize State based on a given "rank".
 
virtual void retrace (std::string sttfile="")
 Retrace history.
 
void set_seed_and_ncalls (long sd, unsigned long ncl)
 Set seed and num_calls (to later call retrace)
 
unsigned long num_calls ()
 Retrieve number of calls.
 
virtual void setSeed (long i)
 Sets seed and Initializes with it.
 
long Seed () const
 Returns the seed.
 

Detailed Description

MersenneTwister inherits from RandomNumberBase. The code here is a simple adaptation of the code found in GSL: The GNU Scientific Library. Essentially the same working code made into a C++ class suitable for use with PROFASI. One slightl change however is that we do not allow the random number to be strictly zero.

Member Function Documentation

int MersenneTwister::recoverState ( std::string  sttfile)
virtual

Check if the given file has a state stored by a random number generator object with the same name. Check if the original seed written in the file matches with what is already stored. Check if the saved state in the file is in the past relative to the number of calls. If all checks pass, read in the state from the file, and if necessary, retrace the remaining number of random number generations to fast forward the ncalls to the required number.

Reimplemented from prf::RandomNumberBase.

void MersenneTwister::saveState ( std::string  sttfile)
virtual

As runs get longer and longer, one can not afford to lose the first 15 minutes to restoring the random number generators to the state at the end of the previous run. Especially if the runs are limited to 6 or 12 hours each time, on some supercomputer.

Therefore, as a compromise between disk usage and restart speed, a random number generator class in PROFASI will, from version 1.4, implement a saveState() function. This function will store in a text file all internal state variables of the generator. This function is meant to be called at the end of each small run, so that the disk usage is not a concern. But this will ensure instant restart, if the run is to resume from the end of a previous run.

The format of data in the state files must contain the name of the random number generator, the regular information like the initial seed and the number of calls. The content of the files after this point could be specific to the random number generator class.

Reimplemented from prf::RandomNumberBase.


The documentation for this class was generated from the following files:

PROFASI: Protein Folding and Aggregation Simulator, Version 1.5
© (2005-2016) Anders Irbäck and Sandipan Mohanty
Documentation generated on Mon Jul 18 2016 using Doxygen version 1.8.2