Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
start initializing routing fields in the constructors, not with a shotgun
authorMartin Quinson <martin.quinson@loria.fr>
Fri, 12 Feb 2016 01:21:09 +0000 (02:21 +0100)
committerMartin Quinson <martin.quinson@loria.fr>
Fri, 12 Feb 2016 01:21:09 +0000 (02:21 +0100)
20 files changed:
src/surf/surf_routing.cpp
src/surf/surf_routing.hpp
src/surf/surf_routing_cluster.cpp
src/surf/surf_routing_cluster.hpp
src/surf/surf_routing_cluster_fat_tree.cpp
src/surf/surf_routing_cluster_fat_tree.hpp
src/surf/surf_routing_cluster_torus.cpp
src/surf/surf_routing_cluster_torus.hpp
src/surf/surf_routing_dijkstra.cpp
src/surf/surf_routing_dijkstra.hpp
src/surf/surf_routing_floyd.cpp
src/surf/surf_routing_floyd.hpp
src/surf/surf_routing_full.cpp
src/surf/surf_routing_full.hpp
src/surf/surf_routing_generic.cpp
src/surf/surf_routing_generic.hpp
src/surf/surf_routing_none.cpp
src/surf/surf_routing_none.hpp
src/surf/surf_routing_vivaldi.cpp
src/surf/surf_routing_vivaldi.hpp

index e36b003..759ba12 100644 (file)
 #include "src/surf/surf_routing_full.hpp"
 #include "src/surf/surf_routing_vivaldi.hpp"
 
 #include "src/surf/surf_routing_full.hpp"
 #include "src/surf/surf_routing_vivaldi.hpp"
 
