From: Frederic Suter Date: Fri, 11 Aug 2017 10:06:14 +0000 (+0200) Subject: stringify cluster X-Git-Tag: v3_17~213 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/b7bae6a27325376248620283dafc43915142b254?ds=sidebyside stringify cluster --- diff --git a/include/simgrid/s4u/Engine.hpp b/include/simgrid/s4u/Engine.hpp index a42becaef6..e705bab613 100644 --- a/include/simgrid/s4u/Engine.hpp +++ b/include/simgrid/s4u/Engine.hpp @@ -75,7 +75,7 @@ public: simgrid::s4u::NetZone* getNetzoneByNameOrNull(const char* name); /** @brief Retrieve the netcard of the given name (or nullptr if not found) */ - simgrid::kernel::routing::NetPoint* getNetpointByNameOrNull(const char* name); + simgrid::kernel::routing::NetPoint* getNetpointByNameOrNull(std::string name); void getNetpointList(std::vector * list); void netpointRegister(simgrid::kernel::routing::NetPoint * card); void netpointUnregister(simgrid::kernel::routing::NetPoint * card); diff --git a/src/kernel/routing/ClusterZone.cpp b/src/kernel/routing/ClusterZone.cpp index 4cf5cb9c40..296f3f8e05 100644 --- a/src/kernel/routing/ClusterZone.cpp +++ b/src/kernel/routing/ClusterZone.cpp @@ -119,9 +119,9 @@ void ClusterZone::getGraph(xbt_graph_t graph, xbt_dict_t nodes, xbt_dict_t edges } } -void ClusterZone::create_links_for_node(sg_platf_cluster_cbarg_t cluster, int id, int /*rank*/, int position) +void ClusterZone::create_links_for_node(ClusterCreationArgs* cluster, int id, int /*rank*/, int position) { - std::string link_id = std::string(cluster->id) + "_link_" + std::to_string(id); + std::string link_id = cluster->id + "_link_" + std::to_string(id); LinkCreationArgs link; link.id = link_id; @@ -133,10 +133,8 @@ void ClusterZone::create_links_for_node(sg_platf_cluster_cbarg_t cluster, int id surf::LinkImpl *linkUp; surf::LinkImpl *linkDown; if (link.policy == SURF_LINK_FULLDUPLEX) { - std::string tmp_link = std::string(link_id) + "_UP"; - linkUp = surf::LinkImpl::byName(tmp_link); - tmp_link = std::string(link_id) + "_DOWN"; - linkDown = surf::LinkImpl::byName(tmp_link); + linkUp = surf::LinkImpl::byName(link_id + "_UP"); + linkDown = surf::LinkImpl::byName(link_id + "_DOWN"); } else { linkUp = surf::LinkImpl::byName(link_id); linkDown = linkUp; diff --git a/src/kernel/routing/ClusterZone.hpp b/src/kernel/routing/ClusterZone.hpp index 13e6aab984..9fe165366d 100644 --- a/src/kernel/routing/ClusterZone.hpp +++ b/src/kernel/routing/ClusterZone.hpp @@ -72,8 +72,8 @@ public: void getLocalRoute(NetPoint* src, NetPoint* dst, sg_platf_route_cbarg_t into, double* latency) override; void getGraph(xbt_graph_t graph, xbt_dict_t nodes, xbt_dict_t edges) override; - virtual void create_links_for_node(sg_platf_cluster_cbarg_t cluster, int id, int rank, int position); - virtual void parse_specific_arguments(sg_platf_cluster_cbarg_t cluster) + virtual void create_links_for_node(ClusterCreationArgs* cluster, int id, int rank, int position); + virtual void parse_specific_arguments(ClusterCreationArgs* cluster) { /* this routing method does not require any specific argument */ } diff --git a/src/kernel/routing/DragonflyZone.cpp b/src/kernel/routing/DragonflyZone.cpp index 89a312427b..2b76d0b7d1 100644 --- a/src/kernel/routing/DragonflyZone.cpp +++ b/src/kernel/routing/DragonflyZone.cpp @@ -41,7 +41,7 @@ void DragonflyZone::rankId_to_coords(int rankId, unsigned int (*coords)[4]) (*coords)[3] = rankId % numNodesPerBlade_; } -void DragonflyZone::parse_specific_arguments(sg_platf_cluster_cbarg_t cluster) +void DragonflyZone::parse_specific_arguments(ClusterCreationArgs* cluster) { std::vector parameters; std::vector tmp; diff --git a/src/kernel/routing/DragonflyZone.hpp b/src/kernel/routing/DragonflyZone.hpp index 760eac36d5..ceeeda348f 100644 --- a/src/kernel/routing/DragonflyZone.hpp +++ b/src/kernel/routing/DragonflyZone.hpp @@ -64,7 +64,7 @@ public: ~DragonflyZone() override; // void create_links_for_node(sg_platf_cluster_cbarg_t cluster, int id, int rank, int position) override; void getLocalRoute(NetPoint* src, NetPoint* dst, sg_platf_route_cbarg_t into, double* latency) override; - void parse_specific_arguments(sg_platf_cluster_cbarg_t cluster) override; + void parse_specific_arguments(ClusterCreationArgs* cluster) override; void seal() override; void generateRouters(); void generateLinks(); @@ -72,7 +72,7 @@ public: private: void rankId_to_coords(int rankId, unsigned int (*coords)[4]); - sg_platf_cluster_cbarg_t cluster_; + ClusterCreationArgs* cluster_; unsigned int numNodesPerBlade_ = 0; unsigned int numBladesPerChassis_ = 0; unsigned int numChassisPerGroup_ = 0; diff --git a/src/kernel/routing/FatTreeZone.cpp b/src/kernel/routing/FatTreeZone.cpp index 9e3cdbcd73..c6485c8540 100644 --- a/src/kernel/routing/FatTreeZone.cpp +++ b/src/kernel/routing/FatTreeZone.cpp @@ -356,7 +356,7 @@ void FatTreeZone::addLink(FatTreeNode* parent, unsigned int parentPort, FatTreeN this->links_.push_back(newLink); } -void FatTreeZone::parse_specific_arguments(sg_platf_cluster_cbarg_t cluster) +void FatTreeZone::parse_specific_arguments(ClusterCreationArgs* cluster) { std::vector parameters; std::vector tmp; @@ -441,7 +441,7 @@ void FatTreeZone::generateDotFile(const std::string& filename) const file.close(); } -FatTreeNode::FatTreeNode(sg_platf_cluster_cbarg_t cluster, int id, int level, int position) +FatTreeNode::FatTreeNode(ClusterCreationArgs* cluster, int id, int level, int position) : id(id), level(level), position(position) { LinkCreationArgs linkTemplate; @@ -463,7 +463,7 @@ FatTreeNode::FatTreeNode(sg_platf_cluster_cbarg_t cluster, int id, int level, in } } -FatTreeLink::FatTreeLink(sg_platf_cluster_cbarg_t cluster, FatTreeNode* downNode, FatTreeNode* upNode) +FatTreeLink::FatTreeLink(ClusterCreationArgs* cluster, FatTreeNode* downNode, FatTreeNode* upNode) : upNode(upNode), downNode(downNode) { static int uniqueId = 0; diff --git a/src/kernel/routing/FatTreeZone.hpp b/src/kernel/routing/FatTreeZone.hpp index e24867f904..c08e69eff5 100644 --- a/src/kernel/routing/FatTreeZone.hpp +++ b/src/kernel/routing/FatTreeZone.hpp @@ -51,7 +51,7 @@ public: * instead of passing by an upper level switch. */ surf::LinkImpl* loopback; - FatTreeNode(sg_platf_cluster_cbarg_t cluster, int id, int level, int position); + FatTreeNode(ClusterCreationArgs* cluster, int id, int level, int position); }; /** \brief Link in a fat tree (@ref FatTreeZone). @@ -61,7 +61,7 @@ public: */ class FatTreeLink { public: - FatTreeLink(sg_platf_cluster_cbarg_t cluster, FatTreeNode* source, FatTreeNode* destination); + FatTreeLink(ClusterCreationArgs* cluster, FatTreeNode* source, FatTreeNode* destination); /** Link going up in the tree */ surf::LinkImpl* upLink; /** Link going down in the tree */ @@ -113,7 +113,7 @@ public: * * It will also store the cluster for future use. */ - void parse_specific_arguments(sg_platf_cluster_cbarg_t cluster) override; + void parse_specific_arguments(ClusterCreationArgs* cluster) override; void addProcessingNode(int id); void generateDotFile(const std::string& filename = "fatTree.dot") const; @@ -129,7 +129,7 @@ private: std::vector links_; std::vector nodesByLevel_; - sg_platf_cluster_cbarg_t cluster_ = nullptr; + ClusterCreationArgs* cluster_ = nullptr; void addLink(FatTreeNode* parent, unsigned int parentPort, FatTreeNode* child, unsigned int childPort); int getLevelPosition(const unsigned int level); diff --git a/src/kernel/routing/TorusZone.cpp b/src/kernel/routing/TorusZone.cpp index cf312416ad..945fa9eb8e 100644 --- a/src/kernel/routing/TorusZone.cpp +++ b/src/kernel/routing/TorusZone.cpp @@ -31,7 +31,7 @@ TorusZone::TorusZone(NetZone* father, std::string name) : ClusterZone(father, na { } -void TorusZone::create_links_for_node(sg_platf_cluster_cbarg_t cluster, int id, int rank, int position) +void TorusZone::create_links_for_node(ClusterCreationArgs* cluster, int id, int rank, int position) { /* Create all links that exist in the torus. Each rank creates @a dimensions-1 links */ int dim_product = 1; // Needed to calculate the next neighbor_id @@ -74,7 +74,7 @@ void TorusZone::create_links_for_node(sg_platf_cluster_cbarg_t cluster, int id, rank++; } -void TorusZone::parse_specific_arguments(sg_platf_cluster_cbarg_t cluster) +void TorusZone::parse_specific_arguments(ClusterCreationArgs* cluster) { std::vector dimensions; boost::split(dimensions, cluster->topo_parameters, boost::is_any_of(",")); diff --git a/src/kernel/routing/TorusZone.hpp b/src/kernel/routing/TorusZone.hpp index 2b76f785a0..56d4c7008c 100644 --- a/src/kernel/routing/TorusZone.hpp +++ b/src/kernel/routing/TorusZone.hpp @@ -21,9 +21,9 @@ namespace routing { class XBT_PRIVATE TorusZone : public ClusterZone { public: explicit TorusZone(NetZone* father, std::string name); - void create_links_for_node(sg_platf_cluster_cbarg_t cluster, int id, int rank, int position) override; + void create_links_for_node(ClusterCreationArgs* cluster, int id, int rank, int position) override; void getLocalRoute(NetPoint* src, NetPoint* dst, sg_platf_route_cbarg_t into, double* latency) override; - void parse_specific_arguments(sg_platf_cluster_cbarg_t cluster) override; + void parse_specific_arguments(ClusterCreationArgs* cluster) override; private: std::vector dimensions_; diff --git a/src/s4u/s4u_engine.cpp b/src/s4u/s4u_engine.cpp index 4c13de0741..50d287e334 100644 --- a/src/s4u/s4u_engine.cpp +++ b/src/s4u/s4u_engine.cpp @@ -126,11 +126,12 @@ NetZone* Engine::getNetzoneByNameOrNull(const char* name) } /** @brief Retrieve the netpoint of the given name (or nullptr if not found) */ -simgrid::kernel::routing::NetPoint* Engine::getNetpointByNameOrNull(const char* name) +simgrid::kernel::routing::NetPoint* Engine::getNetpointByNameOrNull(std::string name) { auto netp = pimpl->netpoints_.find(name); return netp == pimpl->netpoints_.end() ? nullptr : netp->second; } + /** @brief Fill the provided vector with all existing netpoints */ void Engine::getNetpointList(std::vector* list) { diff --git a/src/surf/network_ns3.cpp b/src/surf/network_ns3.cpp index fb0f9cc7d2..a3f621f6a9 100644 --- a/src/surf/network_ns3.cpp +++ b/src/surf/network_ns3.cpp @@ -54,7 +54,7 @@ NetPointNs3::NetPointNs3() * Callbacks * *************/ -static void clusterCreation_cb(sg_platf_cluster_cbarg_t cluster) +static void clusterCreation_cb(ClusterCreationArgs* cluster) { for (int i : *cluster->radicals) { // Routers don't create a router on the other end of the private link by themselves. diff --git a/src/surf/sg_platf.cpp b/src/surf/sg_platf.cpp index 1214fd5589..474ef71fad 100644 --- a/src/surf/sg_platf.cpp +++ b/src/surf/sg_platf.cpp @@ -35,8 +35,7 @@ XBT_PRIVATE std::vector known_storages; namespace simgrid { namespace surf { -simgrid::xbt::signal on_cluster; - +simgrid::xbt::signal on_cluster; } } @@ -100,18 +99,18 @@ void sg_platf_new_host(sg_platf_host_cbarg_t args) } /** @brief Add a "router" to the network element list */ -simgrid::kernel::routing::NetPoint* sg_platf_new_router(const char* name, const char* coords) +simgrid::kernel::routing::NetPoint* sg_platf_new_router(std::string name, const char* coords) { simgrid::kernel::routing::NetZoneImpl* current_routing = routing_get_current(); if (current_routing->hierarchy_ == simgrid::kernel::routing::NetZoneImpl::RoutingMode::unset) current_routing->hierarchy_ = simgrid::kernel::routing::NetZoneImpl::RoutingMode::base; xbt_assert(nullptr == simgrid::s4u::Engine::getInstance()->getNetpointByNameOrNull(name), - "Refusing to create a router named '%s': this name already describes a node.", name); + "Refusing to create a router named '%s': this name already describes a node.", name.c_str()); simgrid::kernel::routing::NetPoint* netpoint = new simgrid::kernel::routing::NetPoint(name, simgrid::kernel::routing::NetPoint::Type::Router, current_routing); - XBT_DEBUG("Router '%s' has the id %u", name, netpoint->id()); + XBT_DEBUG("Router '%s' has the id %u", name.c_str(), netpoint->id()); if (coords && strcmp(coords, "")) new simgrid::kernel::routing::vivaldi::Coords(netpoint, coords); @@ -149,7 +148,7 @@ void sg_platf_new_link(LinkCreationArgs* link) } } -void sg_platf_new_cluster(sg_platf_cluster_cbarg_t cluster) +void sg_platf_new_cluster(ClusterCreationArgs* cluster) { using simgrid::kernel::routing::ClusterZone; using simgrid::kernel::routing::DragonflyZone; @@ -272,8 +271,8 @@ void sg_platf_new_cluster(sg_platf_cluster_cbarg_t cluster) // Add a router. XBT_DEBUG(" "); - XBT_DEBUG("", cluster->router_id); - if (not cluster->router_id || not strcmp(cluster->router_id, "")) { + XBT_DEBUG("", cluster->router_id.c_str()); + if (cluster->router_id.empty()) { std::string newid = std::string(cluster->prefix) + cluster->id + "_router" + cluster->suffix; current_as->router_ = sg_platf_new_router(newid.c_str(), NULL); } else { diff --git a/src/surf/xml/platf.hpp b/src/surf/xml/platf.hpp index 159aa1ae14..17c6f9e155 100644 --- a/src/surf/xml/platf.hpp +++ b/src/surf/xml/platf.hpp @@ -23,10 +23,10 @@ XBT_PUBLIC(void) surf_parse_warn(std::string msg); XBT_PUBLIC(double) surf_parse_get_double(std::string s); XBT_PUBLIC(int) surf_parse_get_int(std::string s); -XBT_PUBLIC(double) surf_parse_get_time(const char *string, const char *entity_kind, const char *name); -XBT_PUBLIC(double) surf_parse_get_size(const char *string, const char *entity_kind, const char *name); -XBT_PUBLIC(double) surf_parse_get_bandwidth(const char *string, const char *entity_kind, const char *name); -XBT_PUBLIC(double) surf_parse_get_speed(const char *string, const char *entity_kind, const char *name); +XBT_PUBLIC(double) surf_parse_get_time(const char* string, const char* entity_kind, std::string name); +XBT_PUBLIC(double) surf_parse_get_size(const char* string, const char* entity_kind, std::string name); +XBT_PUBLIC(double) surf_parse_get_bandwidth(const char* string, const char* entity_kind, std::string name); +XBT_PUBLIC(double) surf_parse_get_speed(const char* string, const char* entity_kind, std::string name); XBT_PUBLIC(int) surf_parse(); /* Entry-point to the parser */ diff --git a/src/surf/xml/platf_private.hpp b/src/surf/xml/platf_private.hpp index 03e3ed1f93..565fbe422a 100644 --- a/src/surf/xml/platf_private.hpp +++ b/src/surf/xml/platf_private.hpp @@ -93,28 +93,28 @@ typedef struct s_sg_platf_route_cbarg { std::vector* link_list; } s_sg_platf_route_cbarg_t; -typedef struct s_sg_platf_cluster_cbarg *sg_platf_cluster_cbarg_t; -typedef struct s_sg_platf_cluster_cbarg { - const char* id; - const char* prefix; - const char* suffix; - std::vector* radicals; +class ClusterCreationArgs { +public: + std::string id; + std::string prefix; + std::string suffix; + std::vector* radicals = nullptr; std::vector speeds; - int core_amount; - double bw; - double lat; - double bb_bw; - double bb_lat; - double loopback_bw; - double loopback_lat; - double limiter_link; + int core_amount = 0; + double bw = 0; + double lat = 0; + double bb_bw = 0; + double bb_lat = 0; + double loopback_bw = 0; + double loopback_lat = 0; + double limiter_link = 0; e_surf_cluster_topology_t topology; - const char* topo_parameters; + std::string topo_parameters; std::map* properties; - const char* router_id; + std::string router_id; e_surf_link_sharing_policy_t sharing_policy; e_surf_link_sharing_policy_t bb_sharing_policy; -} s_sg_platf_cluster_cbarg_t; +}; class CabinetCreationArgs { public: @@ -208,10 +208,10 @@ XBT_PUBLIC(void) sg_platf_new_host(sg_platf_host_cbarg_t host); // Add a XBT_PUBLIC(void) sg_platf_new_hostlink(HostLinkCreationArgs* h); // Add a host_link to the current Zone XBT_PUBLIC(void) sg_platf_new_link(LinkCreationArgs* link); // Add a link to the current Zone XBT_PUBLIC(void) sg_platf_new_peer(PeerCreationArgs* peer); // Add a peer to the current Zone -XBT_PUBLIC(void) sg_platf_new_cluster(sg_platf_cluster_cbarg_t clust); // Add a cluster to the current Zone +XBT_PUBLIC(void) sg_platf_new_cluster(ClusterCreationArgs* clust); // Add a cluster to the current Zone XBT_PUBLIC(void) sg_platf_new_cabinet(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 char* name, const char* coords); +sg_platf_new_router(std::string, const char* coords); XBT_PUBLIC(void) sg_platf_new_route (sg_platf_route_cbarg_t route); // Add a route XBT_PUBLIC(void) sg_platf_new_bypassRoute (sg_platf_route_cbarg_t bypassroute); // Add a bypassRoute @@ -246,8 +246,7 @@ SG_END_DECL() namespace simgrid { namespace surf { -extern XBT_PRIVATE simgrid::xbt::signal on_cluster; - +extern XBT_PRIVATE simgrid::xbt::signal on_cluster; } } diff --git a/src/surf/xml/surfxml_sax_cb.cpp b/src/surf/xml/surfxml_sax_cb.cpp index 53a931d54d..0178db7052 100644 --- a/src/surf/xml/surfxml_sax_cb.cpp +++ b/src/surf/xml/surfxml_sax_cb.cpp @@ -144,8 +144,9 @@ struct unit_scale { }; /* Note: field `unit' for the last element of parameter `units' should be nullptr. */ -static double surf_parse_get_value_with_unit(const char *string, const struct unit_scale *units, - const char *entity_kind, const char *name, const char *error_msg, const char *default_unit) +static double surf_parse_get_value_with_unit(const char* string, const struct unit_scale* units, + const char* entity_kind, std::string name, const char* error_msg, + const char* default_unit) { char* ptr; int i; @@ -159,7 +160,7 @@ static double surf_parse_get_value_with_unit(const char *string, const struct un if (res == 0) return res; // Ok, 0 can be unit-less - XBT_WARN("Deprecated unit-less value '%s' for %s %s. %s",string, entity_kind, name, error_msg); + XBT_WARN("Deprecated unit-less value '%s' for %s %s. %s", string, entity_kind, name.c_str(), error_msg); ptr = (char*)default_unit; } for (i = 0; units[i].unit != nullptr && strcmp(ptr, units[i].unit) != 0; i++); @@ -171,7 +172,7 @@ static double surf_parse_get_value_with_unit(const char *string, const struct un return res; } -double surf_parse_get_time(const char *string, const char *entity_kind, const char *name) +double surf_parse_get_time(const char* string, const char* entity_kind, std::string name) { const struct unit_scale units[] = { { "w", 7 * 24 * 60 * 60 }, @@ -189,7 +190,7 @@ double surf_parse_get_time(const char *string, const char *entity_kind, const ch "Append 's' to your time to get seconds", "s"); } -double surf_parse_get_size(const char *string, const char *entity_kind, const char *name) +double surf_parse_get_size(const char* string, const char* entity_kind, std::string name) { const struct unit_scale units[] = { { "EiB", pow(1024, 6) }, @@ -224,7 +225,7 @@ double surf_parse_get_size(const char *string, const char *entity_kind, const ch "Append 'B' to get bytes (or 'b' for bits but 1B = 8b).", "B"); } -double surf_parse_get_bandwidth(const char *string, const char *entity_kind, const char *name) +double surf_parse_get_bandwidth(const char* string, const char* entity_kind, std::string name) { const struct unit_scale units[] = { { "EiBps", pow(1024, 6) }, @@ -257,7 +258,7 @@ double surf_parse_get_bandwidth(const char *string, const char *entity_kind, con "Append 'Bps' to get bytes per second (or 'bps' for bits but 1Bps = 8bps)", "Bps"); } -double surf_parse_get_speed(const char *string, const char *entity_kind, const char *name) +double surf_parse_get_speed(const char* string, const char* entity_kind, std::string name) { const struct unit_scale units[] = { { "yottaflops", 1e24 }, @@ -284,7 +285,8 @@ double surf_parse_get_speed(const char *string, const char *entity_kind, const c "Append 'f' or 'flops' to your speed to get flop per second", "f"); } -static std::vector surf_parse_get_all_speeds(char* speeds, const char* entity_kind, const char* id){ +static std::vector surf_parse_get_all_speeds(char* speeds, const char* entity_kind, std::string id) +{ std::vector speed_per_pstate; @@ -555,9 +557,8 @@ void STag_surfxml_router(){ } void ETag_surfxml_cluster(){ - s_sg_platf_cluster_cbarg_t cluster; - memset(&cluster,0,sizeof(cluster)); - cluster.properties = current_property_set; + ClusterCreationArgs cluster; + cluster.properties = current_property_set; current_property_set = nullptr; cluster.id = A_surfxml_cluster_id;