From 7f477f475e8bd79141d881a044c59e56a37c1eda Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jean-Baptiste=20Herv=C3=A9?= Date: Tue, 31 Jul 2012 17:02:01 +0200 Subject: [PATCH] platform generation : add promoters and labelers support 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 | 9 ++++++ src/surf/platf_generator.c | 51 ++++++++++++++++++++++++++++++ src/surf/platf_generator_private.h | 1 + 3 files changed, 61 insertions(+) diff --git a/include/simgrid/platf_generator.h b/include/simgrid/platf_generator.h index 968ac6dfa8..13c32debe8 100644 --- a/include/simgrid/platf_generator.h +++ b/include/simgrid/platf_generator.h @@ -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); diff --git a/src/surf/platf_generator.c b/src/surf/platf_generator.c index d6e9f64e5d..bdbfe41bfb 100644 --- a/src/surf/platf_generator.c +++ b/src/surf/platf_generator.c @@ -7,6 +7,8 @@ #include 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) { diff --git a/src/surf/platf_generator_private.h b/src/surf/platf_generator_private.h index bdec97e92d..3b95d508ac 100644 --- a/src/surf/platf_generator_private.h +++ b/src/surf/platf_generator_private.h @@ -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; -- 2.20.1