vSMC
vSMC: Scalable Monte Carlo
Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | Friends | List of all members
vsmc::ThreefryEngine< ResultType, K, Rounds > Class Template Reference

Threefry RNG engine reimplemented. More...

#include <vsmc/rng/threefry.hpp>

Public Types

typedef Array< ResultType, K > buffer_type
 
typedef Array< ResultType, K > ctr_type
 
typedef Array< ResultType, K > key_type
 
typedef ResultType result_type
 

Public Member Functions

 ThreefryEngine (result_type s=0)
 
template<typename SeedSeq >
 ThreefryEngine (SeedSeq &seq, typename cxx11::enable_if< internal::is_seed_seq< SeedSeq, result_type, key_type, ThreefryEngine< ResultType, K, Rounds > >::value >::type *=nullptr)
 
 ThreefryEngine (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, ThreefryEngine< 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 ThreefryEngine< ResultType, K, Rounds > &eng1, const ThreefryEngine< ResultType, K, Rounds > &eng2)
 
template<typename CharT , typename Traits >
std::basic_ostream< CharT, Traits > & operator<< (std::basic_ostream< CharT, Traits > &os, const ThreefryEngine< ResultType, K, Rounds > &eng)
 
bool operator== (const ThreefryEngine< ResultType, K, Rounds > &eng1, const ThreefryEngine< ResultType, K, Rounds > &eng2)
 
template<typename CharT , typename Traits >
std::basic_istream< CharT, Traits > & operator>> (std::basic_istream< CharT, Traits > &is, ThreefryEngine< ResultType, K, Rounds > &eng)
 

Detailed Description

template<typename ResultType, std::size_t K, std::size_t Rounds = 20>
class vsmc::ThreefryEngine< ResultType, K, Rounds >

Threefry RNG engine reimplemented.

This is a reimplementation of the algorithm Threefry 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.

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::Threefry4x32> 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.

Definition at line 265 of file threefry.hpp.

Member Typedef Documentation

template<typename ResultType, std::size_t K, std::size_t Rounds = 20>
typedef Array<ResultType, K> vsmc::ThreefryEngine< ResultType, K, Rounds >::buffer_type

Definition at line 270 of file threefry.hpp.

template<typename ResultType, std::size_t K, std::size_t Rounds = 20>
typedef Array<ResultType, K> vsmc::ThreefryEngine< ResultType, K, Rounds >::ctr_type

Definition at line 271 of file threefry.hpp.

template<typename ResultType, std::size_t K, std::size_t Rounds = 20>
typedef Array<ResultType, K> vsmc::ThreefryEngine< ResultType, K, Rounds >::key_type

Definition at line 272 of file threefry.hpp.

template<typename ResultType, std::size_t K, std::size_t Rounds = 20>
typedef ResultType vsmc::ThreefryEngine< ResultType, K, Rounds >::result_type

Definition at line 269 of file threefry.hpp.

Constructor & Destructor Documentation

template<typename ResultType, std::size_t K, std::size_t Rounds = 20>
vsmc::ThreefryEngine< ResultType, K, Rounds >::ThreefryEngine ( result_type  s = 0)
inlineexplicit

Definition at line 280 of file threefry.hpp.

template<typename ResultType, std::size_t K, std::size_t Rounds = 20>
template<typename SeedSeq >
vsmc::ThreefryEngine< ResultType, K, Rounds >::ThreefryEngine ( SeedSeq &  seq,
typename cxx11::enable_if< internal::is_seed_seq< SeedSeq, result_type, key_type, ThreefryEngine< ResultType, K, Rounds > >::value >::type = nullptr 
)
inlineexplicit

Definition at line 287 of file threefry.hpp.

template<typename ResultType, std::size_t K, std::size_t Rounds = 20>
vsmc::ThreefryEngine< ResultType, K, Rounds >::ThreefryEngine ( const key_type k)
inline

Definition at line 296 of file threefry.hpp.

Member Function Documentation

template<typename ResultType, std::size_t K, std::size_t Rounds = 20>
ctr_type vsmc::ThreefryEngine< ResultType, K, Rounds >::ctr ( ) const
inline

Definition at line 332 of file threefry.hpp.

template<typename ResultType, std::size_t K, std::size_t Rounds = 20>
void vsmc::ThreefryEngine< ResultType, K, Rounds >::ctr ( const ctr_type c)
inline

Definition at line 343 of file threefry.hpp.

template<typename ResultType, std::size_t K, std::size_t Rounds = 20>
void vsmc::ThreefryEngine< ResultType, K, Rounds >::discard ( result_type  nskip)
inline

Definition at line 381 of file threefry.hpp.