-/*************
- * Callbacks *
- *************/
 
 namespace simgrid {
 namespace surf {
 
 
 namespace simgrid {
 namespace surf {
 
-simgrid::xbt::signal<void(simgrid::surf::NetCard*)> netcardCreatedCallbacks;
-simgrid::xbt::signal<void(simgrid::surf::As*)> asCreatedCallbacks;
+  /* Callbacks */
+  simgrid::xbt::signal<void(simgrid::surf::NetCard*)> netcardCreatedCallbacks;
+  simgrid::xbt::signal<void(simgrid::surf::As*)> 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
 
 /**
  * @ingroup SURF_build_api
@@ -78,19 +88,6 @@ simgrid::surf::As* routing_get_current()
   return current_routing;
 }
 
   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)
 {
 /** @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 */
 
   _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 */
 
   /* search the routing model */
+  simgrid::surf::As *new_as = NULL;
   switch(AS->routing){
   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 */
   }
 
   /* 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);
   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) {
 
     /* 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;
                "The AS \"%s\" already exists", AS->id);
     /* it is a part of the tree */
     new_as->p_routingFather = current_routing;
index 7a2a2a3..5bfc90d 100644 (file)
@@ -48,27 +48,22 @@ public:
  */
 class As {
 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;
   char *p_name = nullptr;
+  NetCard *p_netcard = nullptr;
   As *p_routingFather = 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);
   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);
 
   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
 
   /**
    * @brief Get the characteristics of the routing path between two points
index ebb2a58..913d605 100644 (file)
@@ -15,8 +15,10 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_route_cluster, surf, "Routing part of surf"
 
 namespace simgrid {
 namespace 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;
 void AsCluster::getRouteAndLatency(NetCard *src, NetCard *dst, sg_platf_route_cbarg_t route, double *lat)
 {
   s_surf_parsing_link_up_down_t info;
index 5d71231..ad7f4a0 100644 (file)
@@ -26,7 +26,7 @@ class XBT_PRIVATE AsCluster;
 
 class AsCluster: public AsNone {
 public:
 
 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;
   void Seal() override {}; // nothing to do
 
   virtual void getRouteAndLatency(NetCard *src, NetCard *dst, sg_platf_route_cbarg_t into, double *latency) override;
index 5d9bc0c..d8410ef 100644 (file)
@@ -21,7 +21,9 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_route_fat_tree, surf, "Routing for fat tree
 namespace simgrid {
 namespace surf {
 
 namespace simgrid {
 namespace surf {
 
-AsClusterFatTree::AsClusterFatTree() : levels(0) {
+AsClusterFatTree::AsClusterFatTree(const char*name)
+  : AsCluster(name)
+{
   XBT_DEBUG("Creating a new fat tree.");
 }
 
   XBT_DEBUG("Creating a new fat tree.");
 }
 
index 6d6adcf..258dcd6 100644 (file)
@@ -116,7 +116,7 @@ public:
  */
 class XBT_PRIVATE AsClusterFatTree : public AsCluster {
 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,
   ~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)
 private:
   
   //description of a PGFT (TODO : better doc)
-  unsigned int levels;
+  unsigned int levels = 0;
   std::vector<unsigned int> lowerLevelNodesNumber; // number of children by node
   std::vector<unsigned int> upperLevelNodesNumber; // number of parents by node
   std::vector<unsigned int> lowerLevelPortsNumber; // ports between each level l and l-1
   std::vector<unsigned int> lowerLevelNodesNumber; // number of children by node
   std::vector<unsigned int> upperLevelNodesNumber; // number of parents by node
   std::vector<unsigned int> lowerLevelPortsNumber; // ports between each level l and l-1
index 1288cf8..2770527 100644 (file)
@@ -27,7 +27,8 @@ inline unsigned int *rankId_to_coords(int rankId, xbt_dynar_t dimensions)
 
 namespace simgrid {
   namespace surf {
 
 namespace simgrid {
   namespace surf {
-    AsClusterTorus::AsClusterTorus():AsCluster() {
+    AsClusterTorus::AsClusterTorus(const char*name)
+      : AsCluster(name) {
     }
     AsClusterTorus::~AsClusterTorus() {
       xbt_dynar_free(&p_dimensions);
     }
     AsClusterTorus::~AsClusterTorus() {
       xbt_dynar_free(&p_dimensions);
index 35bcb68..b516c73 100644 (file)
@@ -19,7 +19,7 @@ namespace simgrid {
 
     class XBT_PRIVATE AsClusterTorus:public simgrid::surf::AsCluster {
     public:
 
     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;
       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;
index c5cf6a3..0fad741 100644 (file)
@@ -396,10 +396,9 @@ AsDijkstra::~AsDijkstra()
 
 /* Creation routing model functions */
 
 
 /* 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;
 {
   p_routeGraph = NULL;
   p_graphNodeMap = NULL;
index e52beef..74a33cb 100644 (file)
@@ -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:
 /** 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;
 
   void Seal() override;
 
-  AsDijkstra(bool cached);
   ~AsDijkstra();
   xbt_node_t routeGraphNewNode(int id, int graph_id);
   graph_node_map_element_t nodeMapSearch(int id);
   ~AsDijkstra();
   xbt_node_t routeGraphNewNode(int id, int graph_id);
   graph_node_map_element_t nodeMapSearch(int id);
index bed7289..38c9c43 100644 (file)
@@ -17,7 +17,9 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_route_floyd, surf, "Routing part of surf");
 namespace simgrid {
 namespace surf {
 
 namespace simgrid {
 namespace surf {
 
-AsFloyd::AsFloyd(): AsGeneric() {
+AsFloyd::AsFloyd(const char*name)
+  : AsGeneric(name)
+{
   p_predecessorTable = NULL;
   p_costTable = NULL;
   p_linkTable = NULL;
   p_predecessorTable = NULL;
   p_costTable = NULL;
   p_linkTable = NULL;
index 7bca1e1..3da98f1 100644 (file)
@@ -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:
 /** 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;
   ~AsFloyd();
 
   void getRouteAndLatency(NetCard *src, NetCard *dst, sg_platf_route_cbarg_t into, double *latency) override;
index 49e71cc..a64bc49 100644 (file)
@@ -14,6 +14,11 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_route_full, surf, "Routing part of surf");
 
 namespace simgrid {
 namespace surf {
 
 namespace simgrid {
 namespace surf {
+  AsFull::AsFull(const char*name)
+    : AsGeneric(name)
+  {
+  }
+
 void AsFull::Seal() {
   int i;
   sg_platf_route_cbarg_t e_route;
 void AsFull::Seal() {
   int i;
   sg_platf_route_cbarg_t e_route;
index 0473e92..76edfe6 100644 (file)
@@ -23,7 +23,7 @@ class XBT_PRIVATE AsFull;
 class AsFull: public AsGeneric {
 public:
 
 class AsFull: public AsGeneric {
 public:
 
-  AsFull() {}
+  AsFull(const char*name);
   void Seal() override;
   ~AsFull();
 
   void Seal() override;
   ~AsFull();
 
index c455405..262042a 100644 (file)
@@ -47,11 +47,14 @@ void AsGeneric::getRouteAndLatency(NetCard */*src*/, NetCard */*dst*/, sg_platf_
   THROW_IMPOSSIBLE;
 }
 
   THROW_IMPOSSIBLE;
 }
 
-AsGeneric::AsGeneric() {
+AsGeneric::AsGeneric(const char*name)
+  : AsNone(name)
+{
   p_bypassRoutes = xbt_dict_new_homogeneous((void (*)(void *)) routing_route_free);
 }
 
   p_bypassRoutes = xbt_dict_new_homogeneous((void (*)(void *)) routing_route_free);
 }
 
-AsGeneric::~AsGeneric() {
+AsGeneric::~AsGeneric()
+{
   xbt_dict_free(&p_bypassRoutes);
 }
 
   xbt_dict_free(&p_bypassRoutes);
 }
 
index 29c4dd6..ce2c287 100644 (file)
@@ -18,7 +18,7 @@ class XBT_PRIVATE AsGeneric;
 
 class XBT_PRIVATE AsGeneric : public AsNone {
 public:
 
 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;
   ~AsGeneric();
 
   virtual void getRouteAndLatency(NetCard *src, NetCard *dst, sg_platf_route_cbarg_t into, double *latency) override;
index 86d41d4..34e817c 100644 (file)
@@ -11,6 +11,11 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_route_none, surf, "Routing part of surf");
 
 namespace simgrid {
 namespace surf {
 
 namespace simgrid {
 namespace surf {
+AsNone::AsNone(const char*name)
+  : As(name)
+{}
+AsNone::~AsNone()
+{}
 
 xbt_dynar_t AsNone::getOneLinkRoutes() {
   return NULL;
 
 xbt_dynar_t AsNone::getOneLinkRoutes() {
   return NULL;
index 71026a4..3ed7b18 100644 (file)
@@ -17,9 +17,9 @@ namespace surf {
 /** No specific routing. Mainly useful with the constant network model */
 class XBT_PRIVATE AsNone : public As {
 public:
 /** 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
   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;
 
   void getRouteAndLatency(NetCard *src, NetCard *dst, sg_platf_route_cbarg_t into, double *latency) override;
   xbt_dynar_t getOneLinkRoutes() override;
index 69899fc..c22d2f5 100644 (file)
@@ -24,6 +24,9 @@ static XBT_INLINE double euclidean_dist_comp(int index, xbt_dynar_t src, xbt_dyn
 
 namespace simgrid {
 namespace surf {
 
 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)
 {
 
 void AsVivaldi::getRouteAndLatency(NetCard *src, NetCard *dst, sg_platf_route_cbarg_t route, double *lat)
 {
index 43192be..69299e0 100644 (file)
@@ -25,7 +25,7 @@ class XBT_PRIVATE AsVivaldi;
 
 class AsVivaldi: public AsGeneric {
 public:
 
 class AsVivaldi: public AsGeneric {
 public:
-  AsVivaldi() : AsGeneric() {};
+  AsVivaldi(const char *name);
   void Seal() override {}; // nothing to do
   ~AsVivaldi() {};
 
   void Seal() override {}; // nothing to do
   ~AsVivaldi() {};