3 #include "simgrid/platf_generator.h"
4 #include "platf_generator_private.h"
6 #include "xbt/RngStream.h"
9 static xbt_graph_t platform_graph = NULL;
10 static xbt_dynar_t promoter_dynar = NULL;
11 static xbt_dynar_t labeler_dynar = NULL;
13 static RngStream rng_stream = NULL;
15 static unsigned long last_link_id = 0;
17 xbt_graph_t platf_graph_get(void) {
18 // We need some debug, so let's add this function
19 // WARNING : shold be removed when it becomes useless
20 return platform_graph;
23 void platf_random_seed(unsigned long seed[6]) {
25 if(rng_stream == NULL) {
26 //stream not created yet, we do it now
27 rng_stream = RngStream_CreateStream(NULL);
30 RngStream_SetSeed(rng_stream, seed);
34 void platf_graph_init(unsigned long node_count) {
36 platform_graph = xbt_graph_new_graph(FALSE, NULL);
37 if(rng_stream == NULL) {
38 rng_stream = RngStream_CreateStream(NULL);
41 for(i=0 ; i<node_count ; i++) {
42 context_node_t node_data = NULL;
43 node_data = xbt_new0(s_context_node_t, 1);
47 node_data->degree = 0;
48 node_data->kind = ROUTER;
49 xbt_graph_new_node(platform_graph, (void*) node_data);
56 void platf_node_connect(xbt_node_t node1, xbt_node_t node2) {
57 context_node_t node1_data;
58 context_node_t node2_data;
59 node1_data = (context_node_t) xbt_graph_node_get_data(node1);
60 node2_data = (context_node_t) xbt_graph_node_get_data(node2);
64 context_edge_t edge_data = NULL;
65 edge_data = xbt_new0(s_context_edge_t, 1);
66 edge_data->id = ++last_link_id;
67 edge_data->length = platf_node_distance(node1, node2);
68 edge_data->labeled = FALSE;
69 xbt_graph_new_edge(platform_graph, node1, node2, (void*)edge_data);
72 double platf_node_distance(xbt_node_t node1, xbt_node_t node2) {
73 context_node_t node1_data;
74 context_node_t node2_data;
78 node1_data = (context_node_t) xbt_graph_node_get_data(node1);
79 node2_data = (context_node_t) xbt_graph_node_get_data(node2);
80 delta_x = node1_data->x - node2_data->x;
81 delta_y = node1_data->y - node2_data->y;
82 distance = sqrt(delta_x*delta_x + delta_y*delta_y);
86 void platf_graph_uniform(unsigned long node_count) {
87 xbt_dynar_t dynar_nodes = NULL;
88 xbt_node_t graph_node = NULL;
89 context_node_t node_data = NULL;
91 platf_graph_init(node_count);
92 dynar_nodes = xbt_graph_get_nodes(platform_graph);
93 xbt_dynar_foreach(dynar_nodes, i, graph_node) {
94 node_data = (context_node_t) xbt_graph_node_get_data(graph_node);
95 node_data->x = RngStream_RandU01(rng_stream);
96 node_data->y = RngStream_RandU01(rng_stream);
100 void platf_graph_heavytailed(unsigned long node_count) {
101 xbt_dynar_t dynar_nodes = NULL;
102 xbt_node_t graph_node = NULL;
103 context_node_t node_data = NULL;
105 platf_graph_init(node_count);
106 dynar_nodes = xbt_graph_get_nodes(platform_graph);
107 xbt_dynar_foreach(dynar_nodes, i, graph_node) {
108 node_data = (context_node_t) xbt_graph_node_get_data(graph_node);
109 node_data->x = random_pareto(0, 1, 1.0/*K*/, 10e9/*P*/, 1.0/*alpha*/);
110 node_data->y = random_pareto(0, 1, 1.0/*K*/, 10e9/*P*/, 1.0/*alpha*/);
114 void platf_graph_interconnect_star(void) {
115 /* All the nodes are connected to the first one */
116 xbt_dynar_t dynar_nodes = NULL;
117 xbt_node_t graph_node = NULL;
118 xbt_node_t first_node = NULL;
121 dynar_nodes = xbt_graph_get_nodes(platform_graph);
122 xbt_dynar_foreach(dynar_nodes, i, graph_node) {
124 //Ok, we get the first node, let's keep it somewhere...
125 first_node = graph_node;
127 //All the other nodes are connected to the first one
128 platf_node_connect(graph_node, first_node);
133 void platf_graph_interconnect_line(void) {
134 /* Node are connected to the previous and the next node, in a line */
135 xbt_dynar_t dynar_nodes = NULL;
136 xbt_node_t graph_node = NULL;
137 xbt_node_t old_node = NULL;
140 dynar_nodes = xbt_graph_get_nodes(platform_graph);
141 xbt_dynar_foreach(dynar_nodes, i, graph_node) {
142 if(old_node != NULL) {
143 platf_node_connect(graph_node, old_node);
145 old_node = graph_node;
149 void platf_graph_interconnect_ring(void) {
150 /* Create a simple topology where all nodes are connected along a ring */
151 xbt_dynar_t dynar_nodes = NULL;
152 xbt_node_t graph_node = NULL;
153 xbt_node_t old_node = NULL;
154 xbt_node_t first_node = NULL;
157 dynar_nodes = xbt_graph_get_nodes(platform_graph);
158 xbt_dynar_foreach(dynar_nodes, i, graph_node) {
160 // this is the first node, let's keep it somewhere
161 first_node = graph_node;
163 //connect each node to the previous one
164 platf_node_connect(graph_node, old_node);
166 old_node = graph_node;
168 //we still have to connect the first and the last node together
169 platf_node_connect(first_node, graph_node);
172 void platf_graph_interconnect_clique(void) {
173 /* Create a simple topology where all nodes are connected to each other, in a clique manner */
174 xbt_dynar_t dynar_nodes = NULL;
175 xbt_node_t first_node = NULL;
176 xbt_node_t second_node = NULL;
179 dynar_nodes = xbt_graph_get_nodes(platform_graph);
180 xbt_dynar_foreach(dynar_nodes, i, first_node) {
181 xbt_dynar_foreach(dynar_nodes, j, second_node) {
182 platf_node_connect(first_node, second_node);
187 void platf_graph_interconnect_uniform(double alpha) {
188 /* Creates a topology where the probability to connect two nodes is uniform (unrealistic, but simple)
189 alpha : Probability for two nodes to get connected */
190 xbt_dynar_t dynar_nodes = NULL;
191 xbt_node_t first_node = NULL;
192 xbt_node_t second_node = NULL;
195 dynar_nodes = xbt_graph_get_nodes(platform_graph);
196 xbt_dynar_foreach(dynar_nodes, i, first_node) {
197 xbt_dynar_foreach(dynar_nodes, j, second_node) {
200 if(RngStream_RandU01(rng_stream) < alpha) {
201 platf_node_connect(first_node, second_node);
207 void platf_graph_interconnect_exponential(double alpha) {
208 /* Create a topology where the probability follows an exponential law
209 Number of edges increases with alpha */
210 xbt_dynar_t dynar_nodes = NULL;
211 xbt_node_t first_node = NULL;
212 xbt_node_t second_node = NULL;
214 double L = sqrt(2.0); /* L = c*sqrt(2); c=side of placement square */
215 dynar_nodes = xbt_graph_get_nodes(platform_graph);
216 xbt_dynar_foreach(dynar_nodes, i, first_node) {
217 xbt_dynar_foreach(dynar_nodes, j, second_node) {
220 double d = platf_node_distance(first_node, second_node);
221 if(RngStream_RandU01(rng_stream) < alpha*exp(-d/(L-d))) {
222 platf_node_connect(first_node, second_node);
228 void platf_graph_interconnect_waxman(double alpha, double beta) {
229 /* Create a topology where the probability follows the model of Waxman
230 * (see Waxman, Routing of Multipoint Connections, IEEE J. on Selected Areas in Comm., 1988)
232 * Number of edges increases with alpha
233 * edge length heterogeneity increases with beta
235 xbt_dynar_t dynar_nodes = NULL;
236 xbt_node_t first_node = NULL;
237 xbt_node_t second_node = NULL;
239 double L = sqrt(2.0); /* L = c*sqrt(2); c=side of placement square */
240 dynar_nodes = xbt_graph_get_nodes(platform_graph);
241 xbt_dynar_foreach(dynar_nodes, i, first_node) {
242 xbt_dynar_foreach(dynar_nodes, j, second_node) {
245 double d = platf_node_distance(first_node, second_node);
246 if(RngStream_RandU01(rng_stream) < alpha*exp(-d/(L*beta))) {
247 platf_node_connect(first_node, second_node);
253 void platf_graph_interconnect_zegura(double alpha, double beta, double r) {
254 /* Create a topology where the probability follows the model of Zegura
255 * (see Zegura, Calvert, Donahoo, A quantitative comparison of graph-based models
256 * for Internet topology, IEEE/ACM Transactions on Networking, 1997.)
258 * alpha : Probability of connexion for short edges
259 * beta : Probability of connexion for long edges
260 * r : Limit between long and short edges (between 0 and sqrt(2) since nodes are placed on the unit square)
262 xbt_dynar_t dynar_nodes = NULL;
263 xbt_node_t first_node = NULL;
264 xbt_node_t second_node = NULL;
266 dynar_nodes = xbt_graph_get_nodes(platform_graph);
267 xbt_dynar_foreach(dynar_nodes, i, first_node) {
268 xbt_dynar_foreach(dynar_nodes, j, second_node) {
271 double d = platf_node_distance(first_node, second_node);
272 double proba = d < r ? alpha : beta;
273 if(RngStream_RandU01(rng_stream) < proba) {
274 platf_node_connect(first_node, second_node);
280 void platf_graph_interconnect_barabasi(void) {
281 /* Create a topology constructed according to the Barabasi-Albert algorithm (follows power laws)
282 (see Barabasi and Albert, Emergence of scaling in random networks, Science 1999, num 59, p509-512.) */
283 xbt_dynar_t dynar_nodes = NULL;
284 xbt_node_t first_node = NULL;
285 xbt_node_t second_node = NULL;
286 context_node_t node_data = NULL;
288 unsigned long sum = 0;
289 dynar_nodes = xbt_graph_get_nodes(platform_graph);
290 xbt_dynar_foreach(dynar_nodes, i, first_node) {
291 xbt_dynar_foreach(dynar_nodes, j, second_node) {
294 node_data = xbt_graph_node_get_data(second_node);
295 if(sum==0 || RngStream_RandU01(rng_stream) < ((double)(node_data->degree)/ (double)sum)) {
296 platf_node_connect(first_node, second_node);
303 void platf_graph_promote_to_host(context_node_t node, sg_platf_host_cbarg_t parameters) {
305 memcpy(&(node->host_parameters), parameters, sizeof(s_sg_platf_host_cbarg_t));
308 void platf_graph_promote_to_cluster(context_node_t node, sg_platf_cluster_cbarg_t parameters) {
309 node->kind = CLUSTER;
310 memcpy(&(node->cluster_parameters), parameters, sizeof(s_sg_platf_cluster_cbarg_t));
313 void platf_graph_link_label(context_edge_t edge, sg_platf_link_cbarg_t parameters) {
314 memcpy(&(edge->link_parameters), parameters, sizeof(s_sg_platf_link_cbarg_t));
317 void platf_graph_promoter(platf_promoter_cb_t promoter_callback) {
318 if(promoter_dynar == NULL) {
319 promoter_dynar = xbt_dynar_new(sizeof(platf_promoter_cb_t), NULL);
321 xbt_dynar_push(promoter_dynar, &promoter_callback);
324 void platf_graph_labeler(platf_labeler_cb_t labeler_callback) {
325 if(labeler_dynar == NULL) {
326 labeler_dynar = xbt_dynar_new(sizeof(void*), NULL);
328 xbt_dynar_push(labeler_dynar, &labeler_callback);
331 void platf_do_promote(void) {
332 platf_promoter_cb_t promoter_callback;
333 xbt_node_t graph_node = NULL;
334 xbt_dynar_t dynar_nodes = NULL;
335 context_node_t node = NULL;
337 dynar_nodes = xbt_graph_get_nodes(platform_graph);
338 xbt_dynar_foreach(dynar_nodes, i, graph_node) {
339 node = (context_node_t) xbt_graph_node_get_data(graph_node);
340 xbt_dynar_foreach(promoter_dynar, j, promoter_callback) {
341 if(node->kind != ROUTER)
343 promoter_callback(node);
348 void platf_do_label(void) {
349 platf_labeler_cb_t labeler_callback;
350 xbt_edge_t graph_edge = NULL;
351 xbt_dynar_t dynar_edges = NULL;
352 context_edge_t edge = NULL;
354 dynar_edges = xbt_graph_get_edges(platform_graph);
355 xbt_dynar_foreach(dynar_edges, i, graph_edge) {
356 edge = (context_edge_t) xbt_graph_edge_get_data(graph_edge);
357 xbt_dynar_foreach(promoter_dynar, j, labeler_callback) {
358 if(edge->labeled == TRUE)
360 labeler_callback(edge);
365 /* Functions used to generate interesting random values */
367 double random_pareto(double min, double max, double K, double P, double ALPHA) {
368 double x = RngStream_RandU01(rng_stream);
369 double den = pow(1.0 - x + x*pow(K/P, ALPHA), 1.0/ALPHA);
370 double res = (1/den);
371 res += min - 1; // pareto is on [1, infinity) by default