Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
First step to implement a platform generator in Simgrid
[simgrid.git] / src / surf / platf_generator.c
1
2
3 #include <simgrid/platf_generator.h>
4 #include <xbt.h>
5 #include <xbt/graph.h>
6 #include <xbt/RngStream.h>
7
8
9 typedef struct {
10   double x, y;
11   int degree;
12   e_platf_node_kind kind;
13 } s_context_node_t, *context_node_t;
14
15 static xbt_graph_t platform_graph = NULL;
16
17 static RngStream rng_stream = NULL;
18
19 void platf_random_seed(unsigned long seed[6]) {
20   
21   if(rng_stream == NULL) {
22     //stream not created yet, we do it now
23     rng_stream = RngStream_CreateStream(NULL);
24   }
25   if(seed != NULL) {
26     RngStream_SetSeed(rng_stream, seed);
27   }
28 }
29
30 void platf_graph_init(int node_count, e_platf_placement placement) {
31   int i;
32   platform_graph = xbt_graph_new_graph(TRUE, NULL);
33   if(rng_stream == NULL) {
34     rng_stream = RngStream_CreateStream(NULL);
35   }
36   
37   for(i=0 ; i<node_count ; i++) {
38     context_node_t node_data = NULL;
39     node_data = xbt_new(s_context_node_t, 1);
40     switch(placement) {
41       case UNIFORM:
42         node_data->x = RngStream_RandU01(rng_stream);
43         node_data->y = RngStream_RandU01(rng_stream);
44         break;
45       case HEAVY_TAILED:
46         //Not implemented...
47         THROW_UNIMPLEMENTED;
48     }
49     node_data->degree = 0;
50     node_data->kind = ROUTER;
51     xbt_graph_new_node(platform_graph, (void*) node_data);
52   }
53 }