From 8648556e63e965fc3976fae86c4cb7c44b827280 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jean-Baptiste=20Herv=C3=A9?= Date: Thu, 26 Jul 2012 16:12:57 +0200 Subject: [PATCH] Platform generation : Add a function to interconnect nodes More precisely, add a function to connect all nodes following the "star" algorithm. A function ahs also been added to connect two nodes together. --- include/simgrid/platf_generator.h | 2 ++ src/surf/platf_generator.c | 32 ++++++++++++++++++++++++++++-- src/surf/platf_generator_private.h | 4 ++++ 3 files changed, 36 insertions(+), 2 deletions(-) diff --git a/include/simgrid/platf_generator.h b/include/simgrid/platf_generator.h index c36dcdf6d4..5f3d5069a8 100644 --- a/include/simgrid/platf_generator.h +++ b/include/simgrid/platf_generator.h @@ -21,4 +21,6 @@ XBT_PUBLIC(void) platf_random_seed(unsigned long seed[6]); XBT_PUBLIC(void) platf_graph_uniform(int node_count); +XBT_PUBLIC(void) platf_graph_interconnect_star(void); + #endif /* SG_PLATF_GEN_H */ diff --git a/src/surf/platf_generator.c b/src/surf/platf_generator.c index 0acd807a1a..c8f49372c9 100644 --- a/src/surf/platf_generator.c +++ b/src/surf/platf_generator.c @@ -3,7 +3,6 @@ #include #include "platf_generator_private.h" #include -#include #include static xbt_graph_t platform_graph = NULL; @@ -23,7 +22,7 @@ void platf_random_seed(unsigned long seed[6]) { void platf_graph_init(int node_count) { int i; - platform_graph = xbt_graph_new_graph(TRUE, NULL); + platform_graph = xbt_graph_new_graph(FALSE, NULL); if(rng_stream == NULL) { rng_stream = RngStream_CreateStream(NULL); } @@ -39,6 +38,16 @@ void platf_graph_init(int node_count) { } } +void platf_node_connect(xbt_node_t node1, xbt_node_t node2) { + context_node_t node1_data; + context_node_t node2_data; + node1_data = (context_node_t) xbt_graph_node_get_data(node1); + node2_data = (context_node_t) xbt_graph_node_get_data(node2); + node1_data->degree++; + node2_data->degree++; + xbt_graph_new_edge(platform_graph, node1, node2, NULL); +} + void platf_graph_uniform(int node_count) { xbt_dynar_t dynar_nodes = NULL; xbt_node_t graph_node = NULL; @@ -52,3 +61,22 @@ void platf_graph_uniform(int node_count) { node_data->y = RngStream_RandU01(rng_stream); } } + +void platf_graph_interconnect_star(void) { + + xbt_dynar_t dynar_nodes = NULL; + xbt_node_t graph_node = NULL; + xbt_node_t first_node = NULL; + unsigned int i; + + dynar_nodes = xbt_graph_get_nodes(platform_graph); + xbt_dynar_foreach(dynar_nodes, i, graph_node) { + if(i==0) { + //Ok, we get the first node, let's keep it somewhere... + first_node = graph_node; + } else { + //All the other nodes are connected to the first one + platf_node_connect(graph_node, first_node); + } + } +} diff --git a/src/surf/platf_generator_private.h b/src/surf/platf_generator_private.h index db486a99a3..153c1bfaa9 100644 --- a/src/surf/platf_generator_private.h +++ b/src/surf/platf_generator_private.h @@ -1,6 +1,8 @@ #ifndef SG_PLATF_GEN_PRIVATE_H #define SG_PLATF_GEN_PRIVATE_H +#include + typedef struct { double x, y; int degree; @@ -9,4 +11,6 @@ typedef struct { void platf_graph_init(int node_count); +void platf_node_connect(xbt_node_t node1, xbt_node_t node2); + #endif /* SG_PLATF_GEN_PRIVATE_H */ -- 2.20.1