template<typename ResultType, std::size_t K, std::size_t Rounds = 20>
key_type vsmc::ThreefryEngine< ResultType, K, Rounds >::key ( ) const
inline

Definition at line 334 of file threefry.hpp.

template<typename ResultType, std::size_t K, std::size_t Rounds = 20>
void vsmc::ThreefryEngine< ResultType, K, Rounds >::key ( const key_type k)
inline

Definition at line 349 of file threefry.hpp.

template<typename ResultType, std::size_t K, std::size_t Rounds = 20>
static constexpr result_type vsmc::ThreefryEngine< ResultType, K, Rounds >::max ( )
inlinestatic

Definition at line 408 of file threefry.hpp.

template<typename ResultType, std::size_t K, std::size_t Rounds = 20>
static constexpr result_type vsmc::ThreefryEngine< ResultType, K, Rounds >::min ( )
inlinestatic

Definition at line 407 of file threefry.hpp.

template<typename ResultType, std::size_t K, std::size_t Rounds = 20>
result_type vsmc::ThreefryEngine< ResultType, K, Rounds >::operator() ( )
inline

Definition at line 355 of file threefry.hpp.

template<typename ResultType, std::size_t K, std::size_t Rounds = 20>
buffer_type vsmc::ThreefryEngine< ResultType, K, Rounds >::operator() ( const ctr_type c) const
inline

Generate a buffer of random bits given a counter using the current key.

Definition at line 368 of file threefry.hpp.

template<typename ResultType, std::size_t K, std::size_t Rounds = 20>
void vsmc::ThreefryEngine< ResultType, K, Rounds >::operator() ( const ctr_type c,
buffer_type buf 
) const
inline

Generate random bits in a pre-allocated buffer given a counter using the current key.

Definition at line 378 of file threefry.hpp.

template<typename ResultType, std::size_t K, std::size_t Rounds = 20>
void vsmc::ThreefryEngine< ResultType, K, Rounds >::seed ( result_type  s)
inline

Definition at line 302 of file threefry.hpp.

template<typename ResultType, std::size_t K, std::size_t Rounds = 20>
template<typename SeedSeq >
void vsmc::ThreefryEngine< ResultType, K, Rounds >::seed ( SeedSeq &  seq,
typename cxx11::enable_if< internal::is_seed_seq< SeedSeq, result_type, key_type, ThreefryEngine< ResultType, K, Rounds > >::value >::type = nullptr 
)
inline

Definition at line 313 of file threefry.hpp.

template<typename ResultType, std::size_t K, std::size_t Rounds = 20>
void vsmc::ThreefryEngine< ResultType, K, Rounds >::seed ( const key_type k)
inline

Definition at line 325 of file threefry.hpp.

Friends And Related Function Documentation

template<typename ResultType, std::size_t K, std::size_t Rounds = 20>
bool operator!= ( const ThreefryEngine< ResultType, K, Rounds > &  eng1,
const ThreefryEngine< ResultType, K, Rounds > &  eng2 
)
friend

Definition at line 420 of file threefry.hpp.

template<typename ResultType, std::size_t K, std::size_t Rounds = 20>
template<typename CharT , typename Traits >
std::basic_ostream<CharT, Traits>& operator<< ( std::basic_ostream< CharT, Traits > &  os,
const ThreefryEngine< ResultType, K, Rounds > &  eng 
)
friend

Definition at line 426 of file threefry.hpp.

template<typename ResultType, std::size_t K, std::size_t Rounds = 20>
bool operator== ( const ThreefryEngine< ResultType, K, Rounds > &  eng1,
const ThreefryEngine< ResultType, K, Rounds > &  eng2 
)
friend

Definition at line 410 of file threefry.hpp.

template<typename ResultType, std::size_t K, std::size_t Rounds = 20>
template<typename CharT , typename Traits >
std::basic_istream<CharT, Traits>& operator>> ( std::basic_istream< CharT, Traits > &  is,
ThreefryEngine< ResultType, K, Rounds > &  eng 
)
friend

Definition at line 442 of file threefry.hpp.

Member Data Documentation

template<typename ResultType, std::size_t K, std::size_t Rounds = 20>
constexpr const result_type vsmc::ThreefryEngine< ResultType, K, Rounds >::_Max
static
Initial value:
= static_cast<result_type>(
~(static_cast<result_type>(0)))

Definition at line 404 of file threefry.hpp.

template<typename ResultType, std::size_t K, std::size_t Rounds = 20>
constexpr const result_type vsmc::ThreefryEngine< ResultType, K, Rounds >::_Min = 0
static

Definition at line 403 of file threefry.hpp.