COMBINATORIAL_BLAS  1.6
splittable_mrg.h
Go to the documentation of this file.
1 /* Copyright (C) 2010 The Trustees of Indiana University. */
2 /* */
3 /* Use, modification and distribution is subject to the Boost Software */
4 /* License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at */
5 /* http://www.boost.org/LICENSE_1_0.txt) */
6 /* */
7 /* Authors: Jeremiah Willcock */
8 /* Andrew Lumsdaine */
9 
10 #ifndef SPLITTABLE_MRG_H
11 #define SPLITTABLE_MRG_H
12 
13 #include <stdint.h>
14 
15 /* Multiple recursive generator from L'Ecuyer, P., Blouin, F., and */
16 /* Couture, R. 1993. A search for good multiple recursive random number */
17 /* generators. ACM Trans. Model. Comput. Simul. 3, 2 (Apr. 1993), 87-98. */
18 /* DOI= http://doi.acm.org/10.1145/169702.169698 -- particular generator */
19 /* used is from table 3, entry for m = 2^31 - 1, k = 5 (same generator */
20 /* is used in GNU Scientific Library). */
21 
22 /* See notes at top of splittable_mrg.c for information on this */
23 /* implementation. */
24 
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28 
29 typedef struct mrg_transition_matrix {
30  uint_fast32_t s, t, u, v, w;
31  /* Cache for other parts of matrix (see mrg_update_cache function) */
32  uint_fast32_t a, b, c, d;
34 
35 typedef struct mrg_state {
36  uint_fast32_t z1, z2, z3, z4, z5;
37 } mrg_state;
38 
39 /* Returns integer value in [0, 2^31-1) */
40 uint_fast32_t mrg_get_uint(const mrg_transition_matrix* mat, mrg_state* state);
41 
42 /* Returns real value in [0, 1) */
43 double mrg_get_double(const mrg_transition_matrix* mat, mrg_state* state);
44 
45 /* Returns integer value in [0, 2^31-1) using original transition matrix */
46 uint_fast32_t mrg_get_uint_orig(mrg_state* state);
47 
48 /* Returns real value in [0, 1) using original transition matrix */
49 double mrg_get_double_orig(mrg_state* state);
50 
52 
53 void mrg_seed(mrg_state* st, const uint_fast32_t seed[5]);
54 
55 /* Split a transition matrix; the result of this function is pre-cached so it
56  * does not need to be called for individual splits of the PRNG state. */
57 void mrg_split_matrix(const mrg_transition_matrix* tm_in,
58  mrg_transition_matrix* tm_out,
59  unsigned int n);
60 
61 /* The variable st_out should be an array of length n; all other parameters are
62  * single elements.
63  *
64  * The state st_in should not be used for random number generation after this
65  * function is called. */
66 void mrg_split_state(const mrg_transition_matrix* tm_in,
67  const mrg_state* st_in,
68  mrg_state* st_out,
69  unsigned int n);
70 
71 /* Skip the PRNG ahead _exponent_ steps. This code treats the exponent as a
72  * 192-bit word, even though the PRNG period is less than that. */
73 void mrg_skip(mrg_state* state,
74  uint_least64_t exponent_high,
75  uint_least64_t exponent_middle,
76  uint_least64_t exponent_low);
77 
78 #ifdef __cplusplus
79 }
80 #endif
81 
82 #endif /* SPLITTABLE_MRG_H */
void mrg_skip(mrg_state *state, uint_least64_t exponent_high, uint_least64_t exponent_middle, uint_least64_t exponent_low)
void mrg_seed(mrg_state *st, const uint_fast32_t seed[5])
uint_fast32_t mrg_get_uint_orig(mrg_state *state)
void mrg_split_matrix(const mrg_transition_matrix *tm_in, mrg_transition_matrix *tm_out, unsigned int n)
uint_fast32_t mrg_get_uint(const mrg_transition_matrix *mat, mrg_state *state)
struct mrg_state mrg_state
void mrg_init(mrg_transition_matrix *tm, mrg_state *st)
uint_fast32_t z5
struct mrg_transition_matrix mrg_transition_matrix
void mrg_split_state(const mrg_transition_matrix *tm_in, const mrg_state *st_in, mrg_state *st_out, unsigned int n)
double mrg_get_double_orig(mrg_state *state)
double mrg_get_double(const mrg_transition_matrix *mat, mrg_state *state)