The ROme OpTimistic Simulator  2.0.0
A General-Purpose Multithreaded Parallel/Distributed Simulation Platform
ROOT-Sim.h
Go to the documentation of this file.
1 
38 #pragma once
39 
40 #include <stdlib.h>
41 #include <stdio.h>
42 #include <string.h>
43 #include <stdbool.h>
44 #include <float.h>
45 #include <limits.h>
46 #include <argp.h>
47 
48 #ifdef INIT
49 #undef INIT
50 #endif
51 #define INIT 0
53 
55 typedef double simtime_t;
56 
58 #define INFTY DBL_MAX
59 
61 extern unsigned int n_prc_tot;
62 
64 __attribute((weak))
65 extern struct argp model_argp;
66 
67 // Expose to the application level the rollbackable numerical library
68 double Random(void);
69 int RandomRange(int min, int max);
70 int RandomRangeNonUniform(int x, int min, int max);
71 double Expent(double mean);
72 double Normal(void);
73 double Gamma(int ia);
74 double Poisson(void);
75 int Zipf(double skew, int limit);
76 
77 // ROOT-Sim core API
78 extern void (*ScheduleNewEvent)(unsigned int receiver, simtime_t timestamp, unsigned int event_type, void *event_content, unsigned int event_size);
79 extern void SetState(void *new_state);
80 
81 /*********************************/
82 /********TOPOLOGY*LIBRARY*********/
83 /*********************************/
84 
95  TOPOLOGY_STAR, // this still needs to be properly implemented FIXME
97 };
98 
110 typedef enum _direction_t {
113 
116 
121 
122  DIRECTION_INVALID = UINT_MAX
123 } direction_t;
124 
129 };
130 
134 __attribute((weak)) extern struct _topology_settings_t{
135  const char * const topology_path;
136  const enum _topology_type_t type;
137  const enum _topology_geometry_t default_geometry;
138  const unsigned out_of_topology;
139  const bool write_enabled;
140 }topology_settings;
141 
148 double GetValueTopology(unsigned from, unsigned to);
149 
165 void SetValueTopology(unsigned from, unsigned to, double value);
166 
167 // finds a receiver with probabilities weighted on neighbours link (works only for topology type TOPOLOGY_PROBABILITIES)
168 unsigned int FindReceiver (void);
169 
170 // returns the count of regions involved in the topology (can be less than n_prc_tot)
171 unsigned int RegionsCount (void);
172 
173 // returns the maximum count of neighbours this region has, this is made to simplify direction handling (need to explain better xxx)
174 unsigned int DirectionsCount (void);
175 
176 // returns the actual count of neighbours this region has (if this is called from a region on the edge of the topology
177 unsigned int NeighboursCount (unsigned int region);
178 
179 // Returns DIRECTION_INVALID if a movement is not possible according to the given topology
180 unsigned int GetReceiver (unsigned int from, direction_t direction, bool reachable);
181 
182 // this returns the next hop to reach region to following a minimum cost path: it's far less costly than to recompute a new path with ComputeMinTour()
183 unsigned int FindReceiverToward (unsigned int to);
184 
185 // Function to return a list of LP IDs to be visited in order to reach a given cell with minimum cost.
186 // -1.0 is returned is no path is available else the total cost is returned
187 double ComputeMinTour (unsigned int source, unsigned int dest, unsigned int result[RegionsCount()]);
188 
189 /*********************************/
190 /************ABM*LIBRARY**********/
191 /*********************************/
192 
193 typedef unsigned long long agent_t;
194 
195 __attribute((weak)) extern struct _abm_settings_t{
196  const unsigned neighbour_data_size;
197  const unsigned traverse_handler;
198  const bool keep_history;
199 } abm_settings;
200 
201 int GetNeighbourInfo (direction_t i, unsigned int *region_id, void **data_p);
202 void TrackNeighbourInfo (void *neighbour_data);
203 
204 bool IterAgents (agent_t *agent_p);
205 unsigned CountAgents (void);
206 
207 agent_t SpawnAgent (unsigned user_data_size);
208 void KillAgent (agent_t agent);
209 
210 void* DataAgent (agent_t agent, unsigned *data_size_p);
211 
212 void ScheduleNewLeaveEvent (simtime_t time, unsigned int event_type, agent_t agent);
213 
214 unsigned CountVisits (const agent_t agent);
215 void GetVisit (const agent_t agent, unsigned *region_p, unsigned *event_type_p, unsigned i);
216 void SetVisit (const agent_t agent, unsigned region, unsigned event_type, unsigned i);
217 void EnqueueVisit (agent_t agent, unsigned region, unsigned event_type);
218 void AddVisit (agent_t agent, unsigned region, unsigned event_type, unsigned i);
219 void RemoveVisit (agent_t agent, unsigned i);
220 
221 unsigned CountPastVisits (const agent_t agent);
222 void GetPastVisit (const agent_t agent, unsigned *region_p, unsigned *event_type_p, simtime_t *time_p, unsigned i);
all crossing costs and probabilities are set to 1, but there can be not crossable regions ...
Definition: ROOT-Sim.h:126
unsigned int n_prc_tot
This is the definition of the number of LPs running in the current simulation.
Definition: core.c:64
DIRECTION_W.
Definition: ROOT-Sim.h:112
#define min(a, b)
Macro to find the minimum among two values.
Definition: core.h:115
double Expent(double mean)
Definition: numerical.c:120
A generic invalid direction.
Definition: ROOT-Sim.h:122
DIRECTION_SE.
Definition: ROOT-Sim.h:120
double Normal(void)
Definition: numerical.c:141
DIRECTION_E.
Definition: ROOT-Sim.h:111
DIRECTION_N.
Definition: ROOT-Sim.h:114
_direction_t
Definition: ROOT-Sim.h:110
square grid topology
Definition: ROOT-Sim.h:91
DIRECTION_NW.
Definition: ROOT-Sim.h:119
double GetValueTopology(unsigned from, unsigned to)
Definition: topology.c:288
_topology_geometry_t
Definition: ROOT-Sim.h:88
a torus shaped grid topology (a wrapping around square topology)
Definition: ROOT-Sim.h:94
DIRECTION_S.
Definition: ROOT-Sim.h:115
double Gamma(int ia)
Definition: numerical.c:179
double Poisson(void)
Definition: numerical.c:223
hexagonal grid topology
Definition: ROOT-Sim.h:90
double simtime_t
This defines the type with whom timestamps are represented.
Definition: ROOT-Sim.h:55
void SetValueTopology(unsigned from, unsigned to, double value)
Definition: topology.c:261
decisions are taken at random but are weighted on the palatability of neighbours
Definition: ROOT-Sim.h:128
__attribute((weak)) extern struct argp model_argp
This can be implemented by the model for smart argument handling.
Definition: ROOT-Sim.h:134
enum _direction_t direction_t
void(* ScheduleNewEvent)(unsigned int receiver, simtime_t timestamp, unsigned int event_type, void *event_content, unsigned int event_size)
This is the function pointer to correctly set ScheduleNewEvent API version, depending if we&#39;re runnin...
Definition: communication.c:50
double Random(void)
Definition: numerical.c:80
#define max(a, b)
Macro to find the maximum among two values.
Definition: core.h:106
an arbitrary shaped topology
Definition: ROOT-Sim.h:96
a ring shaped topology direction
Definition: ROOT-Sim.h:93
arbitrary offset used to distinguish during debug different enums
Definition: ROOT-Sim.h:89
DIRECTION_SW.
Definition: ROOT-Sim.h:118
decisions on next hops are taken based on the costs undertaken to cross the boundaries ...
Definition: ROOT-Sim.h:127
a ring shaped topology walkable in a single direction
Definition: ROOT-Sim.h:92
_topology_type_t
Definition: ROOT-Sim.h:125
void SetState(void *new_state)
Definition: state.c:321
int Zipf(double skew, int limit)
Definition: numerical.c:237
DIRECTION_NE.
Definition: ROOT-Sim.h:117