3 #include <simgrid/platf_generator.h>
4 #include "platf_generator_private.h"
6 #include <xbt/RngStream.h>
8 static xbt_graph_t platform_graph = NULL;
10 static RngStream rng_stream = NULL;
12 static unsigned long last_link_id = 0;
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;
20 void platf_random_seed(unsigned long seed[6]) {
22 if(rng_stream == NULL) {
23 //stream not created yet, we do it now
24 rng_stream = RngStream_CreateStream(NULL);
27 RngStream_SetSeed(rng_stream, seed);
31 void platf_graph_init(unsigned long node_count) {
33 platform_graph = xbt_graph_new_graph(FALSE, NULL);
34 if(rng_stream == NULL) {
35 rng_stream = RngStream_CreateStream(NULL);
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);
44 node_data->degree = 0;
45 node_data->kind = ROUTER;
46 xbt_graph_new_node(platform_graph, (void*) node_data);
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);
61 unsigned long *link_id = xbt_new(unsigned long, 1);
62 *link_id = ++last_link_id;
64 xbt_graph_new_edge(platform_graph, node1, node2, (void*)link_id);
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;
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);
81 void platf_graph_interconnect_star(void) {
83 xbt_dynar_t dynar_nodes = NULL;
84 xbt_node_t graph_node = NULL;
85 xbt_node_t first_node = NULL;
88 dynar_nodes = xbt_graph_get_nodes(platform_graph);
89 xbt_dynar_foreach(dynar_nodes, i, graph_node) {
91 //Ok, we get the first node, let's keep it somewhere...
92 first_node = graph_node;
94 //All the other nodes are connected to the first one
95 platf_node_connect(graph_node, first_node);