Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Platform generation : Add a function to interconnect nodes
[simgrid.git] / src / surf / platf_generator.c
1
2
3 #include <simgrid/platf_generator.h>
4 #include "platf_generator_private.h"
5 #include <xbt.h>
6 #include <xbt/RngStream.h>
7
8 static xbt_graph_t platform_graph = NULL;
9
10 static RngStream rng_stream = NULL;
11
12 void platf_random_seed(unsigned long seed[6]) {
13
14   if(rng_stream == NULL) {
15     //stream not created yet, we do it now
16     rng_stream = RngStream_CreateStream(NULL);
17   }
18   if(seed != NULL) {
19     RngStream_SetSeed(rng_stream, seed);
20   }
21 }
22
23 void platf_graph_init(int node_count) {
24   int i;
25   platform_graph = xbt_graph_new_graph(FALSE, NULL);
26   if(rng_stream == NULL) {
27     rng_stream = RngStream_CreateStream(NULL);
28   }
29
30   for(i=0 ; i<node_count ; i++) {
31     context_node_t node_data = NULL;
32     node_data = xbt_new(s_context_node_t, 1);
33     node_data->x = 0;
34     node_data->y = 0;
35     node_data->degree = 0;
36     node_data->kind = ROUTER;
37     xbt_graph_new_node(platform_graph, (void*) node_data);
38   }
39 }
40
41 void platf_node_connect(xbt_node_t node1, xbt_node_t node2) {
42   context_node_t node1_data;
43   context_node_t node2_data;
44   node1_data = (context_node_t) xbt_graph_node_get_data(node1);
45   node2_data = (context_node_t) xbt_graph_node_get_data(node2);
46   node1_data->degree++;
47   node2_data->degree++;
48   xbt_graph_new_edge(platform_graph, node1, node2, NULL);
49 }
50
51 void platf_graph_uniform(int node_count) {
52   xbt_dynar_t dynar_nodes = NULL;
53   xbt_node_t graph_node = NULL;
54   context_node_t node_data = NULL;
55   unsigned int i;
56   platf_graph_init(node_count);
57   dynar_nodes = xbt_graph_get_nodes(platform_graph);
58   xbt_dynar_foreach(dynar_nodes, i, graph_node) {
59     node_data = (context_node_t) xbt_graph_node_get_data(graph_node);
60     node_data->x = RngStream_RandU01(rng_stream);
61     node_data->y = RngStream_RandU01(rng_stream);
62   }
63 }
64
65 void platf_graph_interconnect_star(void) {
66
67   xbt_dynar_t dynar_nodes = NULL;
68   xbt_node_t graph_node = NULL;
69   xbt_node_t first_node = NULL;
70   unsigned int i;
71
72   dynar_nodes = xbt_graph_get_nodes(platform_graph);
73   xbt_dynar_foreach(dynar_nodes, i, graph_node) {
74     if(i==0) {
75       //Ok, we get the first node, let's keep it somewhere...
76       first_node = graph_node;
77     } else {
78       //All the other nodes are connected to the first one
79       platf_node_connect(graph_node, first_node);
80     }
81   }
82 }