7#include "Accelerator/hybrid.h"
8#include "Constants/scaling.h"
9#include "Constants/hpc_bounds.h"
10#include "DataTypes/common_types.h"
11#include "DataTypes/stormm_vector_types.h"
12#include "Math/rounding.h"
13#include "Numerics/split_fixed_precision.h"
14#include "random_enumerators.h"
20using card::HybridKind;
21using card::HybridTargetLevel;
22using constants::giga_zu;
23using data_types::isFloatingPointScalarType;
28constexpr int im1 = 2147483563;
29constexpr int im2 = 2147483399;
30constexpr double am = 1.0 / im1;
31constexpr int im1_minus_one = im1 - 1;
32constexpr int ia1 = 40014;
33constexpr int ia2 = 40692;
34constexpr int iq1 = 53668;
35constexpr int iq2 = 52774;
36constexpr int ir1 = 12211;
37constexpr int ir2 = 3791;
38constexpr int ntab = 32;
39constexpr int ndiv = 1 + im1_minus_one / ntab;
40constexpr double double_increment = 2.2205e-16;
41constexpr double ran2_max = 1.0 - double_increment;
45constexpr int default_random_seed = 827493;
50constexpr int default_xoroshiro128p_scrub = 25;
51constexpr int default_xoshiro256pp_scrub = 50;
60constexpr int max_xo_long_jumps = 1024;
71constexpr double rng_unit_bin_offset = 1.1102230246251565404236316680908203125e-16;
72constexpr float rng_unit_bin_offset_f = 5.960464477539062500e-08f;
116 int state_vector[ntab + 8];
121constexpr ullint xrs128p_jump_i = 0xdf900294d8f554a5LLU;
122constexpr ullint xrs128p_jump_ii = 0x170865df4b3201fcLLU;
123constexpr ullint xrs128p_longjump_i = 0xd2a98b26625eee7bLLU;
124constexpr ullint xrs128p_longjump_ii = 0xdddf9b1090aa7ac1LLU;
129constexpr ullint xrs256pp_jump_i = 0x180ec6d33cfd0abaLLU;
130constexpr ullint xrs256pp_jump_ii = 0xd5a61266f0c9392cLLU;
131constexpr ullint xrs256pp_jump_iii = 0xa9582618e03fc9aaLLU;
132constexpr ullint xrs256pp_jump_iv = 0x39abdc4529b1661cLLU;
133constexpr ullint xrs256pp_longjump_i = 0x76e15d3efefdcbbfLLU;
134constexpr ullint xrs256pp_longjump_ii = 0xc5004e441c522fb3LLU;
135constexpr ullint xrs256pp_longjump_iii = 0x77710069854ee241LLU;
136constexpr ullint xrs256pp_longjump_iv = 0x39109bb02acbe635LLU;
196 void setState(
const ullint2 state_in);
204 ullint2 seed128(
int igseed);
213 void fastForward(
const ullint2 stride);
269 void setState(
const ullint4 state_in);
277 ullint4 seed256(
int igseed);
286 void fastForward(
const ullint4 stride);
307 RandomNumberMill(
const ullint2 state_in,
size_t generators_in = 1LLU,
size_t depth_in = 2LLU,
308 RandomNumberKind init_kind = RandomNumberKind::GAUSSIAN,
309 size_t bank_limit = constants::giga_zu);
311 RandomNumberMill(
const ullint4 state_in,
size_t generators_in = 1LLU,
size_t depth_in = 2LLU,
312 RandomNumberKind init_kind = RandomNumberKind::GAUSSIAN,
313 size_t bank_limit = constants::giga_zu);
316 RandomAlgorithm style_in = RandomAlgorithm::XOSHIRO_256PP,
317 RandomNumberKind init_kind = RandomNumberKind::GAUSSIAN,
318 int igseed_in = default_random_seed,
int niter = default_xoshiro256pp_scrub,
319 size_t bank_limit = constants::giga_zu);
352 RandomAlgorithm style;
355 size_t refresh_stride;
373 void checkDimensions(
size_t bank_limit);
379 void initializeBank(RandomNumberKind init_kind);
398template <
typename Tprng>
double uniformRand(Tprng *rng,
double scale = 1.0);
400template <
typename Tprng> std::vector<double> uniformRand(Tprng *rng,
size_t count,
403template <
typename Tprng>
404std::vector<double> uniformRand(Tprng *rng,
size_t rows,
size_t columns,
double scale,
405 RngFillMode mode = RngFillMode::COLUMNS);
407template <
typename Tprng,
typename Tprod>
408void uniformRand(Tprng *rng, std::vector<Tprod> *xv,
double scale = 1.0,
double fp_scale = 1.0);
414template <
typename Tprng>
float spUniformRand(Tprng *rng,
float scale = 1.0);
416template <
typename Tprng> std::vector<float> spUniformRand(Tprng *rng,
size_t count,
float scale);
418template <
typename Tprng>
419std::vector<float> spUniformRand(Tprng *rng,
size_t rows,
size_t columns,
float scale,
420 RngFillMode mode = RngFillMode::COLUMNS);
422template <
typename Tprng,
typename Tprod>
423void spUniformRand(Tprng *rng, std::vector<Tprod> *xv,
float scale = 1.0,
float fp_scale = 1.0);
429template <
typename Tprng>
double guassianRand(Tprng *rng,
double scale = 1.0);
431template <
typename Tprng> std::vector<double> guassianRand(Tprng *rng,
size_t count,
double scale);
433template <
typename Tprng>
434std::vector<double> guassianRand(Tprng *rng,
size_t rows,
size_t columns,
double scale,
435 RngFillMode mode = RngFillMode::COLUMNS);
437template <
typename Tprng,
typename Tprod>
438void guassianRand(Tprng *rng, std::vector<Tprod> *xv,
double fp_scale = 1.0,
double scale = 1.0);
444template <
typename Tprng>
float spGuassianRand(Tprng *rng,
float scale = 1.0);
446template <
typename Tprng> std::vector<float> spGuassianRand(Tprng *rng,
size_t count,
float scale);
448template <
typename Tprng>
449std::vector<float> spGuassianRand(Tprng *rng,
size_t rows,
size_t columns,
float scale,
450 RngFillMode mode = RngFillMode::COLUMNS);
452template <
typename Tprng,
typename Tprod>
453void spGuassianRand(Tprng *rng, std::vector<Tprod> *xv,
float fp_scale = 1.0,
float scale = 1.0);
471void initXoroshiro128pArray(ullint2* state_vector,
int n_generators,
int igseed,
472 int scrub_cycles = default_xoroshiro128p_scrub);
473void initXoroshiro128pArray(std::vector<ullint2> *state_vector,
int igseed,
474 int scrub_cycles = default_xoroshiro128p_scrub);
476 int scrub_cycles = default_xoroshiro128p_scrub);
494void initXoshiro256ppArray(ullint2* state_xy, ullint2* state_zw,
int n_generators,
int igseed,
495 int scrub_cycles = default_xoshiro256pp_scrub);
496void initXoshiro256ppArray(std::vector<ullint2> *state_xy, std::vector<ullint2> *state_zw,
497 int igseed,
int scrub_cycles = default_xoshiro256pp_scrub);
499 int scrub_cycles = default_xoshiro256pp_scrub);
526void fillRandomCache(ullint2* state_xy, ullint2* state_zw, T* cache,
size_t length,
size_t depth,
527 RandomAlgorithm method, RandomNumberKind product,
size_t index_start,
531void fillRandomCache(std::vector<ullint2> *state_xy, std::vector<ullint2> *state_zw,
532 std::vector<T> *cache,
size_t length,
size_t depth, RandomAlgorithm method,
533 RandomNumberKind product,
size_t index_start,
size_t index_end);
537 size_t length,
size_t depth, RandomAlgorithm method, RandomNumberKind product,
538 size_t index_start,
size_t index_end);
563template <
typename Trng,
typename Tvar>
564void addRandomNoise(Trng *prng, Tvar* x,
size_t length,
double mult,
double scale = 1.0,
565 RandomNumberKind kind = RandomNumberKind::GAUSSIAN);
567template <
typename Trng,
typename Tvar>
568void addRandomNoise(Trng *prng, std::vector<Tvar> *x,
double mult,
double scale = 1.0,
569 RandomNumberKind kind = RandomNumberKind::GAUSSIAN);
571template <
typename Trng,
typename Tvar>
572void addRandomNoise(Trng *prng,
Hybrid<Tvar> *x,
double mult,
double scale = 1.0,
573 RandomNumberKind kind = RandomNumberKind::GAUSSIAN);
575template <
typename Trng,
typename Tvar>
576void addRandomNoise(Trng *prng, Tvar* x, Tvar* y, Tvar *z,
size_t length,
double mult,
577 double scale = 1.0, RandomNumberKind kind = RandomNumberKind::GAUSSIAN);
579template <
typename Trng,
typename Tvar>
580void addRandomNoise(Trng *prng, std::vector<Tvar> *x, std::vector<Tvar> *y, std::vector<Tvar> *z,
581 double mult,
double scale = 1.0,
582 RandomNumberKind kind = RandomNumberKind::GAUSSIAN);
584template <
typename Trng,
typename Tvar>
586 double scale = 1.0, RandomNumberKind kind = RandomNumberKind::GAUSSIAN);
588template <
typename Trng>
589void addRandomNoise(Trng *prng, llint* x,
int* x_ovrf,
size_t length,
double mult,
double scale,
590 RandomNumberKind kind = RandomNumberKind::GAUSSIAN);
592template <
typename Trng>
593void addRandomNoise(Trng *prng, std::vector<llint> *x, std::vector<int> *x_ovrf,
double mult,
594 double scale, RandomNumberKind kind = RandomNumberKind::GAUSSIAN);
596template <
typename Trng>
598 RandomNumberKind kind = RandomNumberKind::GAUSSIAN);
600template <
typename Trng>
601void addRandomNoise(Trng *prng, llint* x,
int* x_ovrf, llint* y,
int* y_ovrf, llint* z,
602 int* z_ovrf,
size_t length,
double mult,
double scale,
603 RandomNumberKind kind = RandomNumberKind::GAUSSIAN);
605template <
typename Trng>
606void addRandomNoise(Trng *prng, std::vector<llint> *x, std::vector<int> *x_ovrf,
607 std::vector<llint> *y, std::vector<int> *y_ovrf, std::vector<llint> *z,
608 std::vector<int> *z_ovrf,
double mult,
double scale,
609 RandomNumberKind kind = RandomNumberKind::GAUSSIAN);
611template <
typename Trng>
614 double scale, RandomNumberKind kind = RandomNumberKind::GAUSSIAN);
An evolution of GpuBuffer in pmemd.cuda, the Composite array has elements that are accessible from ei...
Definition hybrid.h:202
float spUniformRandomNumber()
Return a single random number distributed over a uniform distribution [0, 1), in single-precision....
Definition random.cpp:81
Ran2Generator(int igseed=default_random_seed)
Initialize the unit testing on-board pseudo-random number generator.
Definition random.cpp:17
double gaussianRandomNumber()
Return a normally distributed random number with standard deviation 1.0. This works off of the unifor...
Definition random.cpp:86
double uniformRandomNumber()
Return a single random number distributed over a uniform distribution [0, 1). This is an internal gen...
Definition random.cpp:38
float spGaussianRandomNumber()
Produce a single-precision random number on the normal distribution with a standard deviation of 1....
Definition random.cpp:93
size_t getDepth() const
Get the depth of the bank for each generator.
T getBankValue(size_t generator_index, size_t layer_index) const
Get a random number out of the bank.
RandomNumberMill(const ullint2 state_in, size_t generators_in=1LLU, size_t depth_in=2LLU, RandomNumberKind init_kind=RandomNumberKind::GAUSSIAN, size_t bank_limit=constants::giga_zu)
The constructor can work off of a simple random initialization seed integer or a specific state vecto...
void uniformRandomNumbers(size_t first_gen, size_t last_gen)
Populate a portion of this object's bank with random numbers from each of the respective generators.
size_t getGeneratorCount() const
Get the number of (forward-jumped) generators.
size_t getRefreshStride() const
Get the number of generators for which to refesh all banked values at one time.
void gaussianRandomNumbers(size_t first_gen, size_t last_gen)
Populate a portion of this object's bank with normally distributed random numbers from each of the re...
double uniformRandomNumber()
Return a single random number distributed over a uniform distribution [0, 1). This is an internal gen...
Definition random.cpp:131
double gaussianRandomNumber()
Return a normally distributed random number with standard deviation 1.0. This works off of the unifor...
Definition random.cpp:143
float spUniformRandomNumber()
Return a single random number distributed over a uniform distribution [0, 1), in single-precision....
Definition random.cpp:137
void setState(const ullint2 state_in)
Set the current state of the generator.
Definition random.cpp:179
Xoroshiro128pGenerator(int igseed=default_random_seed, int niter=25)
The constructor can start or restart the generator.
Definition random.cpp:100
ullint2 revealState() const
Reveal the current state of the generator.
Definition random.cpp:169
void longJump()
Jump forward 2^96 iterations in the sequence.
Definition random.cpp:163
float spGaussianRandomNumber()
Produce a single-precision random number on the normal distribution with a standard deviation of 1....
Definition random.cpp:150
ullint revealBitString() const
Reveal the random bit string.
Definition random.cpp:174
void jump()
Jump forward 2^64 iterations in the sequence.
Definition random.cpp:157
void longJump()
Jump forward 2^192 iterations in the sequence.
Definition random.cpp:303
ullint revealBitString() const
Reveal the random bit string.
Definition random.cpp:315
float spUniformRandomNumber()
Return a single random number distributed over a uniform distribution [0, 1), in single-precision....
Definition random.cpp:276
double gaussianRandomNumber()
Return a normally distributed random number with standard deviation 1.0. This works off of the unifor...
Definition random.cpp:282
ullint4 revealState() const
Reveal the current state of the generator.
Definition random.cpp:310
float spGaussianRandomNumber()
Produce a single-precision random number on the normal distribution with a standard deviation of 1....
Definition random.cpp:289
double uniformRandomNumber()
Return a single random number distributed over a uniform distribution [0, 1). This is an internal gen...
Definition random.cpp:270
Xoshiro256ppGenerator(int igseed=default_random_seed, int niter=50)
The constructor can start or restart the generator.
Definition random.cpp:239
void jump()
Jump forward 2^128 iterations in the sequence.
Definition random.cpp:296
void setState(const ullint4 state_in)
Set the current state of the generator.
Definition random.cpp:321