Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
platform generation : add promoters and labelers support
authorJean-Baptiste Hervé <jean-baptiste.herve@esial.net>
Tue, 31 Jul 2012 15:02:01 +0000 (17:02 +0200)
committerJean-Baptiste Hervé <jean-baptiste.herve@esial.net>
Tue, 31 Jul 2012 15:02:01 +0000 (17:02 +0200)
Two fucntions register callback functions written by user to promote nodes or label links. Two other functions call the callback functions on each node or link.

include/simgrid/platf_generator.h
src/surf/platf_generator.c
src/surf/platf_generator_private.h

index 968ac6d..13c32de 100644 (file)
@@ -22,6 +22,9 @@ typedef enum {
 typedef struct s_context_node_t *context_node_t;
 typedef struct s_context_edge_t *context_edge_t;
 
+typedef void (*platf_promoter_cb_t) (context_node_t);
+typedef void (*platf_labeler_cb_t) (context_edge_t);
+
 XBT_PUBLIC(void) platf_random_seed(unsigned long seed[6]);
 
 XBT_PUBLIC(void) platf_graph_uniform(unsigned long node_count);
@@ -39,6 +42,12 @@ XBT_PUBLIC(void) platf_graph_promote_to_cluster(context_node_t node, sg_platf_cl
 
 XBT_PUBLIC(void) platf_graph_link_label(context_edge_t edge, sg_platf_link_cbarg_t parameters);
 
+XBT_PUBLIC(void) platf_graph_promoter(platf_promoter_cb_t promoter_callback);
+XBT_PUBLIC(void) platf_graph_labeler(platf_labeler_cb_t labeler_callback);
+
+XBT_PUBLIC(void) platf_do_promote(void);
+XBT_PUBLIC(void) platf_do_label(void);
+
 // WARNING : Only for debbugging ; should be removed when platform
 // generation works correctly
 XBT_PUBLIC(xbt_graph_t) platf_graph_get(void);
index d6e9f64..bdbfe41 100644 (file)
@@ -7,6 +7,8 @@
 #include <math.h>
 
 static xbt_graph_t platform_graph = NULL;
+static xbt_dynar_t promoter_dynar = NULL;
+static xbt_dynar_t labeler_dynar = NULL;
 
 static RngStream rng_stream = NULL;
 
@@ -62,6 +64,7 @@ void platf_node_connect(xbt_node_t node1, xbt_node_t node2) {
   context_edge_t edge_data = NULL;
   edge_data = xbt_new0(s_context_edge_t, 1);
   edge_data->id = ++last_link_id;
+  edge_data->labeled = FALSE;
   xbt_graph_new_edge(platform_graph, node1, node2, (void*)edge_data);
 }
 
@@ -235,6 +238,54 @@ void platf_graph_link_label(context_edge_t edge, sg_platf_link_cbarg_t parameter
   memcpy(&(edge->link_parameters), parameters, sizeof(s_sg_platf_link_cbarg_t));
 }
 
+void platf_graph_promoter(platf_promoter_cb_t promoter_callback) {
+  if(promoter_dynar == NULL) {
+    promoter_dynar = xbt_dynar_new(sizeof(platf_promoter_cb_t), NULL);
+  }
+  xbt_dynar_push(promoter_dynar, &promoter_callback);
+}
+
+void platf_graph_labeler(platf_labeler_cb_t labeler_callback) {
+  if(labeler_dynar == NULL) {
+    labeler_dynar = xbt_dynar_new(sizeof(void*), NULL);
+  }
+  xbt_dynar_push(labeler_dynar, &labeler_callback);
+}
+
+void platf_do_promote(void) {
+  platf_promoter_cb_t promoter_callback;
+  xbt_node_t graph_node = NULL;
+  xbt_dynar_t dynar_nodes = NULL;
+  context_node_t node = NULL;
+  unsigned int i, j;
+  dynar_nodes = xbt_graph_get_nodes(platform_graph);
+  xbt_dynar_foreach(dynar_nodes, i, graph_node) {
+    node = (context_node_t) xbt_graph_node_get_data(graph_node);
+    xbt_dynar_foreach(promoter_dynar, j, promoter_callback) {
+      if(node->kind != ROUTER)
+        break;
+      promoter_callback(node);
+    }
+  }
+}
+
+void platf_do_label(void) {
+  platf_labeler_cb_t labeler_callback;
+  xbt_edge_t graph_edge = NULL;
+  xbt_dynar_t dynar_edges = NULL;
+  context_edge_t edge = NULL;
+  unsigned int i, j;
+  dynar_edges = xbt_graph_get_edges(platform_graph);
+  xbt_dynar_foreach(dynar_edges, i, graph_edge) {
+    edge = (context_edge_t) xbt_graph_edge_get_data(graph_edge);
+    xbt_dynar_foreach(promoter_dynar, j, labeler_callback) {
+      if(edge->labeled == TRUE)
+        break;
+      labeler_callback(edge);
+    }
+  }
+}
+
 /* Functions used to generate interesting random values */
 
 double random_pareto(double min, double max, double K, double P, double ALPHA) {
index bdec97e..3b95d50 100644 (file)
@@ -17,6 +17,7 @@ typedef struct s_context_node_t {
 
 typedef struct s_context_edge_t {
   unsigned long id;
+  int labeled;
   s_sg_platf_link_cbarg_t link_parameters;
 } s_context_edge_t;