You are here:
Home ยป >dSFMT state read/write routines
dSFMT state read/write routines
Short history
In October 2010
I
was working in a research project where we minimize
a segmentation energy for images using a stochastic approach.
To this end, we choose the
SIMD-oriented Fast Mersenne Twister (SFMT).
This random number generator is described in this paper.
-
Mutsuo Saito and Makoto Matsumoto, "A PRNG Specialized in Double
Precision Floating Point Number Using an Affine Transition", Monte Carlo
and Quasi-Monte Carlo Methods 2008, Springer, 2009, pp. 589 -- 602.
DOI:10.1007/978-3-642-04107-5_38
and the authors are so kind as to provide fully working C code,
at the above address.
While we were developing our research, we also added some code to your
library. This code can be used to transform the internal state of the
dSFMT into a formatted ASCII string. This is quite useful for very long
running minimization algorithms. When our minimization algorithm runs,
every 10 seconds it saves this string in a "checkpoint file" together
with all other internal parameters of the algorithm ; if the algorithm
is interrupted, then the algorithm can be restarted and it will read the
file and start from where it last saved its state. This is also very
useful if the algorithm crashes: by loading the state, the debugging can
be done on the state that (nearly) crashed. (This proved very useful
when it happened that a particular choice of inputs would crash the
algorithm after ~50minutes of running...).
New routines
The new code adds 4 functions; the first function transforms the state to a
ASCII multiline string. The other functions read the string back to the state.
- char *dsfmt_state_to_str(dsfmt_t *dsfmt, char *prefix);
This function returns a string that represents the state of the dSFMT.
The string is allocated and should be free-d after use.
- char *dsfmt_str_to_state(dsfmt_t *dsfmt, char *str, char *prefix);
This function reads a string that represents the state of the dSFMT, and fills the state.
It returns NULL if OK, or a string explaining the error, if any. (It should be freed after use)
- char *dsfmt_strlist_to_state(dsfmt_t *dsfmt, char **strlist, char
*prefix);
This function reads a NULL terminated list of string that represents the state of the dSFMT, and fills the state.
It returns NULL if OK, or a string explaining the error, if any. (The error should be freed after use)
- char *dsfmt_file_to_state(dsfmt_t *dsfmt, FILE *origfile, char
*prefix);
This function reads a file descriptor that represents the state of the dSFMT, and fills the state.
It will skip over comments in the file (a comment is any line starting with '#').
It returns NULL if OK, or a string explaining the error, if any. (It should be freed after use)
Various info.
- prefix is a prefix to start all lines; if it is NULL, it is set to "dsfmt_".
- The string is a purely ASCII string, so it can be written in a ASCII
file with other data, and it can be read back.
- The new code also adds a test suite , that reads in a file that is
distributed , and checks that it works fine. I tested it on Debian
GNU/Linux machines, both i386 and amd64 architectures. The test is done
for MEXP=19937 and MEXP=4253 .
-
The new code changes -std=c99 to -std=gnu99 , so that the 'strdup'
function is available.
Downloads
The following files are available for download