54 static double do_random(
void)
64 *seed1 = 36969u * (*seed1 & 0xFFFFu) + (*seed1 >> 16u);
65 *seed2 = 18000u * (*seed2 & 0xFFFFu) + (*seed2 >> 16u);
69 return (((*seed1 << 16u) + (*seed1 >> 16u) + *seed2) +
70 1.0) * 2.328306435454494e-10;
83 switch_to_platform_mode();
87 switch_to_application_mode();
91 int RandomRange(
int min,
int max)
94 switch_to_platform_mode();
96 ret = (int)floor(do_random() * (max -
min + 1)) +
min;
98 switch_to_application_mode();
102 int RandomRangeNonUniform(
int x,
int min,
int max)
105 switch_to_platform_mode();
107 ret = (((RandomRange(0, x) | RandomRange(
min, max))) % (max -
min + 1)) +
min;
109 switch_to_application_mode();
123 switch_to_platform_mode();
127 "Expent() has been passed a negative mean value\n");
130 ret = (-mean * log(1 - do_random()));
132 switch_to_application_mode();
143 double fac, rsq, v1, v2;
150 if (*iset ==
false) {
152 v1 = 2.0 *
Random() - 1.0;
153 v2 = 2.0 *
Random() - 1.0;
154 rsq = v1 * v1 + v2 * v2;
157 fac = sqrt(-2.0 * log(rsq) / rsq);
182 double am, e, s, v1, v2, x, y;
186 "Gamma distribution must have a ia value >= 1. Defaulting to 1...");
193 for (j = 1; j <= ia; j++)
202 v2 = 2.0 *
Random() - 1.0;
203 }
while (v1 * v1 + v2 * v2 > 1.0);
206 am = (double)(ia - 1);
207 s = sqrt(2.0 * am + 1.0);
211 e = (1.0 + y * y) * exp(am * log(x / am) - s * y);
237 int Zipf(
double skew,
int limit)
240 double b = pow(2., a - 1.);
245 x = floor(pow(u, -1. / a - 1.));
246 t = pow(1. + 1. / x, a - 1.);
247 }
while (v * x * (t - 1.) / (b - 1.) > (t / b) || x > limit);
266 uint32_t *seed1 = (uint32_t *) &(cur_seed);
267 uint32_t *seed2 = (uint32_t *) ((
char *)&(cur_seed) + (
sizeof(uint32_t)));
280 if (temp >= UINT32_C(0x9068FFFF))
281 temp -= UINT32_C(0x9068FFFF);
285 temp = state_orig ^ UINT32_C(0xFFFFFFFF);
286 if (temp >= UINT32_C(0x9068FFFF))
287 temp -= UINT32_C(0x9068FFFF);
299 while (temp >= UINT32_C(0x464FFFFF))
300 temp -= UINT32_C(0x464FFFFF);
304 temp = state_orig ^ UINT32_C(0xFFFFFFFF);
305 while (temp >= UINT32_C(0x464FFFFF))
306 temp -= UINT32_C(0x464FFFFF);
329 static bool single_print =
false;
335 sprintf(conf_file,
"%s/.rootsim/numerical.conf", getenv(
"HOME"));
338 if ((fp = fopen(conf_file,
"r+")) == NULL) {
341 sprintf(conf_file,
"%s/.rootsim", getenv(
"HOME"));
345 sprintf(conf_file,
"%s/.rootsim/numerical.conf", getenv(
"HOME"));
346 if ((fp = fopen(conf_file,
"w")) == NULL) {
347 rootsim_error(
true,
"Unable to create the numerical library configuration file %s. Aborting...", conf_file);
353 if ((fd = open(
"/dev/random", O_RDONLY)) == -1) {
354 rootsim_error(
true,
"Unable to initialize the numerical library configuration file %s. Aborting...", conf_file);
359 fprintf(fp,
"%llu\n", (
unsigned long long)new_seed);
375 if ((fp = fopen(conf_file,
"r+")) == NULL) {
376 rootsim_error(
true,
"Unable to load numerical distribution configuration: %s. Aborting...", conf_file);
380 fscanf(fp,
"%llu", (
unsigned long long *)&
master_seed);
387 fprintf(fp,
"%llu\n", (
unsigned long long)new_seed);
399 #define RS_WORD_LENGTH (8 * sizeof(seed_type)) 400 #define ROR(value, places) (value << (places)) | (value >> (RS_WORD_LENGTH - places)) // Circular shift 401 void numerical_init(
void)
413 #undef RS_WORD_LENGTH 431 __attribute__((
const))
435 double sum = addendums[0];
439 tmp = sum + addendums[cnt];
440 if(fabs(sum) >= fabs(addendums[cnt])) {
441 crt += (sum - tmp) + addendums[cnt];
443 crt += (addendums[cnt] - tmp) + sum;
462 __attribute__((
const))
464 double tmp = sh.sum + addendum;
465 if(fabs(sh.sum) >= fabs(addendum)) {
466 sh.crt += (sh.sum - tmp) + addendum;
468 sh.crt += (addendum - tmp) + sh.sum;
uint64_t seed_type
Numerical seed type.
#define min(a, b)
Macro to find the minimum among two values.
static void load_seed(void)
seed_type set_seed
The master seed to be used in this run.
ROOT-Sim header for model development.
static seed_type sanitize_seed(seed_type cur_seed)
void _mkdir(const char *path)
struct _sum_helper_t PartialNeumaierSum(struct _sum_helper_t sh, double addendum)
bool deterministic_seed
Does not change the seed value config file that will be read during the next runs.
The ROOT-Sim scheduler main module header.
__thread struct lp_struct * current
This is a per-thread variable pointing to the block state of the LP currently scheduled.
this represents a partial Neumaier sum
simulation_configuration rootsim_config
This global variable holds the configuration for the current simulation.
Memory Manager main header.
#define max(a, b)
Macro to find the maximum among two values.
#define D_EQUAL_ZERO(a)
Equality to zero condition for doubles.
int Zipf(double skew, int limit)
double NeumaierSum(unsigned cnt, double addendums[cnt])
static seed_type master_seed
double Expent(double mean)
#define unlikely(exp)
Optimize the branch as likely not taken.