From ac3ee4faa126c5b894fb4040b33d6b4e02047921 Mon Sep 17 00:00:00 2001 From: Martin Quinson Date: Thu, 11 Feb 2016 15:11:16 +0100 Subject: [PATCH] First attempt to untangle the AS parsing Each surf::As is given a Seal() method in charge of finalizing its initialization once the last element is added. --- src/surf/surf_routing.hpp | 8 ++----- src/surf/surf_routing_cluster.hpp | 2 ++ src/surf/surf_routing_dijkstra.cpp | 38 +++++++++++++++--------------- src/surf/surf_routing_dijkstra.hpp | 2 ++ src/surf/surf_routing_floyd.cpp | 4 ++-- src/surf/surf_routing_floyd.hpp | 2 +- src/surf/surf_routing_full.cpp | 22 +++++++++-------- src/surf/surf_routing_full.hpp | 1 + src/surf/surf_routing_none.hpp | 1 + src/surf/surf_routing_vivaldi.hpp | 1 + 10 files changed, 43 insertions(+), 38 deletions(-) diff --git a/src/surf/surf_routing.hpp b/src/surf/surf_routing.hpp index 2cb37b86b1..6096197350 100644 --- a/src/surf/surf_routing.hpp +++ b/src/surf/surf_routing.hpp @@ -58,14 +58,10 @@ public: NetCard *p_netcard; xbt_dynar_t p_linkUpDownList = NULL; - /** - * @brief The As constructor - */ As(){}; + /* Close that AS: no more content can be added to it */ + virtual void Seal()=0; - /** - * @brief The As destructor - */ virtual ~As(){ xbt_dict_free(&p_routingSons); xbt_dynar_free(&p_indexNetworkElm); diff --git a/src/surf/surf_routing_cluster.hpp b/src/surf/surf_routing_cluster.hpp index c1962f0c28..5d7123192c 100644 --- a/src/surf/surf_routing_cluster.hpp +++ b/src/surf/surf_routing_cluster.hpp @@ -27,6 +27,7 @@ class XBT_PRIVATE AsCluster; class AsCluster: public AsNone { public: AsCluster() {} + void Seal() override {}; // nothing to do virtual void getRouteAndLatency(NetCard *src, NetCard *dst, sg_platf_route_cbarg_t into, double *latency) override; void getGraph(xbt_graph_t graph, xbt_dict_t nodes, xbt_dict_t edges) override; @@ -36,6 +37,7 @@ public: virtual void create_links_for_node(sg_platf_cluster_cbarg_t cluster, int id, int rank, int position); virtual void parse_specific_arguments(sg_platf_cluster_cbarg_t cluster) {} + Link* p_backbone = nullptr; void *p_loopback = nullptr; NetCard *p_router = nullptr; diff --git a/src/surf/surf_routing_dijkstra.cpp b/src/surf/surf_routing_dijkstra.cpp index dbf3931623..f6fe75f74d 100644 --- a/src/surf/surf_routing_dijkstra.cpp +++ b/src/surf/surf_routing_dijkstra.cpp @@ -46,39 +46,39 @@ AS_t model_dijkstracache_create(void){ void model_dijkstra_both_end(AS_t as) { - simgrid::surf::AsDijkstra *THIS_AS - = static_cast(as); - xbt_node_t node = NULL; - unsigned int cursor2; - xbt_dynar_t nodes = NULL; + as->Seal(); +} +/* Utility functions */ + +namespace simgrid { +namespace surf { +void AsDijkstra::Seal() +{ /* Create the topology graph */ - if(!THIS_AS->p_routeGraph) - THIS_AS->p_routeGraph = xbt_graph_new_graph(1, NULL); - if(!THIS_AS->p_graphNodeMap) - THIS_AS->p_graphNodeMap = xbt_dict_new_homogeneous(&graph_node_map_elem_free); + if(!p_routeGraph) + p_routeGraph = xbt_graph_new_graph(1, NULL); + if(!p_graphNodeMap) + p_graphNodeMap = xbt_dict_new_homogeneous(&graph_node_map_elem_free); - if (THIS_AS->m_cached && !THIS_AS->p_routeCache) - THIS_AS->p_routeCache = xbt_dict_new_homogeneous(&route_cache_elem_free); + if (m_cached && !p_routeCache) + p_routeCache = xbt_dict_new_homogeneous(&route_cache_elem_free); /* Add the loopback if needed */ - if (routing_platf->p_loopback && as->p_hierarchy == SURF_ROUTING_BASE) - THIS_AS->addLoopback(); + if (routing_platf->p_loopback && p_hierarchy == SURF_ROUTING_BASE) + addLoopback(); /* initialize graph indexes in nodes after graph has been built */ - nodes = xbt_graph_get_nodes(THIS_AS->p_routeGraph); + xbt_dynar_t nodes = xbt_graph_get_nodes(p_routeGraph); + xbt_node_t node = NULL; + unsigned int cursor2; xbt_dynar_foreach(nodes, cursor2, node) { graph_node_data_t data = (graph_node_data_t) xbt_graph_node_get_data(node); data->graph_id = cursor2; } } -/* Utility functions */ - -namespace simgrid { -namespace surf { - xbt_node_t AsDijkstra::routeGraphNewNode(int id, int graph_id) { xbt_node_t node = NULL; diff --git a/src/surf/surf_routing_dijkstra.hpp b/src/surf/surf_routing_dijkstra.hpp index bcae26f09f..7f6e4b8c26 100644 --- a/src/surf/surf_routing_dijkstra.hpp +++ b/src/surf/surf_routing_dijkstra.hpp @@ -37,6 +37,8 @@ class XBT_PRIVATE AsDijkstra; class AsDijkstra : public AsGeneric { public: AsDijkstra(); + void Seal() override; + AsDijkstra(bool cached); ~AsDijkstra(); xbt_node_t routeGraphNewNode(int id, int graph_id); diff --git a/src/surf/surf_routing_floyd.cpp b/src/surf/surf_routing_floyd.cpp index 7f2c653bb8..934273b73a 100644 --- a/src/surf/surf_routing_floyd.cpp +++ b/src/surf/surf_routing_floyd.cpp @@ -21,7 +21,7 @@ AS_t model_floyd_create(void) void model_floyd_end(AS_t current_routing) { - static_cast(current_routing)->end(); + current_routing->Seal(); } namespace simgrid { @@ -269,7 +269,7 @@ void AsFloyd::parseRoute(sg_platf_route_cbarg_t route) xbt_dynar_free(&route->link_list); } -void AsFloyd::end(){ +void AsFloyd::Seal(){ unsigned int i, j, a, b, c; /* set the size of table routing */ diff --git a/src/surf/surf_routing_floyd.hpp b/src/surf/surf_routing_floyd.hpp index 5f498f4357..c9ab30ba2f 100644 --- a/src/surf/surf_routing_floyd.hpp +++ b/src/surf/surf_routing_floyd.hpp @@ -29,7 +29,7 @@ public: xbt_dynar_t getOneLinkRoutes() override; void parseASroute(sg_platf_route_cbarg_t route) override; void parseRoute(sg_platf_route_cbarg_t route) override; - void end(); + void Seal() override; private: /* vars to compute the Floyd algorithm. */ diff --git a/src/surf/surf_routing_full.cpp b/src/surf/surf_routing_full.cpp index 67363d71e9..312eeb77bb 100644 --- a/src/surf/surf_routing_full.cpp +++ b/src/surf/surf_routing_full.cpp @@ -19,36 +19,38 @@ AS_t model_full_create(void) void model_full_end(AS_t _routing) { + _routing->Seal(); +} + +namespace simgrid { +namespace surf { +void AsFull::Seal() { int i; sg_platf_route_cbarg_t e_route; /* set utils vars */ - simgrid::surf::AsFull *routing = static_cast(_routing); - int table_size = (int)xbt_dynar_length(routing->p_indexNetworkElm); + int table_size = (int)xbt_dynar_length(p_indexNetworkElm); /* Create table if necessary */ - if (!routing->p_routingTable) - routing->p_routingTable = xbt_new0(sg_platf_route_cbarg_t, table_size * table_size); + if (!p_routingTable) + p_routingTable = xbt_new0(sg_platf_route_cbarg_t, table_size * table_size); /* Add the loopback if needed */ - if (routing_platf->p_loopback && routing->p_hierarchy == SURF_ROUTING_BASE) { + if (routing_platf->p_loopback && p_hierarchy == SURF_ROUTING_BASE) { for (i = 0; i < table_size; i++) { - e_route = routing->TO_ROUTE_FULL(i, i); + e_route = TO_ROUTE_FULL(i, i); if (!e_route) { e_route = xbt_new0(s_sg_platf_route_cbarg_t, 1); e_route->gw_src = NULL; e_route->gw_dst = NULL; e_route->link_list = xbt_dynar_new(sizeof(sg_routing_link_t), NULL); xbt_dynar_push(e_route->link_list, &routing_platf->p_loopback); - routing->TO_ROUTE_FULL(i, i) = e_route; + TO_ROUTE_FULL(i, i) = e_route; } } } } -namespace simgrid { -namespace surf { - AsFull::~AsFull(){ if (p_routingTable) { int table_size = (int)xbt_dynar_length(p_indexNetworkElm); diff --git a/src/surf/surf_routing_full.hpp b/src/surf/surf_routing_full.hpp index c7b662421a..77debc1acb 100644 --- a/src/surf/surf_routing_full.hpp +++ b/src/surf/surf_routing_full.hpp @@ -23,6 +23,7 @@ class AsFull: public AsGeneric { public: AsFull() {} + void Seal() override; ~AsFull(); void getRouteAndLatency(NetCard *src, NetCard *dst, sg_platf_route_cbarg_t into, double *latency) override; diff --git a/src/surf/surf_routing_none.hpp b/src/surf/surf_routing_none.hpp index b706f89832..a81babf4dd 100644 --- a/src/surf/surf_routing_none.hpp +++ b/src/surf/surf_routing_none.hpp @@ -17,6 +17,7 @@ namespace surf { class XBT_PRIVATE AsNone : public As { public: AsNone() {} + void Seal() override {}; // nothing to do ~AsNone() {} void getRouteAndLatency(NetCard *src, NetCard *dst, sg_platf_route_cbarg_t into, double *latency) override; diff --git a/src/surf/surf_routing_vivaldi.hpp b/src/surf/surf_routing_vivaldi.hpp index 3641a13960..43192be62a 100644 --- a/src/surf/surf_routing_vivaldi.hpp +++ b/src/surf/surf_routing_vivaldi.hpp @@ -26,6 +26,7 @@ class XBT_PRIVATE AsVivaldi; class AsVivaldi: public AsGeneric { public: AsVivaldi() : AsGeneric() {}; + void Seal() override {}; // nothing to do ~AsVivaldi() {}; void getRouteAndLatency(NetCard *src, NetCard *dst, sg_platf_route_cbarg_t into, double *latency) override; -- 2.20.1