X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/cf108868b4eeed4d0d9d343bc68557d7814e18c0..36b13d80aa850a3ce2ac8255f384ac79ec70fb6f:/src/surf/instr_routing.cpp diff --git a/src/surf/instr_routing.cpp b/src/surf/instr_routing.cpp index e79947ac4c..c52abdad65 100644 --- a/src/surf/instr_routing.cpp +++ b/src/surf/instr_routing.cpp @@ -6,13 +6,16 @@ #include "src/instr/instr_private.h" -#include "src/surf/surf_private.h" +#include "src/surf/AsImpl.hpp" +#include "simgrid/s4u/engine.hpp" +#include "surf/surf.h" +#include "src/surf/xml/platf_private.hpp" #include "xbt/graph.h" XBT_LOG_NEW_DEFAULT_SUBCATEGORY (instr_routing, instr, "Tracing platform hierarchy"); static int platform_created = 0; /* indicate whether the platform file has been traced */ -static xbt_dynar_t currentContainer = NULL; /* push and pop, used only in creation */ +static xbt_dynar_t currentContainer = nullptr; /* push and pop, used only in creation */ static const char *instr_node_name (xbt_node_t node) { @@ -28,7 +31,7 @@ static container_t lowestCommonAncestor (container_t a1, container_t a2) if (a1->father == a2->father) return a1->father; //create an array with all ancestors of a1 - xbt_dynar_t ancestors_a1 = xbt_dynar_new(sizeof(container_t), NULL); + xbt_dynar_t ancestors_a1 = xbt_dynar_new(sizeof(container_t), nullptr); container_t p; p = a1->father; while (p){ @@ -37,7 +40,7 @@ static container_t lowestCommonAncestor (container_t a1, container_t a2) } //create an array with all ancestors of a2 - xbt_dynar_t ancestors_a2 = xbt_dynar_new(sizeof(container_t), NULL); + xbt_dynar_t ancestors_a2 = xbt_dynar_new(sizeof(container_t), nullptr); p = a2->father; while (p){ xbt_dynar_push_as (ancestors_a2, container_t, p); @@ -45,7 +48,7 @@ static container_t lowestCommonAncestor (container_t a1, container_t a2) } //find the lowest ancestor - p = NULL; + p = nullptr; int i = xbt_dynar_length (ancestors_a1) - 1; int j = xbt_dynar_length (ancestors_a2) - 1; while (i >= 0 && j >= 0){ @@ -78,7 +81,7 @@ static void linkContainers (container_t src, container_t dst, xbt_dict_t filter) xbt_die ("common father unknown, this is a tracing problem"); } - if (filter != NULL){ + if (filter != nullptr){ //check if we already register this pair (we only need one direction) char aux1[INSTR_DEFAULT_STR_SIZE], aux2[INSTR_DEFAULT_STR_SIZE]; snprintf (aux1, INSTR_DEFAULT_STR_SIZE, "%s%s", src->name, dst->name); @@ -93,8 +96,8 @@ static void linkContainers (container_t src, container_t dst, xbt_dict_t filter) } //ok, not found, register it - xbt_dict_set (filter, aux1, xbt_strdup ("1"), NULL); - xbt_dict_set (filter, aux2, xbt_strdup ("1"), NULL); + xbt_dict_set (filter, aux1, xbt_strdup ("1"), nullptr); + xbt_dict_set (filter, aux2, xbt_strdup ("1"), nullptr); } //declare type @@ -104,12 +107,12 @@ static void linkContainers (container_t src, container_t dst, xbt_dict_t filter) src->type->name, src->type->id, dst->type->name, dst->type->id); type_t link_type = PJ_type_get_or_null (link_typename, father->type); - if (link_type == NULL){ + if (link_type == nullptr){ link_type = PJ_type_link_new (link_typename, father->type, src->type, dst->type); } //register EDGE types for triva configuration - xbt_dict_set (trivaEdgeTypes, link_type->name, xbt_strdup("1"), NULL); + xbt_dict_set (trivaEdgeTypes, link_type->name, xbt_strdup("1"), nullptr); //create the link static long long counter = 0; @@ -122,35 +125,34 @@ static void linkContainers (container_t src, container_t dst, xbt_dict_t filter) XBT_DEBUG (" linkContainers %s <-> %s", src->name, dst->name); } -static void recursiveGraphExtraction (AS_t rc, container_t container, xbt_dict_t filter) +static void recursiveGraphExtraction (simgrid::s4u::As *as, container_t container, xbt_dict_t filter) { if (!TRACE_platform_topology()){ XBT_DEBUG("Graph extraction disabled by user."); return; } - XBT_DEBUG ("Graph extraction for routing_component = %s", surf_AS_get_name(rc)); - if (!xbt_dict_is_empty(surf_AS_get_routing_sons(rc))){ - xbt_dict_cursor_t cursor = NULL; + XBT_DEBUG ("Graph extraction for routing_component = %s", as->name()); + if (!xbt_dict_is_empty(as->children())){ + xbt_dict_cursor_t cursor = nullptr; AS_t rc_son; char *child_name; //bottom-up recursion - xbt_dict_foreach(surf_AS_get_routing_sons(rc), cursor, child_name, rc_son) { - container_t child_container = (container_t) xbt_dict_get ( - container->children, surf_AS_get_name(rc_son)); + xbt_dict_foreach(as->children(), cursor, child_name, rc_son) { + container_t child_container = (container_t) xbt_dict_get (container->children, rc_son->name()); recursiveGraphExtraction (rc_son, child_container, filter); } } { - xbt_graph_t graph = xbt_graph_new_graph (0, NULL); - xbt_dict_t nodes = xbt_dict_new_homogeneous(NULL); - xbt_dict_t edges = xbt_dict_new_homogeneous(NULL); - xbt_edge_t edge = NULL; + xbt_graph_t graph = xbt_graph_new_graph (0, nullptr); + xbt_dict_t nodes = xbt_dict_new_homogeneous(nullptr); + xbt_dict_t edges = xbt_dict_new_homogeneous(nullptr); + xbt_edge_t edge = nullptr; - xbt_dict_cursor_t cursor = NULL; + xbt_dict_cursor_t cursor = nullptr; char *edge_name; - surf_AS_get_graph(rc, graph, nodes, edges); + static_cast(as)->getGraph(graph, nodes, edges); xbt_dict_foreach(edges,cursor,edge_name,edge) { linkContainers( PJ_container_get((const char*) edge->src->data), @@ -158,7 +160,7 @@ static void recursiveGraphExtraction (AS_t rc, container_t container, xbt_dict_t } xbt_dict_free (&nodes); xbt_dict_free (&edges); - xbt_graph_free_graph(graph, xbt_free_f, xbt_free_f, NULL); + xbt_graph_free_graph(graph, xbt_free_f, xbt_free_f, nullptr); } } @@ -169,25 +171,23 @@ void sg_instr_AS_begin(sg_platf_AS_cbarg_t AS) { const char*id = AS->id; - if (PJ_container_get_root() == NULL){ + if (PJ_container_get_root() == nullptr){ PJ_container_alloc (); PJ_type_alloc(); - container_t root = PJ_container_new (id, INSTR_AS, NULL); + container_t root = PJ_container_new (id, INSTR_AS, nullptr); PJ_container_set_root (root); if (TRACE_smpi_is_enabled()) { - if (!TRACE_smpi_is_grouped()){ - type_t mpi = PJ_type_get_or_null ("MPI", root->type); - if (mpi == NULL){ - mpi = PJ_type_container_new("MPI", root->type); - PJ_type_state_new ("MPI_STATE", mpi); - PJ_type_link_new ("MPI_LINK", PJ_type_get_root(), mpi, mpi); - } + type_t mpi = PJ_type_get_or_null ("MPI", root->type); + if (mpi == nullptr){ + mpi = PJ_type_container_new("MPI", root->type); + if (!TRACE_smpi_is_grouped()) PJ_type_state_new ("MPI_STATE", mpi); + PJ_type_link_new ("MPI_LINK", PJ_type_get_root(), mpi, mpi); } } if (TRACE_needs_platform()){ - currentContainer = xbt_dynar_new (sizeof(container_t), NULL); + currentContainer = xbt_dynar_new (sizeof(container_t), nullptr); xbt_dynar_push (currentContainer, &root); } return; @@ -226,7 +226,7 @@ static void instr_routing_parse_start_link (sg_platf_link_cbarg_t link) xbt_dynar_push_as (links_to_create, char*, strdup(link->id)); } - char *link_name = NULL; + char *link_name = nullptr; unsigned int i; xbt_dynar_foreach (links_to_create, i, link_name){ @@ -234,19 +234,19 @@ static void instr_routing_parse_start_link (sg_platf_link_cbarg_t link) if ((TRACE_categorized() || TRACE_uncategorized() || TRACE_platform()) && (! TRACE_disable_link())) { type_t bandwidth = PJ_type_get_or_null ("bandwidth", container->type); - if (bandwidth == NULL){ - bandwidth = PJ_type_variable_new ("bandwidth", NULL, container->type); + if (bandwidth == nullptr){ + bandwidth = PJ_type_variable_new ("bandwidth", nullptr, container->type); } type_t latency = PJ_type_get_or_null ("latency", container->type); - if (latency == NULL){ - latency = PJ_type_variable_new ("latency", NULL, container->type); + if (latency == nullptr){ + latency = PJ_type_variable_new ("latency", nullptr, container->type); } new_pajeSetVariable (0, container, bandwidth, bandwidth_value); new_pajeSetVariable (0, container, latency, latency_value); } if (TRACE_uncategorized()){ type_t bandwidth_used = PJ_type_get_or_null ("bandwidth_used", container->type); - if (bandwidth_used == NULL){ + if (bandwidth_used == nullptr){ PJ_type_variable_new ("bandwidth_used", "0.5 0.5 0.5", container->type); } } @@ -262,33 +262,32 @@ void sg_instr_new_host(sg_platf_host_cbarg_t host) if ((TRACE_categorized() || TRACE_uncategorized() || TRACE_platform()) && (! TRACE_disable_speed())) { type_t speed = PJ_type_get_or_null ("power", container->type); - if (speed == NULL){ - speed = PJ_type_variable_new ("power", NULL, container->type); + if (speed == nullptr){ + speed = PJ_type_variable_new ("power", nullptr, container->type); } double current_speed_state; - xbt_dynar_get_cpy(host->speed_peak, host->pstate, ¤t_speed_state); + xbt_dynar_get_cpy(host->speed_per_pstate, host->pstate, ¤t_speed_state); new_pajeSetVariable (0, container, speed, current_speed_state); } if (TRACE_uncategorized()){ type_t speed_used = PJ_type_get_or_null ("power_used", container->type); - if (speed_used == NULL){ + if (speed_used == nullptr){ PJ_type_variable_new ("power_used", "0.5 0.5 0.5", container->type); } } if (TRACE_smpi_is_enabled() && TRACE_smpi_is_grouped()){ type_t mpi = PJ_type_get_or_null ("MPI", container->type); - if (mpi == NULL){ + if (mpi == nullptr){ mpi = PJ_type_container_new("MPI", container->type); PJ_type_state_new ("MPI_STATE", mpi); - PJ_type_link_new ("MPI_LINK", PJ_type_get_root(), mpi, mpi); } } if (TRACE_msg_process_is_enabled()) { type_t msg_process = PJ_type_get_or_null ("MSG_PROCESS", container->type); - if (msg_process == NULL){ + if (msg_process == nullptr){ msg_process = PJ_type_container_new("MSG_PROCESS", container->type); type_t state = PJ_type_state_new ("MSG_PROCESS_STATE", msg_process); PJ_value_new ("suspend", "1 0 1", state); @@ -303,7 +302,7 @@ void sg_instr_new_host(sg_platf_host_cbarg_t host) if (TRACE_msg_vm_is_enabled()) { type_t msg_vm = PJ_type_get_or_null ("MSG_VM", container->type); - if (msg_vm == NULL){ + if (msg_vm == nullptr){ msg_vm = PJ_type_container_new("MSG_VM", container->type); type_t state = PJ_type_state_new ("MSG_VM_STATE", msg_vm); PJ_value_new ("suspend", "1 0 1", state); @@ -327,10 +326,10 @@ void sg_instr_new_router(sg_platf_router_cbarg_t router) static void instr_routing_parse_end_platform () { xbt_dynar_free(¤tContainer); - currentContainer = NULL; + currentContainer = nullptr; xbt_dict_t filter = xbt_dict_new_homogeneous(xbt_free_f); XBT_DEBUG ("Starting graph extraction."); - recursiveGraphExtraction (surf_AS_get_routing_root(), PJ_container_get_root(), filter); + recursiveGraphExtraction (simgrid::s4u::Engine::instance()->rootAs(), PJ_container_get_root(), filter); XBT_DEBUG ("Graph extraction finished."); xbt_dict_free(&filter); platform_created = 1; @@ -367,7 +366,7 @@ static void recursiveNewVariableType (const char *new_typename, const char *colo snprintf (tnstr, INSTR_DEFAULT_STR_SIZE, "b%s", new_typename); PJ_type_variable_new (tnstr, color, root); } - xbt_dict_cursor_t cursor = NULL; + xbt_dict_cursor_t cursor = nullptr; type_t child_type; char *name; xbt_dict_foreach(root->children, cursor, name, child_type) { @@ -385,7 +384,7 @@ static void recursiveNewUserVariableType (const char *father_type, const char *n if (!strcmp (root->name, father_type)){ PJ_type_variable_new (new_typename, color, root); } - xbt_dict_cursor_t cursor = NULL; + xbt_dict_cursor_t cursor = nullptr; type_t child_type; char *name; xbt_dict_foreach(root->children, cursor, name, child_type) { @@ -403,7 +402,7 @@ static void recursiveNewUserStateType (const char *father_type, const char *new_ if (!strcmp (root->name, father_type)){ PJ_type_state_new (new_typename, root); } - xbt_dict_cursor_t cursor = NULL; + xbt_dict_cursor_t cursor = nullptr; type_t child_type; char *name; xbt_dict_foreach(root->children, cursor, name, child_type) { @@ -421,7 +420,7 @@ static void recursiveNewValueForUserStateType (const char *type_name, const char if (!strcmp (root->name, type_name)){ PJ_value_new (value, color, root); } - xbt_dict_cursor_t cursor = NULL; + xbt_dict_cursor_t cursor = nullptr; type_t child_type; char *name; xbt_dict_foreach(root->children, cursor, name, child_type) { @@ -443,29 +442,29 @@ int instr_platform_traced () static void recursiveXBTGraphExtraction (xbt_graph_t graph, xbt_dict_t nodes, xbt_dict_t edges, - AS_t rc, container_t container) + AS_t as, container_t container) { - if (!xbt_dict_is_empty(surf_AS_get_routing_sons(rc))){ - xbt_dict_cursor_t cursor = NULL; - AS_t rc_son; + if (!xbt_dict_is_empty(as->children())){ + xbt_dict_cursor_t cursor = nullptr; + AS_t as_child; char *child_name; //bottom-up recursion - xbt_dict_foreach(surf_AS_get_routing_sons(rc), cursor, child_name, rc_son) { + xbt_dict_foreach(as->children(), cursor, child_name, as_child) { container_t child_container = (container_t) xbt_dict_get ( - container->children, surf_AS_get_name(rc_son)); - recursiveXBTGraphExtraction (graph, nodes, edges, rc_son, child_container); + container->children, as_child->name()); + recursiveXBTGraphExtraction (graph, nodes, edges, as_child, child_container); } } - surf_AS_get_graph(rc, graph, nodes, edges); + static_cast(as)->getGraph(graph, nodes, edges); } xbt_graph_t instr_routing_platform_graph (void) { - xbt_graph_t ret = xbt_graph_new_graph (0, NULL); - xbt_dict_t nodes = xbt_dict_new_homogeneous(NULL); - xbt_dict_t edges = xbt_dict_new_homogeneous(NULL); - recursiveXBTGraphExtraction (ret, nodes, edges, surf_AS_get_routing_root(), PJ_container_get_root()); + xbt_graph_t ret = xbt_graph_new_graph (0, nullptr); + xbt_dict_t nodes = xbt_dict_new_homogeneous(nullptr); + xbt_dict_t edges = xbt_dict_new_homogeneous(nullptr); + recursiveXBTGraphExtraction (ret, nodes, edges, simgrid::s4u::Engine::instance()->rootAs(), PJ_container_get_root()); xbt_dict_free (&nodes); xbt_dict_free (&edges); return ret; @@ -474,9 +473,9 @@ xbt_graph_t instr_routing_platform_graph (void) void instr_routing_platform_graph_export_graphviz (xbt_graph_t g, const char *filename) { unsigned int cursor = 0; - xbt_node_t node = NULL; - xbt_edge_t edge = NULL; - FILE *file = NULL; + xbt_node_t node = nullptr; + xbt_edge_t edge = nullptr; + FILE *file = nullptr; file = fopen(filename, "w"); xbt_assert(file, "Failed to open %s \n", filename);