From: Martin Quinson Date: Tue, 8 Nov 2016 14:38:58 +0000 (+0100) Subject: Make a proper extension out of the Vivaldi coordinates X-Git-Tag: v3_14~222 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/1973cb8a42030c3663609c111d4acf5eb519d8f1?ds=sidebyside Make a proper extension out of the Vivaldi coordinates --- diff --git a/include/surf/surf_routing.h b/include/surf/surf_routing.h index 075f7c7b67..011ee929cd 100644 --- a/include/surf/surf_routing.h +++ b/include/surf/surf_routing.h @@ -12,7 +12,6 @@ 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 diff --git a/src/kernel/routing/AsVivaldi.cpp b/src/kernel/routing/AsVivaldi.cpp index 57c48cb4cd..3dd35623d1 100644 --- a/src/kernel/routing/AsVivaldi.cpp +++ b/src/kernel/routing/AsVivaldi.cpp @@ -15,11 +15,42 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_route_vivaldi, surf, "Routing part of surf" 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 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(); + } + + 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(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) @@ -27,13 +58,13 @@ namespace routing { 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) - res = (xbt_dynar_t) host->extension(COORD_HOST_LEVEL); + res = host->extension()->coords; } else if(nc->isRouter() || nc->isAS()){ tmp_name = bprintf("router_%s", nc->name().c_str()); diff --git a/src/kernel/routing/AsVivaldi.hpp b/src/kernel/routing/AsVivaldi.hpp index e8038e8e23..65f4d523a7 100644 --- a/src/kernel/routing/AsVivaldi.hpp +++ b/src/kernel/routing/AsVivaldi.hpp @@ -22,6 +22,18 @@ public: 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 EXTENSION_ID; + explicit Coords(s4u::Host* host, const char* str); + virtual ~Coords(); + + xbt_dynar_t coords; +}; +} +} +} +} // namespace #endif /* SURF_ROUTING_VIVALDI_HPP_ */ diff --git a/src/simgrid/sg_config.cpp b/src/simgrid/sg_config.cpp index 3f973e3331..a56881ac7f 100644 --- a/src/simgrid/sg_config.cpp +++ b/src/simgrid/sg_config.cpp @@ -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) { - 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); - } already_set = 1; } else if (already_set) diff --git a/src/surf/sg_platf.cpp b/src/surf/sg_platf.cpp index d6c3aaa3cd..65b2133d9e 100644 --- a/src/surf/sg_platf.cpp +++ b/src/surf/sg_platf.cpp @@ -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, "")) { - 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); diff --git a/src/surf/surf_routing.cpp b/src/surf/surf_routing.cpp index d4b0924bcb..3dee138b2b 100644 --- a/src/surf/surf_routing.cpp +++ b/src/surf/surf_routing.cpp @@ -35,8 +35,6 @@ namespace routing { * @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