Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Platform generation : Add a function to interconnect nodes
authorJean-Baptiste Hervé <jean-baptiste.herve@esial.net>
Thu, 26 Jul 2012 14:12:57 +0000 (16:12 +0200)
committerJean-Baptiste Hervé <jean-baptiste.herve@esial.net>
Thu, 26 Jul 2012 14:12:57 +0000 (16:12 +0200)
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
src/surf/platf_generator.c
src/surf/platf_generator_private.h

index c36dcdf..5f3d506 100644 (file)
@@ -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_uniform(int node_count);
 
+XBT_PUBLIC(void) platf_graph_interconnect_star(void);
+
 #endif              /* SG_PLATF_GEN_H */
 #endif              /* SG_PLATF_GEN_H */
index 0acd807..c8f4937 100644 (file)
@@ -3,7 +3,6 @@
 #include <simgrid/platf_generator.h>
 #include "platf_generator_private.h"
 #include <xbt.h>
 #include <simgrid/platf_generator.h>
 #include "platf_generator_private.h"
 #include <xbt.h>
-#include <xbt/graph.h>
 #include <xbt/RngStream.h>
 
 static xbt_graph_t platform_graph = NULL;
 #include <xbt/RngStream.h>
 
 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;
 
 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);
   }
   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;
 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);
   }
 }
     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);
+    }
+  }
+}
index db486a9..153c1bf 100644 (file)
@@ -1,6 +1,8 @@
 #ifndef SG_PLATF_GEN_PRIVATE_H
 #define SG_PLATF_GEN_PRIVATE_H
 
 #ifndef SG_PLATF_GEN_PRIVATE_H
 #define SG_PLATF_GEN_PRIVATE_H
 
+#include <xbt/graph.h>
+
 typedef struct {
   double x, y;
   int degree;
 typedef struct {
   double x, y;
   int degree;
@@ -9,4 +11,6 @@ typedef struct {
 
 void platf_graph_init(int node_count);
 
 
 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 */
 #endif      /* SG_PLATF_GEN_PRIVATE_H */