vSMC
vSMC: Scalable Monte Carlo
|
Philox RNG engine reimplemented. More...
#include <vsmc/rng/philox.hpp>
Public Types | |
typedef Array< ResultType, K > | buffer_type |
typedef Array< ResultType, K > | ctr_type |
typedef Array< ResultType, K/2 > | key_type |
typedef ResultType | result_type |
Public Member Functions | |
PhiloxEngine (result_type s=0) | |
template<typename SeedSeq > | |
PhiloxEngine (SeedSeq &seq, typename cxx11::enable_if< internal::is_seed_seq< SeedSeq, result_type, key_type, PhiloxEngine< ResultType, K, Rounds > >::value >::type *=nullptr) | |
PhiloxEngine (const key_type &k) | |
ctr_type | ctr () const |
void | ctr (const ctr_type &c) |
void | discard (result_type nskip) |
key_type | key () const |
void | key (const key_type &k) |
result_type | operator() () |
buffer_type | operator() (const ctr_type &c) const |
Generate a buffer of random bits given a counter using the current key. More... | |
void | operator() (const ctr_type &c, buffer_type &buf) const |
Generate random bits in a pre-allocated buffer given a counter using the current key. More... | |
void | seed (result_type s) |
template<typename SeedSeq > | |
void | seed (SeedSeq &seq, typename cxx11::enable_if< internal::is_seed_seq< SeedSeq, result_type, key_type, PhiloxEngine< ResultType, K, Rounds > >::value >::type *=nullptr) |
void | seed (const key_type &k) |
Static Public Member Functions | |
static constexpr result_type | max () |
static constexpr result_type | min () |
Static Public Attributes | |
static constexpr const result_type | _Max |
static constexpr const result_type | _Min = 0 |
Friends | |
bool | operator!= (const PhiloxEngine< ResultType, K, Rounds > &eng1, const PhiloxEngine< ResultType, K, Rounds > &eng2) |
template<typename CharT , typename Traits > | |
std::basic_ostream< CharT, Traits > & | operator<< (std::basic_ostream< CharT, Traits > &os, const PhiloxEngine< ResultType, K, Rounds > &eng) |
bool | operator== (const PhiloxEngine< ResultType, K, Rounds > &eng1, const PhiloxEngine< ResultType, K, Rounds > &eng2) |
template<typename CharT , typename Traits > | |
std::basic_istream< CharT, Traits > & | operator>> (std::basic_istream< CharT, Traits > &is, PhiloxEngine< ResultType, K, Rounds > &eng) |
Philox RNG engine reimplemented.
This is a reimplementation of the algorithm Philox as described in Parallel Random Numbers: As Easy as 1, 2, 3 and implemented in Random123.
Depending on the compilers, processors and RNG configurations, it might be slightly faster or slower than the original implementation. At most two-folds performace difference (both faster and slower) were observed.
Currently the 64-bits version is much slower than the original, except when using recent Clang, GCC, Intel C++ or MSVC on x86-64 computers. The original implementation use some platform dependent assembly or intrinsics to optimize the performance. This implementation use standard C99 when used on other platforms.
This implementation is slightly more flexible in the sense that it does not limit the number of rounds. However, larger number of rounds can have undesired effects. To say the least, currently all loops are unrolled, which can slow down significantly when the number of rounds is large.
Compared to r123:Engine<r123::Philox4x32>
etc., when using the default constructor or the one with a single seed, the output shall be exactly the same for the first \(2^n\) iterations, where \(n\) is the number of bits (32 or 64). Further iterations may produce different results, as vSMC increment the counter slightly differently, but it still cover the same range and has the same period as the original.
The constants of bumping the key (Weyl constants) and those used in each rounds can be set through traits, vsmc::traits::PhiloxWeylConstantTrait
and vsmc::traits::PhiloxRoundConstantTrait
.
Definition at line 307 of file philox.hpp.
typedef Array<ResultType, K> vsmc::PhiloxEngine< ResultType, K, Rounds >::buffer_type |
Definition at line 312 of file philox.hpp.
typedef Array<ResultType, K> vsmc::PhiloxEngine< ResultType, K, Rounds >::ctr_type |
Definition at line 313 of file philox.hpp.
typedef Array<ResultType, K / 2> vsmc::PhiloxEngine< ResultType, K, Rounds >::key_type |
Definition at line 314 of file philox.hpp.
typedef ResultType vsmc::PhiloxEngine< ResultType, K, Rounds >::result_type |
Definition at line 311 of file philox.hpp.
|
inlineexplicit |
Definition at line 322 of file philox.hpp.
|
inlineexplicit |
Definition at line 329 of file philox.hpp.
|
inline |
Definition at line 338 of file philox.hpp.
|
inline |
Definition at line 370 of file philox.hpp.
|
inline |
Definition at line 374 of file philox.hpp.
|
inline |
Definition at line 412 of file philox.hpp.
|
inline |
Definition at line 372 of file philox.hpp.
|
inline |
Definition at line 380 of file philox.hpp.
|
inlinestatic |
Definition at line 439 of file philox.hpp.
|
inlinestatic |
Definition at line 438 of file philox.hpp.
|
inline |
Definition at line 386 of file philox.hpp.
|
inline |
Generate a buffer of random bits given a counter using the current key.
Definition at line 399 of file philox.hpp.
|
inline |
Generate random bits in a pre-allocated buffer given a counter using the current key.
Definition at line 409 of file philox.hpp.
|
inline |
Definition at line 344 of file philox.hpp.
|
inline |
Definition at line 353 of file philox.hpp.
|
inline |
Definition at line 363 of file philox.hpp.
|
friend |
Definition at line 451 of file philox.hpp.
|
friend |
Definition at line 457 of file philox.hpp.
|
friend |
Definition at line 441 of file philox.hpp.
|
friend |
Definition at line 473 of file philox.hpp.
|
static |
Definition at line 435 of file philox.hpp.
|
static |
Definition at line 434 of file philox.hpp.