Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
3a2e44b58930d375917bb2716a81a695cf7d934c
[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 static unsigned long last_link_id = 0;
13
14 xbt_graph_t platf_graph_get(void) {
15   // We need some debug, so let's add this function
16   // WARNING : shold be removed when it becomes useless
17   return platform_graph;
18 }
19
20 void platf_random_seed(unsigned long seed[6]) {
21
22   if(rng_stream == NULL) {
23     //stream not created yet, we do it now
24     rng_stream = RngStream_CreateStream(NULL);
25   }
26   if(seed != NULL) {
27     RngStream_SetSeed(rng_stream, seed);
28   }
29 }
30
31 void platf_graph_init(unsigned long node_count) {
32   unsigned long i;
33   platform_graph = xbt_graph_new_graph(FALSE, NULL);
34   if(rng_stream == NULL) {
35     rng_stream = RngStream_CreateStream(NULL);
36   }
37
38   for(i=0 ; i<node_count ; i++) {
39     context_node_t node_data = NULL;
40     node_data = xbt_new(s_context_node_t, 1);
41     node_data->id = i+1;
42     node_data->x = 0;
43     node_data->y = 0;
44     node_data->degree = 0;
45     node_data->kind = ROUTER;
46     xbt_graph_new_node(platform_graph, (void*) node_data);
47   }
48
49   last_link_id = 0;
50
51 }
52
53 void platf_node_connect(xbt_node_t node1, xbt_node_t node2) {
54   context_node_t node1_data;
55   context_node_t node2_data;
56   node1_data = (context_node_t) xbt_graph_node_get_data(node1);
57   node2_data = (context_node_t) xbt_graph_node_get_data(node2);
58   node1_data->degree++;
59   node2_data->degree++;
60
61   unsigned long *link_id = xbt_new(unsigned long, 1);
62   *link_id = ++last_link_id;
63
64   xbt_graph_new_edge(platform_graph, node1, node2, (void*)link_id);
65 }
66
67 void platf_graph_uniform(unsigned long node_count) {
68   xbt_dynar_t dynar_nodes = NULL;
69   xbt_node_t graph_node = NULL;
70   context_node_t node_data = NULL;
71   unsigned int i;
72   platf_graph_init(node_count);
73   dynar_nodes = xbt_graph_get_nodes(platform_graph);
74   xbt_dynar_foreach(dynar_nodes, i, graph_node) {
75     node_data = (context_node_t) xbt_graph_node_get_data(graph_node);
76     node_data->x = RngStream_RandU01(rng_stream);
77     node_data->y = RngStream_RandU01(rng_stream);
78   }
79 }
80
81 void platf_graph_interconnect_star(void) {
82
83   xbt_dynar_t dynar_nodes = NULL;
84   xbt_node_t graph_node = NULL;
85   xbt_node_t first_node = NULL;
86   unsigned int i;
87
88   dynar_nodes = xbt_graph_get_nodes(platform_graph);
89   xbt_dynar_foreach(dynar_nodes, i, graph_node) {
90     if(i==0) {
91       //Ok, we get the first node, let's keep it somewhere...
92       first_node = graph_node;
93     } else {
94       //All the other nodes are connected to the first one
95       platf_node_connect(graph_node, first_node);
96     }
97   }
98 }