From 6534c58a2afafe609a4671073f6b20f839e20fd7 Mon Sep 17 00:00:00 2001 From: Martin Quinson Date: Fri, 12 Feb 2016 02:21:09 +0100 Subject: [PATCH] start initializing routing fields in the constructors, not with a shotgun --- src/surf/surf_routing.cpp | 68 ++++++++++------------ src/surf/surf_routing.hpp | 25 ++++---- src/surf/surf_routing_cluster.cpp | 4 +- src/surf/surf_routing_cluster.hpp | 2 +- src/surf/surf_routing_cluster_fat_tree.cpp | 4 +- src/surf/surf_routing_cluster_fat_tree.hpp | 4 +- src/surf/surf_routing_cluster_torus.cpp | 3 +- src/surf/surf_routing_cluster_torus.hpp | 2 +- src/surf/surf_routing_dijkstra.cpp | 7 +-- src/surf/surf_routing_dijkstra.hpp | 3 +- src/surf/surf_routing_floyd.cpp | 4 +- src/surf/surf_routing_floyd.hpp | 2 +- src/surf/surf_routing_full.cpp | 5 ++ src/surf/surf_routing_full.hpp | 2 +- src/surf/surf_routing_generic.cpp | 7 ++- src/surf/surf_routing_generic.hpp | 2 +- src/surf/surf_routing_none.cpp | 5 ++ src/surf/surf_routing_none.hpp | 4 +- src/surf/surf_routing_vivaldi.cpp | 3 + src/surf/surf_routing_vivaldi.hpp | 2 +- 20 files changed, 83 insertions(+), 75 deletions(-) diff --git a/src/surf/surf_routing.cpp b/src/surf/surf_routing.cpp index e36b003d61..759ba1266f 100644 --- a/src/surf/surf_routing.cpp +++ b/src/surf/surf_routing.cpp @@ -21,18 +21,28 @@ #include "src/surf/surf_routing_full.hpp" #include "src/surf/surf_routing_vivaldi.hpp" -/************* - * Callbacks * - *************/ namespace simgrid { namespace surf { -simgrid::xbt::signal netcardCreatedCallbacks; -simgrid::xbt::signal asCreatedCallbacks; + /* Callbacks */ + simgrid::xbt::signal netcardCreatedCallbacks; + simgrid::xbt::signal asCreatedCallbacks; -} -} + As::As(const char*name) + : p_name(xbt_strdup(name)) + {} + As::~As() + { + xbt_dict_free(&p_routingSons); + xbt_dynar_free(&p_indexNetworkElm); + xbt_dynar_free(&p_linkUpDownList); + xbt_free(p_name); + if (p_netcard) + delete p_netcard; + } + +}} // namespace simgrid::surf /** * @ingroup SURF_build_api @@ -78,19 +88,6 @@ simgrid::surf::As* routing_get_current() return current_routing; } -/* this lines are only for replace use like index in the model table */ -typedef enum { - SURF_MODEL_FULL = 0, - SURF_MODEL_FLOYD, - SURF_MODEL_DIJKSTRA, - SURF_MODEL_DIJKSTRACACHE, - SURF_MODEL_NONE, - SURF_MODEL_VIVALDI, - SURF_MODEL_CLUSTER, - SURF_MODEL_TORUS_CLUSTER, - SURF_MODEL_FAT_TREE_CLUSTER, -} e_routing_types; - /** @brief Add a link connecting an host to the rest of its AS (which must be cluster or vivaldi) */ void sg_platf_new_hostlink(sg_platf_host_link_cbarg_t netcard_arg) { @@ -152,38 +149,33 @@ void routing_AS_begin(sg_platf_AS_cbarg_t AS) _sg_cfg_init_status = 2; /* HACK: direct access to the global controlling the level of configuration to prevent * any further config now that we created some real content */ - simgrid::surf::As *new_as = NULL; /* search the routing model */ + simgrid::surf::As *new_as = NULL; switch(AS->routing){ - case A_surfxml_AS_routing_Cluster: new_as = new simgrid::surf::AsCluster(); break; - case A_surfxml_AS_routing_ClusterTorus: new_as = new simgrid::surf::AsClusterTorus(); break; - case A_surfxml_AS_routing_ClusterFatTree: new_as = new simgrid::surf::AsClusterFatTree(); break; - case A_surfxml_AS_routing_Dijkstra: new_as = new simgrid::surf::AsDijkstra(0); break; - case A_surfxml_AS_routing_DijkstraCache: new_as = new simgrid::surf::AsDijkstra(1); break; - case A_surfxml_AS_routing_Floyd: new_as = new simgrid::surf::AsFloyd(); break; - case A_surfxml_AS_routing_Full: new_as = new simgrid::surf::AsFull(); break; - case A_surfxml_AS_routing_None: new_as = new simgrid::surf::AsNone(); break; - case A_surfxml_AS_routing_Vivaldi: new_as = new simgrid::surf::AsVivaldi(); break; - default: xbt_die("Not a valid model!"); break; + case A_surfxml_AS_routing_Cluster: new_as = new simgrid::surf::AsCluster(AS->id); break; + case A_surfxml_AS_routing_ClusterTorus: new_as = new simgrid::surf::AsClusterTorus(AS->id); break; + case A_surfxml_AS_routing_ClusterFatTree: new_as = new simgrid::surf::AsClusterFatTree(AS->id); break; + case A_surfxml_AS_routing_Dijkstra: new_as = new simgrid::surf::AsDijkstra(AS->id, 0); break; + case A_surfxml_AS_routing_DijkstraCache: new_as = new simgrid::surf::AsDijkstra(AS->id, 1); break; + case A_surfxml_AS_routing_Floyd: new_as = new simgrid::surf::AsFloyd(AS->id); break; + case A_surfxml_AS_routing_Full: new_as = new simgrid::surf::AsFull(AS->id); break; + case A_surfxml_AS_routing_None: new_as = new simgrid::surf::AsNone(AS->id); break; + case A_surfxml_AS_routing_Vivaldi: new_as = new simgrid::surf::AsVivaldi(AS->id); break; + default: xbt_die("Not a valid model!"); break; } /* make a new routing component */ - - new_as->p_hierarchy = SURF_ROUTING_NULL; - new_as->p_name = xbt_strdup(AS->id); - simgrid::surf::NetCard *netcard = new simgrid::surf::NetCardImpl(new_as->p_name, SURF_NETWORK_ELEMENT_AS, current_routing); - if (current_routing == NULL && routing_platf->p_root == NULL) { + if (current_routing == NULL && routing_platf->p_root == NULL) { /* it is the first one */ new_as->p_routingFather = NULL; routing_platf->p_root = new_as; netcard->setId(-1); } else if (current_routing != NULL && routing_platf->p_root != NULL) { - xbt_assert(!xbt_dict_get_or_null - (current_routing->p_routingSons, AS->id), + xbt_assert(!xbt_dict_get_or_null(current_routing->p_routingSons, AS->id), "The AS \"%s\" already exists", AS->id); /* it is a part of the tree */ new_as->p_routingFather = current_routing; diff --git a/src/surf/surf_routing.hpp b/src/surf/surf_routing.hpp index 7a2a2a35c6..5bfc90df6c 100644 --- a/src/surf/surf_routing.hpp +++ b/src/surf/surf_routing.hpp @@ -48,27 +48,22 @@ public: */ class As { public: - xbt_dynar_t p_indexNetworkElm = xbt_dynar_new(sizeof(char*),NULL); - xbt_dict_t p_bypassRoutes; /* store bypass routes */ - e_surf_routing_hierarchy_t p_hierarchy; + As(const char*name); + /** @brief Close that AS: no more content can be added to it */ + virtual void Seal()=0; + virtual ~As(); + char *p_name = nullptr; + NetCard *p_netcard = nullptr; As *p_routingFather = nullptr; + + xbt_dynar_t p_indexNetworkElm = xbt_dynar_new(sizeof(char*),NULL); + xbt_dict_t p_bypassRoutes = nullptr; + e_surf_routing_hierarchy_t p_hierarchy = SURF_ROUTING_NULL; xbt_dict_t p_routingSons = xbt_dict_new_homogeneous(NULL); - NetCard *p_netcard; xbt_dynar_t p_linkUpDownList = xbt_dynar_new(sizeof(s_surf_parsing_link_up_down_t),NULL); - As(){}; - /* Close that AS: no more content can be added to it */ - virtual void Seal()=0; - virtual ~As(){ - xbt_dict_free(&p_routingSons); - xbt_dynar_free(&p_indexNetworkElm); - xbt_dynar_free(&p_linkUpDownList); - xbt_free(p_name); - if (p_netcard) - delete p_netcard; - }; /** * @brief Get the characteristics of the routing path between two points diff --git a/src/surf/surf_routing_cluster.cpp b/src/surf/surf_routing_cluster.cpp index ebb2a58ebd..913d605908 100644 --- a/src/surf/surf_routing_cluster.cpp +++ b/src/surf/surf_routing_cluster.cpp @@ -15,8 +15,10 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_route_cluster, surf, "Routing part of surf" namespace simgrid { namespace surf { + AsCluster::AsCluster(const char*name) + : AsNone(name) + {} -/* Business methods */ void AsCluster::getRouteAndLatency(NetCard *src, NetCard *dst, sg_platf_route_cbarg_t route, double *lat) { s_surf_parsing_link_up_down_t info; diff --git a/src/surf/surf_routing_cluster.hpp b/src/surf/surf_routing_cluster.hpp index 5d7123192c..ad7f4a0d07 100644 --- a/src/surf/surf_routing_cluster.hpp +++ b/src/surf/surf_routing_cluster.hpp @@ -26,7 +26,7 @@ class XBT_PRIVATE AsCluster; class AsCluster: public AsNone { public: - AsCluster() {} + AsCluster(const char*name); void Seal() override {}; // nothing to do virtual void getRouteAndLatency(NetCard *src, NetCard *dst, sg_platf_route_cbarg_t into, double *latency) override; diff --git a/src/surf/surf_routing_cluster_fat_tree.cpp b/src/surf/surf_routing_cluster_fat_tree.cpp index 5d9bc0c961..d8410ef27f 100644 --- a/src/surf/surf_routing_cluster_fat_tree.cpp +++ b/src/surf/surf_routing_cluster_fat_tree.cpp @@ -21,7 +21,9 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_route_fat_tree, surf, "Routing for fat tree namespace simgrid { namespace surf { -AsClusterFatTree::AsClusterFatTree() : levels(0) { +AsClusterFatTree::AsClusterFatTree(const char*name) + : AsCluster(name) +{ XBT_DEBUG("Creating a new fat tree."); } diff --git a/src/surf/surf_routing_cluster_fat_tree.hpp b/src/surf/surf_routing_cluster_fat_tree.hpp index 6d6adcf668..258dcd6ebd 100644 --- a/src/surf/surf_routing_cluster_fat_tree.hpp +++ b/src/surf/surf_routing_cluster_fat_tree.hpp @@ -116,7 +116,7 @@ public: */ class XBT_PRIVATE AsClusterFatTree : public AsCluster { public: - AsClusterFatTree(); + AsClusterFatTree(const char*name); ~AsClusterFatTree(); virtual void getRouteAndLatency(NetCard *src, NetCard *dst, sg_platf_route_cbarg_t into, @@ -140,7 +140,7 @@ public: private: //description of a PGFT (TODO : better doc) - unsigned int levels; + unsigned int levels = 0; std::vector lowerLevelNodesNumber; // number of children by node std::vector upperLevelNodesNumber; // number of parents by node std::vector lowerLevelPortsNumber; // ports between each level l and l-1 diff --git a/src/surf/surf_routing_cluster_torus.cpp b/src/surf/surf_routing_cluster_torus.cpp index 1288cf8da5..2770527846 100644 --- a/src/surf/surf_routing_cluster_torus.cpp +++ b/src/surf/surf_routing_cluster_torus.cpp @@ -27,7 +27,8 @@ inline unsigned int *rankId_to_coords(int rankId, xbt_dynar_t dimensions) namespace simgrid { namespace surf { - AsClusterTorus::AsClusterTorus():AsCluster() { + AsClusterTorus::AsClusterTorus(const char*name) + : AsCluster(name) { } AsClusterTorus::~AsClusterTorus() { xbt_dynar_free(&p_dimensions); diff --git a/src/surf/surf_routing_cluster_torus.hpp b/src/surf/surf_routing_cluster_torus.hpp index 35bcb6817f..b516c73b02 100644 --- a/src/surf/surf_routing_cluster_torus.hpp +++ b/src/surf/surf_routing_cluster_torus.hpp @@ -19,7 +19,7 @@ namespace simgrid { class XBT_PRIVATE AsClusterTorus:public simgrid::surf::AsCluster { public: - AsClusterTorus(); + AsClusterTorus(const char*name); virtual ~AsClusterTorus(); void create_links_for_node(sg_platf_cluster_cbarg_t cluster, int id, int rank, int position) override; void getRouteAndLatency(NetCard * src, NetCard * dst, sg_platf_route_cbarg_t into, double *latency) override; diff --git a/src/surf/surf_routing_dijkstra.cpp b/src/surf/surf_routing_dijkstra.cpp index c5cf6a33a9..0fad7412f9 100644 --- a/src/surf/surf_routing_dijkstra.cpp +++ b/src/surf/surf_routing_dijkstra.cpp @@ -396,10 +396,9 @@ AsDijkstra::~AsDijkstra() /* Creation routing model functions */ -AsDijkstra::AsDijkstra() : AsGeneric() { -} - -AsDijkstra::AsDijkstra(bool cached) : AsGeneric(), m_cached(cached) +AsDijkstra::AsDijkstra(const char*name, bool cached) + : AsGeneric(name) + , m_cached(cached) { p_routeGraph = NULL; p_graphNodeMap = NULL; diff --git a/src/surf/surf_routing_dijkstra.hpp b/src/surf/surf_routing_dijkstra.hpp index e52beef258..74a33cb698 100644 --- a/src/surf/surf_routing_dijkstra.hpp +++ b/src/surf/surf_routing_dijkstra.hpp @@ -37,10 +37,9 @@ class XBT_PRIVATE AsDijkstra; /** Dijkstra routing data: fast initialization, slow lookup, small memory requirements, shortest path routing only */ class AsDijkstra : public AsGeneric { public: - AsDijkstra(); + AsDijkstra(const char*name, bool cached); void Seal() override; - AsDijkstra(bool cached); ~AsDijkstra(); xbt_node_t routeGraphNewNode(int id, int graph_id); graph_node_map_element_t nodeMapSearch(int id); diff --git a/src/surf/surf_routing_floyd.cpp b/src/surf/surf_routing_floyd.cpp index bed72895c8..38c9c432ca 100644 --- a/src/surf/surf_routing_floyd.cpp +++ b/src/surf/surf_routing_floyd.cpp @@ -17,7 +17,9 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_route_floyd, surf, "Routing part of surf"); namespace simgrid { namespace surf { -AsFloyd::AsFloyd(): AsGeneric() { +AsFloyd::AsFloyd(const char*name) + : AsGeneric(name) +{ p_predecessorTable = NULL; p_costTable = NULL; p_linkTable = NULL; diff --git a/src/surf/surf_routing_floyd.hpp b/src/surf/surf_routing_floyd.hpp index 7bca1e158f..3da98f1c50 100644 --- a/src/surf/surf_routing_floyd.hpp +++ b/src/surf/surf_routing_floyd.hpp @@ -23,7 +23,7 @@ class XBT_PRIVATE AsFloyd; /** Floyd routing data: slow initialization, fast lookup, lesser memory requirements, shortest path routing only */ class AsFloyd: public AsGeneric { public: - AsFloyd(); + AsFloyd(const char *name); ~AsFloyd(); void getRouteAndLatency(NetCard *src, NetCard *dst, sg_platf_route_cbarg_t into, double *latency) override; diff --git a/src/surf/surf_routing_full.cpp b/src/surf/surf_routing_full.cpp index 49e71cc36f..a64bc49d0d 100644 --- a/src/surf/surf_routing_full.cpp +++ b/src/surf/surf_routing_full.cpp @@ -14,6 +14,11 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_route_full, surf, "Routing part of surf"); namespace simgrid { namespace surf { + AsFull::AsFull(const char*name) + : AsGeneric(name) + { + } + void AsFull::Seal() { int i; sg_platf_route_cbarg_t e_route; diff --git a/src/surf/surf_routing_full.hpp b/src/surf/surf_routing_full.hpp index 0473e9289d..76edfe66b6 100644 --- a/src/surf/surf_routing_full.hpp +++ b/src/surf/surf_routing_full.hpp @@ -23,7 +23,7 @@ class XBT_PRIVATE AsFull; class AsFull: public AsGeneric { public: - AsFull() {} + AsFull(const char*name); void Seal() override; ~AsFull(); diff --git a/src/surf/surf_routing_generic.cpp b/src/surf/surf_routing_generic.cpp index c455405087..262042a96c 100644 --- a/src/surf/surf_routing_generic.cpp +++ b/src/surf/surf_routing_generic.cpp @@ -47,11 +47,14 @@ void AsGeneric::getRouteAndLatency(NetCard */*src*/, NetCard */*dst*/, sg_platf_ THROW_IMPOSSIBLE; } -AsGeneric::AsGeneric() { +AsGeneric::AsGeneric(const char*name) + : AsNone(name) +{ p_bypassRoutes = xbt_dict_new_homogeneous((void (*)(void *)) routing_route_free); } -AsGeneric::~AsGeneric() { +AsGeneric::~AsGeneric() +{ xbt_dict_free(&p_bypassRoutes); } diff --git a/src/surf/surf_routing_generic.hpp b/src/surf/surf_routing_generic.hpp index 29c4dd686e..ce2c2876f4 100644 --- a/src/surf/surf_routing_generic.hpp +++ b/src/surf/surf_routing_generic.hpp @@ -18,7 +18,7 @@ class XBT_PRIVATE AsGeneric; class XBT_PRIVATE AsGeneric : public AsNone { public: - AsGeneric(); + AsGeneric(const char*name); ~AsGeneric(); virtual void getRouteAndLatency(NetCard *src, NetCard *dst, sg_platf_route_cbarg_t into, double *latency) override; diff --git a/src/surf/surf_routing_none.cpp b/src/surf/surf_routing_none.cpp index 86d41d47bf..34e817cef3 100644 --- a/src/surf/surf_routing_none.cpp +++ b/src/surf/surf_routing_none.cpp @@ -11,6 +11,11 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_route_none, surf, "Routing part of surf"); namespace simgrid { namespace surf { +AsNone::AsNone(const char*name) + : As(name) +{} +AsNone::~AsNone() +{} xbt_dynar_t AsNone::getOneLinkRoutes() { return NULL; diff --git a/src/surf/surf_routing_none.hpp b/src/surf/surf_routing_none.hpp index 71026a44db..3ed7b18e03 100644 --- a/src/surf/surf_routing_none.hpp +++ b/src/surf/surf_routing_none.hpp @@ -17,9 +17,9 @@ namespace surf { /** No specific routing. Mainly useful with the constant network model */ class XBT_PRIVATE AsNone : public As { public: - AsNone() {} + AsNone(const char*name); void Seal() override {}; // nothing to do - ~AsNone() {} + ~AsNone(); void getRouteAndLatency(NetCard *src, NetCard *dst, sg_platf_route_cbarg_t into, double *latency) override; xbt_dynar_t getOneLinkRoutes() override; diff --git a/src/surf/surf_routing_vivaldi.cpp b/src/surf/surf_routing_vivaldi.cpp index 69899fc99a..c22d2f5976 100644 --- a/src/surf/surf_routing_vivaldi.cpp +++ b/src/surf/surf_routing_vivaldi.cpp @@ -24,6 +24,9 @@ static XBT_INLINE double euclidean_dist_comp(int index, xbt_dynar_t src, xbt_dyn namespace simgrid { namespace surf { + AsVivaldi::AsVivaldi(const char *name) + : AsGeneric(name) + {} void AsVivaldi::getRouteAndLatency(NetCard *src, NetCard *dst, sg_platf_route_cbarg_t route, double *lat) { diff --git a/src/surf/surf_routing_vivaldi.hpp b/src/surf/surf_routing_vivaldi.hpp index 43192be62a..69299e0e32 100644 --- a/src/surf/surf_routing_vivaldi.hpp +++ b/src/surf/surf_routing_vivaldi.hpp @@ -25,7 +25,7 @@ class XBT_PRIVATE AsVivaldi; class AsVivaldi: public AsGeneric { public: - AsVivaldi() : AsGeneric() {}; + AsVivaldi(const char *name); void Seal() override {}; // nothing to do ~AsVivaldi() {}; -- 2.20.1