Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Make a proper extension out of the Vivaldi coordinates
authorMartin Quinson <martin.quinson@loria.fr>
Tue, 8 Nov 2016 14:38:58 +0000 (15:38 +0100)
committerMartin Quinson <martin.quinson@loria.fr>
Tue, 8 Nov 2016 15:49:42 +0000 (16:49 +0100)
include/surf/surf_routing.h
src/kernel/routing/AsVivaldi.cpp
src/kernel/routing/AsVivaldi.hpp
src/simgrid/sg_config.cpp
src/surf/sg_platf.cpp
src/surf/surf_routing.cpp

index 075f7c7..011ee92 100644 (file)
@@ -12,7 +12,6 @@
 SG_BEGIN_DECL()
 
 XBT_PUBLIC_DATA(int) SIMIX_STORAGE_LEVEL; //Simix storage level
 SG_BEGIN_DECL()
 
 XBT_PUBLIC_DATA(int) SIMIX_STORAGE_LEVEL; //Simix storage level
-XBT_PUBLIC_DATA(int) COORD_HOST_LEVEL;    //Coordinates level
 
 XBT_PUBLIC_DATA(xbt_lib_t) as_router_lib;
 XBT_PUBLIC_DATA(int) ROUTING_ASR_LEVEL;  //Routing level
 
 XBT_PUBLIC_DATA(xbt_lib_t) as_router_lib;
 XBT_PUBLIC_DATA(int) ROUTING_ASR_LEVEL;  //Routing level
