![]() |
The ROme OpTimistic Simulator
2.0.0
A General-Purpose Multithreaded Parallel/Distributed Simulation Platform
|
Numerical Library. More...
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <unistd.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <ROOT-Sim.h>
#include <core/init.h>
#include <communication/communication.h>
#include <mm/mm.h>
#include <scheduler/process.h>
#include <scheduler/scheduler.h>
#include <statistics/statistics.h>
Go to the source code of this file.
Macros | |
#define | RS_WORD_LENGTH (8 * sizeof(seed_type)) |
#define | ROR(value, places) (value << (places)) | (value >> (RS_WORD_LENGTH - places)) |
Functions | |
static double | do_random (void) |
double | Random (void) |
int | RandomRange (int min, int max) |
int | RandomRangeNonUniform (int x, int min, int max) |
double | Expent (double mean) |
double | Normal (void) |
double | Gamma (int ia) |
double | Poisson (void) |
int | Zipf (double skew, int limit) |
static seed_type | sanitize_seed (seed_type cur_seed) |
static void | load_seed (void) |
void | numerical_init (void) |
double | NeumaierSum (unsigned cnt, double addendums[cnt]) |
struct _sum_helper_t | PartialNeumaierSum (struct _sum_helper_t sh, double addendum) |
Variables | |
static seed_type | master_seed |
Numerical Library.
Piece-Wise Deterministic Random Number Generators.
This file is part of ROOT-Sim (ROme OpTimistic Simulator).
ROOT-Sim is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; only version 3 of the License applies.
ROOT-Sim is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with ROOT-Sim; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Definition in file numerical.c.
double Expent | ( | double | mean | ) |
This function returns a random number according to an Exponential distribution. The mean value of the distribution must be passed as the mean value.
mean | Mean value of the distribution |
Definition at line 120 of file numerical.c.
double Gamma | ( | int | ia | ) |
This function returns a number in according to a Gamma Distribution of Integer Order ia, a waiting time to the ia-th event in a Poisson process of unit mean.
ia | Integer Order of the Gamma Distribution |
Definition at line 179 of file numerical.c.
|
static |
This function is used by ROOT-Sim to load the initial value of the seed.
A configuration file is used to store the last master seed, amongst different invocations of the simulator. Using the first value stored in the file, a random number is generated, which is used as a row-offset in the file istelf, where a specified seed will be found. The first line is the replaced with the subsequent seed generated by the Random function.
Definition at line 326 of file numerical.c.
double NeumaierSum | ( | unsigned | cnt, |
double | addendums[cnt] | ||
) |
Calculates a sum within double variables with bounded approximation error
This implements a variant of the Kahan summation algorithm: https://en.wikipedia.org/wiki/Kahan_summation_algorithm This is used in the topology module to calculate minimum costs and weighted probabilities since the classic iterated floating point sum may result in unbounded errors originated from the limited precision of the underlying floating point representation.
cnt | the number of addendums to sum |
addendums | a pointer to a sequence of cnt doubles |
Definition at line 432 of file numerical.c.
double Normal | ( | void | ) |
This function returns a number according to a Normal Distribution with mean 0
Definition at line 141 of file numerical.c.
struct _sum_helper_t PartialNeumaierSum | ( | struct _sum_helper_t | sh, |
double | addendum | ||
) |
Calculates a partial sum within double variables with bounded approximation error
This has similar utilization to <NeumaierSum>() with the difference that this can be used to calculate partial sums, adding doubles one by one.
sh | a struct _sum_helper_t holding the partial result typically from a previous sum |
addendum | the double floating point value to add |
Definition at line 463 of file numerical.c.
double Poisson | ( | void | ) |
This function returns the waiting time to the next event in a Poisson process of unit mean.
Definition at line 223 of file numerical.c.
double Random | ( | void | ) |
This function returns a number in between (0,1), according to a Uniform Distribution. It is based on Multiply with Carry by George Marsaglia
Definition at line 80 of file numerical.c.
MwC random number generators suffer from bad seeds. Since initial LPs' seeds are derived randomly from a random master seed, chances are that we incur in a bad seed. This would create a strong bias in the generation of random numbers for certain LPs. This function checks whether a randomly generated seed is a bad one, and switch to a different safe initial state. This generation is deterministic, therefore it is good for PWD executions of different simulations using the same initial master seed.
cur_seed | The current seed which has been generated and must be checked |
Definition at line 263 of file numerical.c.
int Zipf | ( | double | skew, |
int | limit | ||
) |
This function returns a random sample from a Zipf distribution. Based on the rejection method by Luc Devroye for sampling: "Non-Uniform Random Variate Generation, page 550, Springer-Verlag, 1986
skew | The skew of the distribution |
limit | The largest sample to retrieve |
Definition at line 237 of file numerical.c.
|
static |
Master seed to initialize local seeds of all LPs. This is taken from the configuration file in ~/.rootsim if available, or from /dev/urand the first time a ROOT-Sim model is run.
Definition at line 52 of file numerical.c.