ROOT-Sim core
3.0.0-rc.2
A General-Purpose Multi-threaded Parallel/Distributed Simulation Library
|
ROOT-Sim header for model development. More...
#include <limits.h>
#include <float.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
Go to the source code of this file.
Classes | |
struct | simulation_configuration |
A set of configurable values used by other modules. More... | |
Macros | |
#define | SIMTIME_MAX DBL_MAX |
The maximum value of the logical simulation time, semantically never. | |
#define | Expent(mean) ((mean) * Poisson()) |
#define | INVALID_DIRECTION UINT64_MAX |
An invalid direction, used as error value for the functions which return a LP id. | |
#define | PP_NARG(...) PP_NARG_(__VA_ARGS__,PP_RSEQ_N()) |
Compute the number of arguments to a variadic macro. | |
#define | PP_NARG_(...) PP_128TH_ARG(__VA_ARGS__) |
Compute the number of arguments to a variadic macro. | |
#define | PP_128TH_ARG(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, _31, _32, _33, _34, _35, _36, _37, _38, _39, _40, _41, _42, _43, _44, _45, _46, _47, _48, _49, _50, _51, _52, _53, _54, _55, _56, _57, _58, _59, _60, _61, _62, _63, _64, _65, _66, _67, _68, _69, _70, _71, _72, _73, _74, _75, _76, _77, _78, _79, _80, _81, _82, _83, _84, _85, _86, _87, _88, _89, _90, _91, _92, _93, _94, _95, _96, _97, _98, _99, _100, _101, _102, _103, _104, _105, _106, _107, _108, _109, _110, _111, _112, _113, _114, _115, _116, _117, _118, _119, _120, _121, _122, _123, _124, _125, _126, _127, N, ...) N |
Enumerate the arguments' count to a variadic macro. | |
#define | PP_RSEQ_N() |
Enumerate the arguments' count to a variadic macro in reverse order. More... | |
#define | InitializeTopology(geometry, ...) vInitializeTopology(geometry, PP_NARG(__VA_ARGS__), __VA_ARGS__) |
Initialize a topology struct. More... | |
Typedefs | |
typedef double | simtime_t |
Simulation time data type. | |
typedef uint64_t | lp_id_t |
Logical Process ID data type. | |
typedef void(* | ProcessEvent_t) (lp_id_t me, simtime_t now, unsigned event_type, const void *event_content, unsigned event_size, void *st) |
ProcessEvent callback function. More... | |
typedef bool(* | CanEnd_t) (lp_id_t me, const void *snapshot) |
Determine if simulation can be halted. More... | |
Enumerations | |
enum | rootsim_event { LP_INIT = 65534 , LP_FINI } |
enum | log_level { LOG_TRACE , LOG_DEBUG , LOG_INFO , LOG_WARN , LOG_ERROR , LOG_FATAL , LOG_SILENT } |
enum | topology_geometry { TOPOLOGY_HEXAGON = 1 , TOPOLOGY_SQUARE , TOPOLOGY_TORUS , TOPOLOGY_RING , TOPOLOGY_BIDRING , TOPOLOGY_STAR , TOPOLOGY_FCMESH , TOPOLOGY_GRAPH } |
enum | topology_direction { DIRECTION_E , DIRECTION_W , DIRECTION_N , DIRECTION_S , DIRECTION_NE , DIRECTION_SW , DIRECTION_NW , DIRECTION_SE , DIRECTION_RANDOM } |
Functions | |
void | ScheduleNewEvent (lp_id_t receiver, simtime_t timestamp, unsigned event_type, const void *event_content, unsigned event_size) |
API to inject a new event in the simulation. More... | |
void | SetState (void *new_state) |
Set the LP simulation state main pointer. More... | |
void * | rs_malloc (size_t req_size) |
void * | rs_calloc (size_t nmemb, size_t size) |
void | rs_free (void *ptr) |
void * | rs_realloc (void *ptr, size_t req_size) |
double | Random (void) |
Return a random value in [0,1] according to a uniform distribution. More... | |
uint64_t | RandomU64 (void) |
Return a random 64-bit value. More... | |
double | Poisson (void) |
Return a random number according to an Exponential distribution with unit mean Corresponds to the waiting time to the next event in a Poisson process of unit mean. More... | |
double | Normal (void) |
Return a pair of independent random numbers according to a Standard Normal Distribution. More... | |
int | RandomRange (int min, int max) |
int | RandomRangeNonUniform (int x, int min, int max) |
double | Gamma (unsigned ia) |
Return a number in according to a Gamma Distribution of Integer Order ia Corresponds to the waiting time to the ia-th event in a Poisson process of unit mean. More... | |
unsigned | Zipf (double skew, unsigned limit) |
Return 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. More... | |
lp_id_t | CountRegions (struct topology *topology) |
lp_id_t | CountDirections (lp_id_t from, struct topology *topology) |
lp_id_t | GetReceiver (lp_id_t from, struct topology *topology, enum topology_direction direction) |
void | ReleaseTopology (struct topology *topology) |
bool | AddTopologyLink (struct topology *topology, lp_id_t from, lp_id_t to, double probability) |
bool | IsNeighbor (lp_id_t from, lp_id_t to, struct topology *topology) |
struct topology * | vInitializeTopology (enum topology_geometry geometry, int argc,...) |
Initialize a topology region. More... | |
int | RootsimInit (const struct simulation_configuration *conf) |
Initialize the core library. More... | |
int | RootsimRun (void) |
Start the simulation. More... | |
void | RootsimStop (void) |
Force termination of the simulation. | |
ROOT-Sim header for model development.
This header defines all the symbols which are needed to develop a model to be simulated on top of ROOT-Sim.
This header is the only file which should be included when developing a simulation model. All function prototypes exposed to the application developer are exposed and defined here.
#define InitializeTopology | ( | geometry, | |
... | |||
) | vInitializeTopology(geometry, PP_NARG(__VA_ARGS__), __VA_ARGS__) |
Initialize a topology struct.
geometry | The topology struct to initialize |
... | The number of regions and/or the number of links, depending on the topology geometry |
#define PP_RSEQ_N | ( | ) |
Enumerate the arguments' count to a variadic macro in reverse order.
typedef bool(* CanEnd_t) (lp_id_t me, const void *snapshot) |
Determine if simulation can be halted.
me | The logical process ID of the called LP |
snapshot | The committed state of the logical process |
This function receives a committed snapshot of the logical process state. It can be inspected to determine whether the simulation can be halted, locally at the LP. The function should return true if the simulation can be halted, false otherwise.
typedef void(* ProcessEvent_t) (lp_id_t me, simtime_t now, unsigned event_type, const void *event_content, unsigned event_size, void *st) |
ProcessEvent callback function.
me | The logical process ID of the called LP |
now | The current simulation time |
event_type | The type of the simulation event |
event_content | The (model-specific) content of the simulation event |
event_size | The size of the event content |
st | The current state of the logical process |
This function is called by the simulation kernel whenever a new event is extracted from the event queue. The event is executed in the speculative part of the simulation trajectory: any change to the simulation state might be reverted by the simulation kernel in case a straggler event is detected.
enum log_level |
enum topology_direction |
enum topology_geometry |
double Gamma | ( | unsigned | ia | ) |
Return a number in according to a Gamma Distribution of Integer Order ia Corresponds to the waiting time to the ia-th event in a Poisson process of unit mean.
ia | Integer Order of the Gamma Distribution |
double Normal | ( | void | ) |
Return a pair of independent random numbers according to a Standard Normal Distribution.
double Poisson | ( | void | ) |
Return a random number according to an Exponential distribution with unit mean Corresponds to the waiting time to the next event in a Poisson process of unit mean.
double Random | ( | void | ) |
Return a random value in [0,1] according to a uniform distribution.
uint64_t RandomU64 | ( | void | ) |
Return a random 64-bit value.
int RootsimInit | ( | const struct simulation_configuration * | conf | ) |
Initialize the core library.
This function must be invoked so as to initialize the core. The structure passed to this function is copied into a library variable, that is used by the core to support the simulation run.
conf | A pointer to a struct simulation_configuration used to configure the core library. |
int RootsimRun | ( | void | ) |
Start the simulation.
This function starts the simulation. It must be called after having initialized the ROOT-Sim core by calling RootsimInit(), otherwise the invocation will fail.
void ScheduleNewEvent | ( | lp_id_t | receiver, |
simtime_t | timestamp, | ||
unsigned | event_type, | ||
const void * | event_content, | ||
unsigned | event_size | ||
) |
API to inject a new event in the simulation.
This is a function pointer that is setup at simulation startup to point to either ScheduleNewEvent_parallel() in case of a parallel/distributed simulation, or to ScheduleNewEvent_serial() in case of a serial simulation.
receiver | The ID of the LP that should receive the newly-injected message |
timestamp | The simulation time at which the event should be delivered at the recipient LP |
event_type | Numerical event type to be passed to the model's dispatcher |
event_content | The event content |
event_size | The size (in bytes) of the event content |
void SetState | ( | void * | state | ) |
Set the LP simulation state main pointer.
state | The state pointer to be passed to ProcessEvent() for the invoker LP |
struct topology* vInitializeTopology | ( | enum topology_geometry | geometry, |
int | argc, | ||
... | |||
) |
Initialize a topology region.
This is a variadic function, that initializes a topology depending on its actual shape. In case the topology is a grid, two unsigned parameters should be passed, to specify the width and height of the grid. For all other topologies (included generic graphs) only a single unsigned parameter is needed, which is the number of elements composing the topology.
geometry | The geometry to be used in the topology, a value from enum topology_geometry |
argc | This is the number of variadic arguments passed to the function, computed thanks to some preprocessor black magic. This allows to make some early sanity check and prevent users to mess with the stack or initialize wrong topologies. |
... | If geometry is TOPOLOGY_HEXAGON, TOPOLOGY_SQUARE, or TOPOLOGY_TORUS, two unsigned should be passed, to specify the width and height of the topology's grid. For all the other topologies, a single unsigned, determining the number of elements that compose the topology should be passed. |
unsigned Zipf | ( | double | skew, |
unsigned | limit | ||
) |
Return 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 |