index 57c48cb..3dd3562 100644 (file)
@@ -15,11 +15,42 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_route_vivaldi, surf, "Routing part of surf"
 namespace simgrid {
 namespace kernel {
 namespace routing {
 namespace simgrid {
 namespace kernel {
 namespace routing {
-  static inline double euclidean_dist_comp(int index, xbt_dynar_t src, xbt_dynar_t dst) {
-    double src_coord = xbt_dynar_get_as(src, index, double);
-    double dst_coord = xbt_dynar_get_as(dst, index, double);
+namespace vivaldi {
+simgrid::xbt::Extension<s4u::Host, Coords> Coords::EXTENSION_ID;
 
 
-    return (src_coord-dst_coord)*(src_coord-dst_coord);
+Coords::Coords(s4u::Host* host, const char* coordStr)
+{
+  if (!Coords::EXTENSION_ID.valid()) {
+    Coords::EXTENSION_ID = s4u::Host::extension_create<Coords>();
+  }
+
+  unsigned int cursor;
+  char* str;
+
+  xbt_dynar_t ctn_str = xbt_str_split_str(coordStr, " ");
+  xbt_assert(xbt_dynar_length(ctn_str) == 3, "Coordinates of %s must have 3 dimensions", host->name().c_str());
+
+  this->coords = xbt_dynar_new(sizeof(double), nullptr);
+  xbt_dynar_foreach (ctn_str, cursor, str) {
+    double val = xbt_str_parse_double(str, "Invalid coordinate: %s");
+    xbt_dynar_push(this->coords, &val);
+  }
+  xbt_dynar_free(&ctn_str);
+  xbt_dynar_shrink(this->coords, 0);
+  host->extension_set<Coords>(this);
+}
+Coords::~Coords()
+{
+  xbt_dynar_free(&coords);
+}
+}; // namespace vivaldi
+
+static inline double euclidean_dist_comp(int index, xbt_dynar_t src, xbt_dynar_t dst)
+{
+  double src_coord = xbt_dynar_get_as(src, index, double);
+  double dst_coord = xbt_dynar_get_as(dst, index, double);
+
+  return (src_coord - dst_coord) * (src_coord - dst_coord);
   }
 
   static xbt_dynar_t getCoordsFromNetcard(NetCard *nc)
   }
 
   static xbt_dynar_t getCoordsFromNetcard(NetCard *nc)
@@ -27,13 +58,13 @@ namespace routing {
     xbt_dynar_t res = nullptr;
     char *tmp_name;
 
     xbt_dynar_t res = nullptr;
     char *tmp_name;
 
-    if(nc->isHost()){
+    if (nc->isHost()) {
       tmp_name                 = bprintf("peer_%s", nc->name().c_str());
       simgrid::s4u::Host *host = simgrid::s4u::Host::by_name_or_null(tmp_name);
       if (host == nullptr)
         host = simgrid::s4u::Host::by_name_or_null(nc->name());
       if (host != nullptr)
       tmp_name                 = bprintf("peer_%s", nc->name().c_str());
       simgrid::s4u::Host *host = simgrid::s4u::Host::by_name_or_null(tmp_name);
       if (host == nullptr)
         host = simgrid::s4u::Host::by_name_or_null(nc->name());
       if (host != nullptr)
-        res = (xbt_dynar_t) host->extension(COORD_HOST_LEVEL);
+        res = host->extension<simgrid::kernel::routing::vivaldi::Coords>()->coords;
     }
     else if(nc->isRouter() || nc->isAS()){
       tmp_name = bprintf("router_%s", nc->name().c_str());
     }
     else if(nc->isRouter() || nc->isAS()){
       tmp_name = bprintf("router_%s", nc->name().c_str());
index e8038e8..65f4d52 100644 (file)
@@ -22,6 +22,18 @@ public:
   void getRouteAndLatency(NetCard *src, NetCard *dst, sg_platf_route_cbarg_t into, double *latency) override;
 };
 
   void getRouteAndLatency(NetCard *src, NetCard *dst, sg_platf_route_cbarg_t into, double *latency) override;
 };
 
-}}} // namespace
+namespace vivaldi {
+class XBT_PRIVATE Coords {
+public:
+  static simgrid::xbt::Extension<simgrid::s4u::Host, Coords> EXTENSION_ID;
+  explicit Coords(s4u::Host* host, const char* str);
+  virtual ~Coords();
+
+  xbt_dynar_t coords;
+};
+}
+}
+}
+} // namespace
 
 #endif /* SURF_ROUTING_VIVALDI_HPP_ */
 
 #endif /* SURF_ROUTING_VIVALDI_HPP_ */
index 3f973e3..a56881a 100644 (file)
@@ -347,10 +347,8 @@ static void _sg_cfg_cb__surf_network_coordinates(const char *name)
   static int already_set = 0;
   int val = xbt_cfg_get_boolean(name);
   if (val) {
   static int already_set = 0;
   int val = xbt_cfg_get_boolean(name);
   if (val) {
-    if (!already_set) {
-      COORD_HOST_LEVEL = sg_host_extension_create(xbt_dynar_free_voidp);
+    if (!already_set)
       COORD_ASR_LEVEL  = xbt_lib_add_level(as_router_lib,xbt_dynar_free_voidp);
       COORD_ASR_LEVEL  = xbt_lib_add_level(as_router_lib,xbt_dynar_free_voidp);
-    }
     already_set = 1;
   } else
     if (already_set)
     already_set = 1;
   } else
     if (already_set)
index d6c3aaa..65b2133 100644 (file)
@@ -82,22 +82,7 @@ void sg_platf_new_host(sg_platf_host_cbarg_t host)
   current_routing->attachHost(h);
 
   if (host->coord && strcmp(host->coord, "")) {
   current_routing->attachHost(h);
 
   if (host->coord && strcmp(host->coord, "")) {
-    unsigned int cursor;
-    char*str;
-
-    xbt_assert(COORD_HOST_LEVEL, "To use host coordinates, please add --cfg=network/coordinates:yes to your command line");
-    /* Pre-parse the host coordinates -- FIXME factorize with routers by overloading the routing->parse_PU function*/
-    xbt_dynar_t ctn_str = xbt_str_split_str(host->coord, " ");
-    xbt_assert(xbt_dynar_length(ctn_str)==3,"Coordinates of %s must have 3 dimensions", host->id);
-
-    xbt_dynar_t ctn = xbt_dynar_new(sizeof(double),nullptr);
-    xbt_dynar_foreach(ctn_str,cursor, str) {
-      double val = xbt_str_parse_double(str, "Invalid coordinate: %s");
-      xbt_dynar_push(ctn,&val);
-    }
-    xbt_dynar_free(&ctn_str);
-    xbt_dynar_shrink(ctn, 0);
-    h->extension_set(COORD_HOST_LEVEL, (void *) ctn);
+    new simgrid::kernel::routing::vivaldi::Coords(h, host->coord);
   }
 
   simgrid::surf::Cpu *cpu = surf_cpu_model_pm->createCpu( h, &host->speed_per_pstate, host->core_amount);
   }
 
   simgrid::surf::Cpu *cpu = surf_cpu_model_pm->createCpu( h, &host->speed_per_pstate, host->core_amount);
index d4b0924..3dee138 100644 (file)
@@ -35,8 +35,6 @@ namespace routing {
  * @brief A library containing all known hosts
  */
 
  * @brief A library containing all known hosts
  */
 
-int COORD_HOST_LEVEL = -1;         //Coordinates level
-
 int MSG_FILE_LEVEL = -1;             //Msg file level
 
 int SIMIX_STORAGE_LEVEL = -1;        //Simix storage level
 int MSG_FILE_LEVEL = -1;             //Msg file level
 
 int SIMIX_STORAGE_LEVEL = -1;        //Simix storage level