The ROme OpTimistic Simulator  2.0.0
A General-Purpose Multithreaded Parallel/Distributed Simulation Platform
numerical.c File Reference

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>
+ Include dependency graph for numerical.c:

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
 

Detailed Description

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

Author
Alessandro Pellegrini
Date
March 16, 2011

Definition in file numerical.c.

Function Documentation

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.

Parameters
meanMean value of the distribution
Returns
A random number

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.

Author
D. E. Knuth
Parameters
iaInteger Order of the Gamma Distribution
Returns
A random number

Definition at line 179 of file numerical.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void load_seed ( void  )
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.

Returns
The master seed

Definition at line 326 of file numerical.c.

+ Here is the call graph for this function:

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.

Author
Andrea Piccione
Parameters
cntthe number of addendums to sum
addendumsa pointer to a sequence of cnt doubles
Returns
the sum between the addendums with bounded error

Definition at line 432 of file numerical.c.

double Normal ( void  )

This function returns a number according to a Normal Distribution with mean 0

Returns
A random number

Definition at line 141 of file numerical.c.

+ Here is the call graph for this function:

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.

Author
Andrea Piccione
Parameters
sha struct _sum_helper_t holding the partial result typically from a previous sum
addendumthe double floating point value to add
Returns
a struct _sum_helper_t holding the sum between sh and addendum

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.

Returns
A random number

Definition at line 223 of file numerical.c.

+ Here is the call graph for this function:

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

Returns
A random number, in between (0,1)

Definition at line 80 of file numerical.c.

+ Here is the caller graph for this function:

static seed_type sanitize_seed ( seed_type  cur_seed)
static

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.

Parameters
cur_seedThe current seed which has been generated and must be checked
Returns
A sanitized seed

Definition at line 263 of file numerical.c.

+ Here is the caller graph for this function:

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

Parameters
skewThe skew of the distribution
limitThe largest sample to retrieve
Returns
A random number

Definition at line 237 of file numerical.c.

+ Here is the call graph for this function:

Variable Documentation

seed_type master_seed
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.