From 55429072c45ff0bc9d127a116e4f2de3428515b5 Mon Sep 17 00:00:00 2001 From: SUTER Frederic Date: Mon, 12 Apr 2021 14:24:45 +0200 Subject: [PATCH] change way vivaldi coordinates are managed internally --- include/simgrid/kernel/routing/NetPoint.hpp | 1 + .../simgrid/kernel/routing/VivaldiZone.hpp | 2 +- include/simgrid/s4u/Host.hpp | 1 + src/kernel/routing/NetPoint.cpp | 6 +++++ src/kernel/routing/VivaldiZone.cpp | 4 +--- src/s4u/s4u_Host.cpp | 6 +++++ src/surf/sg_platf.cpp | 23 ++++++++----------- src/surf/xml/platf_private.hpp | 4 ++-- 8 files changed, 28 insertions(+), 19 deletions(-) diff --git a/include/simgrid/kernel/routing/NetPoint.hpp b/include/simgrid/kernel/routing/NetPoint.hpp index c5f553561d..33d1be544d 100644 --- a/include/simgrid/kernel/routing/NetPoint.hpp +++ b/include/simgrid/kernel/routing/NetPoint.hpp @@ -38,6 +38,7 @@ public: NetZoneImpl* get_englobing_zone() { return englobing_zone_; } /** @brief Set the NetZone in which this NetPoint is included */ NetPoint* set_englobing_zone(NetZoneImpl* netzone_p); + NetPoint* set_coordinates(const std::string& coords); bool is_netzone() const { return component_type_ == Type::NetZone; } bool is_host() const { return component_type_ == Type::Host; } diff --git a/include/simgrid/kernel/routing/VivaldiZone.hpp b/include/simgrid/kernel/routing/VivaldiZone.hpp index d7627b96c5..4e4f6af00e 100644 --- a/include/simgrid/kernel/routing/VivaldiZone.hpp +++ b/include/simgrid/kernel/routing/VivaldiZone.hpp @@ -47,7 +47,7 @@ namespace routing { class XBT_PRIVATE VivaldiZone : public ClusterZone { public: using ClusterZone::ClusterZone; - void set_peer_link(NetPoint* netpoint, double bw_in, double bw_out, const std::string& coord); + void set_peer_link(NetPoint* netpoint, double bw_in, double bw_out); void get_local_route(NetPoint* src, NetPoint* dst, RouteCreationArgs* into, double* latency) override; }; diff --git a/include/simgrid/s4u/Host.hpp b/include/simgrid/s4u/Host.hpp index 4ecd0d5857..07d7cc58da 100644 --- a/include/simgrid/s4u/Host.hpp +++ b/include/simgrid/s4u/Host.hpp @@ -163,6 +163,7 @@ public: int get_pstate() const; double get_pstate_speed(int pstate_index) const; Host* set_pstate(int pstate_index); + Host* set_coordinates(const std::string& coords); std::vector get_disks() const; /** diff --git a/src/kernel/routing/NetPoint.cpp b/src/kernel/routing/NetPoint.cpp index 14c4c70d95..fad35e5e8b 100644 --- a/src/kernel/routing/NetPoint.cpp +++ b/src/kernel/routing/NetPoint.cpp @@ -4,6 +4,7 @@ * under the terms of the license (GNU LGPL) which comes with this package. */ #include "simgrid/kernel/routing/NetPoint.hpp" +#include "simgrid/kernel/routing/VivaldiZone.hpp" #include "simgrid/s4u/Engine.hpp" #include "simgrid/s4u/Host.hpp" #include "xbt/log.h" @@ -33,6 +34,11 @@ NetPoint* NetPoint::set_englobing_zone(NetZoneImpl* netzone_p) return this; } +NetPoint* NetPoint::set_coordinates(const std::string& coords) +{ + new vivaldi::Coords(this, coords); + return this; +} } // namespace routing } // namespace kernel } // namespace simgrid diff --git a/src/kernel/routing/VivaldiZone.cpp b/src/kernel/routing/VivaldiZone.cpp index f073f37826..bab770979f 100644 --- a/src/kernel/routing/VivaldiZone.cpp +++ b/src/kernel/routing/VivaldiZone.cpp @@ -61,13 +61,11 @@ static std::vector* netpoint_get_coords(NetPoint* np) return &coords->coords; } -void VivaldiZone::set_peer_link(NetPoint* netpoint, double bw_in, double bw_out, const std::string& coord) +void VivaldiZone::set_peer_link(NetPoint* netpoint, double bw_in, double bw_out) { xbt_assert(netpoint->get_englobing_zone() == this, "Cannot add a peer link to a netpoint that is not in this netzone"); - new vivaldi::Coords(netpoint, coord); - std::string link_up = "link_" + netpoint->get_name() + "_UP"; std::string link_down = "link_" + netpoint->get_name() + "_DOWN"; resource::LinkImpl* linkUp = get_network_model()->create_link(link_up, std::vector(1, bw_out)); diff --git a/src/s4u/s4u_Host.cpp b/src/s4u/s4u_Host.cpp index 72dcc0f2c7..72c27ad7ca 100644 --- a/src/s4u/s4u_Host.cpp +++ b/src/s4u/s4u_Host.cpp @@ -305,6 +305,12 @@ int Host::get_pstate() const return this->pimpl_cpu->get_pstate(); } +Host* Host::set_coordinates(const std::string& coords) +{ + if (not coords.empty()) + kernel::actor::simcall([this, coords] { this->pimpl_netpoint_->set_coordinates(coords); }); + return this; +} std::vector Host::get_disks() const { return this->pimpl_->get_disks(); diff --git a/src/surf/sg_platf.cpp b/src/surf/sg_platf.cpp index b3e76c3a00..1f4eb20f9a 100644 --- a/src/surf/sg_platf.cpp +++ b/src/surf/sg_platf.cpp @@ -63,10 +63,8 @@ void sg_platf_exit() /** @brief Add a host to the current NetZone */ void sg_platf_new_host(const simgrid::kernel::routing::HostCreationArgs* args) { - simgrid::s4u::Host* host = routing_get_current()->create_host(args->id, args->speed_per_pstate); - - if (not args->coord.empty()) - new simgrid::kernel::routing::vivaldi::Coords(host->get_netpoint(), args->coord); + simgrid::s4u::Host* host = + routing_get_current()->create_host(args->id, args->speed_per_pstate)->set_coordinates(args->coord); if (args->properties) { host->set_properties(*args->properties); @@ -87,7 +85,7 @@ void sg_platf_new_host(const simgrid::kernel::routing::HostCreationArgs* args) } /** @brief Add a "router" to the network element list */ -simgrid::kernel::routing::NetPoint* sg_platf_new_router(const std::string& name, const char* coords) +simgrid::kernel::routing::NetPoint* sg_platf_new_router(const std::string& name, const std::string& coords) { xbt_assert(nullptr == simgrid::s4u::Engine::get_instance()->netpoint_by_name_or_null(name), "Refusing to create a router named '%s': this name already describes a node.", name.c_str()); @@ -96,8 +94,8 @@ simgrid::kernel::routing::NetPoint* sg_platf_new_router(const std::string& name, netpoint->set_englobing_zone(current_routing); XBT_DEBUG("Router '%s' has the id %u", netpoint->get_cname(), netpoint->id()); - if (coords && strcmp(coords, "")) - new simgrid::kernel::routing::vivaldi::Coords(netpoint, coords); + if (not coords.empty()) + netpoint->set_coordinates(coords); return netpoint; } @@ -231,7 +229,7 @@ void sg_platf_new_cluster(simgrid::kernel::routing::ClusterCreationArgs* cluster XBT_DEBUG("", cluster->router_id.c_str()); if (cluster->router_id.empty()) cluster->router_id = std::string(cluster->prefix) + cluster->id + "_router" + cluster->suffix; - current_zone->set_router(sg_platf_new_router(cluster->router_id, nullptr)); + current_zone->set_router(sg_platf_new_router(cluster->router_id, "")); // Make the backbone if ((cluster->bb_bw > 0) || (cluster->bb_lat > 0)) { @@ -395,13 +393,12 @@ void sg_platf_new_peer(const simgrid::kernel::routing::PeerCreationArgs* peer) simgrid::s4u::Host* host = zone->create_host(peer->id, std::vector{peer->speed}) ->set_state_profile(peer->state_trace) - ->set_speed_profile(peer->speed_trace); - - zone->set_peer_link(host->get_netpoint(), peer->bw_in, peer->bw_out, peer->coord); + ->set_speed_profile(peer->speed_trace) + ->set_coordinates(peer->coord) + ->seal(); - host->seal(); + zone->set_peer_link(host->get_netpoint(), peer->bw_in, peer->bw_out); } - /** * @brief Auxiliary function to build the object NetZoneImpl * diff --git a/src/surf/xml/platf_private.hpp b/src/surf/xml/platf_private.hpp index f48f6fb030..165da986c8 100644 --- a/src/surf/xml/platf_private.hpp +++ b/src/surf/xml/platf_private.hpp @@ -189,8 +189,8 @@ sg_platf_new_peer(const simgrid::kernel::routing::PeerCreationArgs* peer); // Ad XBT_PUBLIC void sg_platf_new_cluster(simgrid::kernel::routing::ClusterCreationArgs* clust); // Add a cluster to the current Zone XBT_PUBLIC void sg_platf_new_cabinet(const simgrid::kernel::routing::CabinetCreationArgs* cabinet); // Add a cabinet to the current Zone -XBT_PUBLIC simgrid::kernel::routing::NetPoint* // Add a router to the current Zone - sg_platf_new_router(const std::string&, const char* coords); +XBT_PUBLIC simgrid::kernel::routing::NetPoint* // Add a router to the current Zone +sg_platf_new_router(const std::string&, const std::string& coords); XBT_PUBLIC void sg_platf_new_route(simgrid::kernel::routing::RouteCreationArgs* route); // Add a route XBT_PUBLIC void sg_platf_new_bypassRoute(simgrid::kernel::routing::RouteCreationArgs* bypassroute); // Add a bypassRoute -- 2.20.1