From: Bruno Donassolo Date: Fri, 30 Apr 2021 09:50:29 +0000 (+0200) Subject: Torus/Fat-Tree/Dragonfly: Aggregate callbacks X-Git-Tag: v3.28~388 X-Git-Url: http://bilbo.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/38ffc837c5692a4d52e7610a67453a5335434bbd Torus/Fat-Tree/Dragonfly: Aggregate callbacks Put set callbacks in an object. Less (or encapsulated) arguments for create_zones. Remove create_cluster_zone (create_star_zone does its job for C++ interfaces). --- diff --git a/examples/cpp/clusters-multicpu/s4u-clusters-multicpu.cpp b/examples/cpp/clusters-multicpu/s4u-clusters-multicpu.cpp index 763326250a..a473bcdf98 100644 --- a/examples/cpp/clusters-multicpu/s4u-clusters-multicpu.cpp +++ b/examples/cpp/clusters-multicpu/s4u-clusters-multicpu.cpp @@ -171,8 +171,8 @@ static sg4::Link* create_limiter(sg4::NetZone* zone, const std::vectorseal(); } @@ -224,8 +224,8 @@ static void create_torus_cluster() static void create_fatTree_cluster() { /* create the fat tree cluster, 10Gbs link between elements in the cluster */ - sg4::create_fatTree_zone("cluster", nullptr, {2, {2, 3}, {1, 2}, {1, 1}}, 10e9, 10e-6, - sg4::Link::SharingPolicy::SPLITDUPLEX, create_hostzone, {}, create_limiter) + sg4::create_fatTree_zone("cluster", nullptr, {2, {2, 3}, {1, 2}, {1, 1}}, {create_hostzone, {}, create_limiter}, 10e9, + 10e-6, sg4::Link::SharingPolicy::SPLITDUPLEX) ->seal(); } @@ -272,8 +272,8 @@ static void create_fatTree_cluster() static void create_dragonfly_cluster() { /* create the dragonfly cluster, 10Gbs link between elements in the cluster */ - sg4::create_dragonfly_zone("cluster", nullptr, {{2, 2}, {2, 1}, {2, 2}, 2}, 10e9, 10e-6, - sg4::Link::SharingPolicy::SPLITDUPLEX, create_hostzone, {}, create_limiter) + sg4::create_dragonfly_zone("cluster", nullptr, {{2, 2}, {2, 1}, {2, 2}, 2}, {create_hostzone, {}, create_limiter}, + 10e9, 10e-6, sg4::Link::SharingPolicy::SPLITDUPLEX) ->seal(); } diff --git a/include/simgrid/kernel/routing/ClusterZone.hpp b/include/simgrid/kernel/routing/ClusterZone.hpp index fb6a615dcf..1280241ffb 100644 --- a/include/simgrid/kernel/routing/ClusterZone.hpp +++ b/include/simgrid/kernel/routing/ClusterZone.hpp @@ -115,10 +115,8 @@ public: } /** Fill the leaf retriving netpoint from a user's callback */ void fill_leaf_from_cb(unsigned int position, const std::vector& dimensions, - const std::function& set_netpoint_cb, - const std::function& set_loopback_cb, - const std::function& set_limiter_cb, NetPoint** node_netpoint, - s4u::Link** lb_link, s4u::Link** limiter_link); + const s4u::ClusterCallbacks& set_callbacks, NetPoint** node_netpoint, s4u::Link** lb_link, + s4u::Link** limiter_link); }; } // namespace routing } // namespace kernel diff --git a/include/simgrid/kernel/routing/TorusZone.hpp b/include/simgrid/kernel/routing/TorusZone.hpp index fbfd798ce9..9d6273e949 100644 --- a/include/simgrid/kernel/routing/TorusZone.hpp +++ b/include/simgrid/kernel/routing/TorusZone.hpp @@ -27,7 +27,7 @@ class XBT_PRIVATE TorusZone : public ClusterZone { public: using ClusterZone::ClusterZone; - void create_links_for_node(int id, int rank, unsigned int position); + void create_links(int id, int rank, unsigned int position); void get_local_route(NetPoint* src, NetPoint* dst, RouteCreationArgs* into, double* latency) override; void set_topology(const std::vector& dimensions); diff --git a/include/simgrid/s4u/NetZone.hpp b/include/simgrid/s4u/NetZone.hpp index 3b412762fc..085788eb38 100644 --- a/include/simgrid/s4u/NetZone.hpp +++ b/include/simgrid/s4u/NetZone.hpp @@ -146,35 +146,48 @@ private: // External constructors so that the types (and the types of their content) remain hidden XBT_PUBLIC NetZone* create_full_zone(const std::string& name); -XBT_PUBLIC NetZone* create_cluster_zone(const std::string& name); XBT_PUBLIC NetZone* create_star_zone(const std::string& name); XBT_PUBLIC NetZone* create_dijkstra_zone(const std::string& name, bool cache); XBT_PUBLIC NetZone* create_empty_zone(const std::string& name); XBT_PUBLIC NetZone* create_floyd_zone(const std::string& name); XBT_PUBLIC NetZone* create_vivaldi_zone(const std::string& name); XBT_PUBLIC NetZone* create_wifi_zone(const std::string& name); -/** - * @brief Callback used to set the netpoint and gateway located at some leaf of clusters (Torus, FatTree, etc) - * - * The netpoint can be either a host, router or another netzone. - * Gateway must be non-null if netpoint is a netzone - * - * @param zone: The newly create zone, needed for creating new resources (hosts, links) - * @param coord: the coordinates of the element - * @param id: Internal identifier of the element - * @return pair: returns a pair of netpoint and gateway. - */ -using ClusterNetPointCb = std::pair( - NetZone* zone, const std::vector& coord, int id); -/** - * @brief Callback used to set the links for some leaf of the cluster (Torus, FatTree, etc) - * - * @param zone: The newly create zone, needed for creating new resources (hosts, links) - * @param coord: the coordinates of the element - * @param id: Internal identifier of the element - * @return Pointer to the Link - */ -using ClusterLinkCb = Link*(NetZone* zone, const std::vector& coord, int id); + +// Extra data structure for complex constructors + +/** @brief Aggregates the callbacks used to build clusters netzones (Torus/Dragronfly/Fat-Tree) */ +struct ClusterCallbacks { + /** + * @brief Callback used to set the netpoint and gateway located at some leaf of clusters (Torus, FatTree, etc) + * + * The netpoint can be either a host, router or another netzone. + * Gateway must be non-null if netpoint is a netzone + * + * @param zone: The newly create zone, needed for creating new resources (hosts, links) + * @param coord: the coordinates of the element + * @param id: Internal identifier of the element + * @return pair: returns a pair of netpoint and gateway. + */ + using ClusterNetPointCb = std::pair( + NetZone* zone, const std::vector& coord, int id); + /** + * @brief Callback used to set the links for some leaf of the cluster (Torus, FatTree, etc) + * + * @param zone: The newly create zone, needed for creating new resources (hosts, links) + * @param coord: the coordinates of the element + * @param id: Internal identifier of the element + * @return Pointer to the Link + */ + using ClusterLinkCb = Link*(NetZone* zone, const std::vector& coord, int id); + + std::function netpoint; + std::function loopback = {}; + std::function limiter = {}; + explicit ClusterCallbacks(std::function set_netpoint) : netpoint(set_netpoint){/*nothing to do */}; + ClusterCallbacks(std::function set_netpoint, std::function set_loopback, + std::function set_limiter) + : netpoint(set_netpoint), loopback(set_loopback), limiter(set_limiter){/*nothing to do */}; +}; /** * @brief Create a torus zone * @@ -194,20 +207,16 @@ using ClusterLinkCb = Link*(NetZone* zone, const std::vector& coor * @param parent Pointer to parent's netzone (nullptr if root netzone). Needed to be able to create the resources inside * the netzone * @param dimensions List of positive integers (> 0) which determines the torus' dimensions + * @param set_callbacks Callbacks to set properties from cluster elements (netpoint, loopback and limiter) * @param bandwidth Characteristics of the inter-nodes link * @param latency Characteristics of the inter-nodes link * @param sharing_policy Characteristics of the inter-nodes link - * @param set_netpoint Callback to set the netpoint of an element in the torus - * @param set_loopback Callback to set the loopback - * @param set_limiter Callback to set the limiter * @return Pointer to new netzone */ XBT_PUBLIC NetZone* create_torus_zone(const std::string& name, const NetZone* parent, - const std::vector& dimensions, double bandwidth, double latency, - Link::SharingPolicy sharing_policy, - const std::function& set_netpoint, - const std::function& set_loopback = {}, - const std::function& set_limiter = {}); + const std::vector& dimensions, + const ClusterCallbacks& set_callbacks, double bandwidth, double latency, + Link::SharingPolicy sharing_policy); /** @brief Aggregates the parameters necessary to build a Fat-tree zone */ struct FatTreeParams { @@ -239,19 +248,15 @@ struct FatTreeParams { * @param parent Pointer to parent's netzone (nullptr if root netzone). Needed to be able to create the resources inside * the netzone * @param parameters Characteristics of this Fat-Tree + * @param set_callbacks Callbacks to set properties from cluster elements (netpoint, loopback and limiter) * @param bandwidth Characteristics of the inter-nodes link * @param latency Characteristics of the inter-nodes link * @param sharing_policy Characteristics of the inter-nodes link - * @param set_netpoint Callback to set the netpoint of an element in the torus - * @param set_loopback Callback to set the loopback - * @param set_limiter Callback to set the limiter * @return Pointer to new netzone */ XBT_PUBLIC NetZone* create_fatTree_zone(const std::string& name, const NetZone* parent, const FatTreeParams& parameters, - double bandwidth, double latency, Link::SharingPolicy sharing_policy, - const std::function& set_netpoint, - const std::function& set_loopback = {}, - const std::function& set_limiter = {}); + const ClusterCallbacks& set_callbacks, double bandwidth, double latency, + Link::SharingPolicy sharing_policy); /** @brief Aggregates the parameters necessary to build a Dragonfly zone */ struct DragonflyParams { @@ -285,20 +290,15 @@ struct DragonflyParams { * @param parent Pointer to parent's netzone (nullptr if root netzone). Needed to be able to create the resources inside * the netzone * @param parameters Characteristics of this Dragonfly + * @param set_callbacks Callbacks to set properties from cluster elements (netpoint, loopback and limiter) * @param bandwidth Characteristics of the inter-nodes link * @param latency Characteristics of the inter-nodes link * @param sharing_policy Characteristics of the inter-nodes link - * @param set_netpoint Callback to set the netpoint of an element in the torus - * @param set_loopback Callback to set the loopback - * @param set_limiter Callback to set the limiter * @return Pointer to new netzone */ XBT_PUBLIC NetZone* create_dragonfly_zone(const std::string& name, const NetZone* parent, - const DragonflyParams& parameters, double bandwidth, double latency, - Link::SharingPolicy sharing_policy, - const std::function& set_netpoint, - const std::function& set_loopback = {}, - const std::function& set_limiter = {}); + const DragonflyParams& parameters, const ClusterCallbacks& set_callbacks, + double bandwidth, double latency, Link::SharingPolicy sharing_policy); } // namespace s4u } // namespace simgrid diff --git a/src/kernel/routing/ClusterZone.cpp b/src/kernel/routing/ClusterZone.cpp index fc35ba1b3c..5d31b78f65 100644 --- a/src/kernel/routing/ClusterZone.cpp +++ b/src/kernel/routing/ClusterZone.cpp @@ -175,9 +175,7 @@ NetPoint* ClusterZone::get_gateway(unsigned int position) } void ClusterZone::fill_leaf_from_cb(unsigned int position, const std::vector& dimensions, - const std::function& set_netpoint_cb, - const std::function& set_loopback_cb, - const std::function& set_limiter_cb, NetPoint** node_netpoint, + const s4u::ClusterCallbacks& set_callbacks, NetPoint** node_netpoint, s4u::Link** lb_link, s4u::Link** limiter_link) { xbt_assert(node_netpoint, "Invalid node_netpoint parameter"); @@ -203,7 +201,7 @@ void ClusterZone::fill_leaf_from_cb(unsigned int position, const std::vectoris_netzone()) { xbt_assert(gw && not gw->is_netzone(), @@ -215,16 +213,16 @@ void ClusterZone::fill_leaf_from_cb(unsigned int position, const std::vectorid()), {loopback->get_impl(), loopback->get_impl()}); *lb_link = loopback; } - if (set_limiter_cb) { - s4u::Link* limiter = set_limiter_cb(get_iface(), dims, position); + if (set_callbacks.limiter) { + s4u::Link* limiter = set_callbacks.limiter(get_iface(), dims, position); xbt_assert(limiter, "set_limiter: Invalid limiter link (nullptr) for element %u", position); set_limiter(); add_private_link_at(node_pos_with_loopback(netpoint->id()), {limiter->get_impl(), limiter->get_impl()}); @@ -235,12 +233,4 @@ void ClusterZone::fill_leaf_from_cb(unsigned int position, const std::vectorget_iface(); -} -} // namespace s4u - } // namespace simgrid diff --git a/src/kernel/routing/DragonflyZone.cpp b/src/kernel/routing/DragonflyZone.cpp index 4a72dee9d4..f6e7d95efd 100644 --- a/src/kernel/routing/DragonflyZone.cpp +++ b/src/kernel/routing/DragonflyZone.cpp @@ -390,10 +390,8 @@ DragonflyParams::DragonflyParams(const std::pair& gr } NetZone* create_dragonfly_zone(const std::string& name, const NetZone* parent, const DragonflyParams& params, - double bandwidth, double latency, Link::SharingPolicy sharing_policy, - const std::function& set_netpoint, - const std::function& set_loopback, - const std::function& set_limiter) + const ClusterCallbacks& set_callbacks, double bandwidth, double latency, + Link::SharingPolicy sharing_policy) { /* initial checks */ if (bandwidth <= 0) @@ -419,7 +417,7 @@ NetZone* create_dragonfly_zone(const std::string& name, const NetZone* parent, c kernel::routing::NetPoint* netpoint; Link* limiter; Link* loopback; - zone->fill_leaf_from_cb(i, dimensions, set_netpoint, set_loopback, set_limiter, &netpoint, &loopback, &limiter); + zone->fill_leaf_from_cb(i, dimensions, set_callbacks, &netpoint, &loopback, &limiter); } return zone->get_iface(); diff --git a/src/kernel/routing/DragonflyZone_test.cpp b/src/kernel/routing/DragonflyZone_test.cpp index 254680c34b..0f0edb1bf1 100644 --- a/src/kernel/routing/DragonflyZone_test.cpp +++ b/src/kernel/routing/DragonflyZone_test.cpp @@ -32,74 +32,76 @@ TEST_CASE("kernel::routing::DragonflyZone: Creating Zone", "") { using namespace simgrid::s4u; EngineWrapper e("test"); - REQUIRE(create_dragonfly_zone("test", e.e.get_netzone_root(), {{3, 4}, {4, 3}, {5, 1}, 2}, 1e9, 10, - simgrid::s4u::Link::SharingPolicy::SHARED, create_host)); + ClusterCallbacks callbacks(create_host); + REQUIRE(create_dragonfly_zone("test", e.e.get_netzone_root(), {{3, 4}, {4, 3}, {5, 1}, 2}, callbacks, 1e9, 10, + simgrid::s4u::Link::SharingPolicy::SHARED)); } TEST_CASE("kernel::routing::DragonflyZone: Invalid params", "") { using namespace simgrid::s4u; EngineWrapper e("test"); + ClusterCallbacks callbacks(create_host); SECTION("0 nodes") { - REQUIRE_THROWS_AS(create_dragonfly_zone("test", e.e.get_netzone_root(), {{3, 4}, {4, 3}, {5, 1}, 0}, 1e9, 10, - simgrid::s4u::Link::SharingPolicy::SHARED, create_host), + REQUIRE_THROWS_AS(create_dragonfly_zone("test", e.e.get_netzone_root(), {{3, 4}, {4, 3}, {5, 1}, 0}, callbacks, 1e9, + 10, simgrid::s4u::Link::SharingPolicy::SHARED), std::invalid_argument); } SECTION("0 groups") { - REQUIRE_THROWS_AS(create_dragonfly_zone("test", e.e.get_netzone_root(), {{0, 4}, {4, 3}, {5, 1}, 2}, 1e9, 10, - simgrid::s4u::Link::SharingPolicy::SHARED, create_host), + REQUIRE_THROWS_AS(create_dragonfly_zone("test", e.e.get_netzone_root(), {{0, 4}, {4, 3}, {5, 1}, 2}, callbacks, 1e9, + 10, simgrid::s4u::Link::SharingPolicy::SHARED), std::invalid_argument); } SECTION("0 groups links") { - REQUIRE_THROWS_AS(create_dragonfly_zone("test", e.e.get_netzone_root(), {{3, 0}, {4, 3}, {5, 1}, 2}, 1e9, 10, - simgrid::s4u::Link::SharingPolicy::SHARED, create_host), + REQUIRE_THROWS_AS(create_dragonfly_zone("test", e.e.get_netzone_root(), {{3, 0}, {4, 3}, {5, 1}, 2}, callbacks, 1e9, + 10, simgrid::s4u::Link::SharingPolicy::SHARED), std::invalid_argument); } SECTION("0 chassis") { - REQUIRE_THROWS_AS(create_dragonfly_zone("test", e.e.get_netzone_root(), {{3, 4}, {0, 3}, {5, 1}, 2}, 1e9, 10, - simgrid::s4u::Link::SharingPolicy::SHARED, create_host), + REQUIRE_THROWS_AS(create_dragonfly_zone("test", e.e.get_netzone_root(), {{3, 4}, {0, 3}, {5, 1}, 2}, callbacks, 1e9, + 10, simgrid::s4u::Link::SharingPolicy::SHARED), std::invalid_argument); } SECTION("0 chassis links") { - REQUIRE_THROWS_AS(create_dragonfly_zone("test", e.e.get_netzone_root(), {{3, 4}, {4, 0}, {5, 1}, 2}, 1e9, 10, - simgrid::s4u::Link::SharingPolicy::SHARED, create_host), + REQUIRE_THROWS_AS(create_dragonfly_zone("test", e.e.get_netzone_root(), {{3, 4}, {4, 0}, {5, 1}, 2}, callbacks, 1e9, + 10, simgrid::s4u::Link::SharingPolicy::SHARED), std::invalid_argument); } SECTION("0 routers") { - REQUIRE_THROWS_AS(create_dragonfly_zone("test", e.e.get_netzone_root(), {{3, 4}, {4, 3}, {0, 1}, 2}, 1e9, 10, - simgrid::s4u::Link::SharingPolicy::SHARED, create_host), + REQUIRE_THROWS_AS(create_dragonfly_zone("test", e.e.get_netzone_root(), {{3, 4}, {4, 3}, {0, 1}, 2}, callbacks, 1e9, + 10, simgrid::s4u::Link::SharingPolicy::SHARED), std::invalid_argument); } SECTION("0 routers links") { - REQUIRE_THROWS_AS(create_dragonfly_zone("test", e.e.get_netzone_root(), {{3, 4}, {4, 3}, {5, 0}, 2}, 1e9, 10, - simgrid::s4u::Link::SharingPolicy::SHARED, create_host), + REQUIRE_THROWS_AS(create_dragonfly_zone("test", e.e.get_netzone_root(), {{3, 4}, {4, 3}, {5, 0}, 2}, callbacks, 1e9, + 10, simgrid::s4u::Link::SharingPolicy::SHARED), std::invalid_argument); } SECTION("0 bandwidth") { - REQUIRE_THROWS_AS(create_dragonfly_zone("test", e.e.get_netzone_root(), {{3, 4}, {4, 3}, {5, 1}, 2}, 0, 10, - simgrid::s4u::Link::SharingPolicy::SHARED, create_host), + REQUIRE_THROWS_AS(create_dragonfly_zone("test", e.e.get_netzone_root(), {{3, 4}, {4, 3}, {5, 1}, 2}, callbacks, 0, + 10, simgrid::s4u::Link::SharingPolicy::SHARED), std::invalid_argument); } SECTION("Negative latency") { - REQUIRE_THROWS_AS(create_dragonfly_zone("test", e.e.get_netzone_root(), {{3, 4}, {4, 3}, {5, 1}, 2}, 1e9, -10, - simgrid::s4u::Link::SharingPolicy::SHARED, create_host), + REQUIRE_THROWS_AS(create_dragonfly_zone("test", e.e.get_netzone_root(), {{3, 4}, {4, 3}, {5, 1}, 2}, callbacks, 1e9, + -10, simgrid::s4u::Link::SharingPolicy::SHARED), std::invalid_argument); } } \ No newline at end of file diff --git a/src/kernel/routing/FatTreeZone.cpp b/src/kernel/routing/FatTreeZone.cpp index 5bda9635a9..5613a21b7b 100644 --- a/src/kernel/routing/FatTreeZone.cpp +++ b/src/kernel/routing/FatTreeZone.cpp @@ -500,10 +500,8 @@ FatTreeParams::FatTreeParams(unsigned int n_levels, const std::vector& set_netpoint, - const std::function& set_loopback, - const std::function& set_limiter) + const ClusterCallbacks& set_callbacks, double bandwidth, double latency, + Link::SharingPolicy sharing_policy) { /* initial checks */ if (bandwidth <= 0) @@ -526,7 +524,7 @@ NetZone* create_fatTree_zone(const std::string& name, const NetZone* parent, con kernel::routing::NetPoint* netpoint; Link* limiter; Link* loopback; - zone->fill_leaf_from_cb(i, params.down, set_netpoint, set_loopback, set_limiter, &netpoint, &loopback, &limiter); + zone->fill_leaf_from_cb(i, params.down, set_callbacks, &netpoint, &loopback, &limiter); zone->add_processing_node(i, limiter ? limiter->get_impl() : nullptr, loopback ? loopback->get_impl() : nullptr); } diff --git a/src/kernel/routing/FatTreeZone_test.cpp b/src/kernel/routing/FatTreeZone_test.cpp index a1923f9b10..171314f91b 100644 --- a/src/kernel/routing/FatTreeZone_test.cpp +++ b/src/kernel/routing/FatTreeZone_test.cpp @@ -32,75 +32,77 @@ TEST_CASE("kernel::routing::FatTreeZone: Creating Zone", "") { using namespace simgrid::s4u; EngineWrapper e("test"); - REQUIRE(create_fatTree_zone("test", e.e.get_netzone_root(), {2, {4, 4}, {1, 2}, {1, 2}}, 1e9, 10, - simgrid::s4u::Link::SharingPolicy::SHARED, create_host)); + ClusterCallbacks callbacks(create_host); + REQUIRE(create_fatTree_zone("test", e.e.get_netzone_root(), {2, {4, 4}, {1, 2}, {1, 2}}, callbacks, 1e9, 10, + simgrid::s4u::Link::SharingPolicy::SHARED)); } TEST_CASE("kernel::routing::FatTreeZone: Invalid params", "") { using namespace simgrid::s4u; EngineWrapper e("test"); + ClusterCallbacks callbacks(create_host); SECTION("0 levels") { - REQUIRE_THROWS_AS(create_fatTree_zone("test", e.e.get_netzone_root(), {0, {4, 4}, {1, 2}, {1, 2}}, 1e9, 10, - simgrid::s4u::Link::SharingPolicy::SHARED, create_host), + REQUIRE_THROWS_AS(create_fatTree_zone("test", e.e.get_netzone_root(), {0, {4, 4}, {1, 2}, {1, 2}}, callbacks, 1e9, + 10, simgrid::s4u::Link::SharingPolicy::SHARED), std::invalid_argument); } SECTION("Invalid down links") { - REQUIRE_THROWS_AS(create_fatTree_zone("test", e.e.get_netzone_root(), {2, {4}, {1, 2}, {1, 2}}, 1e9, 10, - simgrid::s4u::Link::SharingPolicy::SHARED, create_host), + REQUIRE_THROWS_AS(create_fatTree_zone("test", e.e.get_netzone_root(), {2, {4}, {1, 2}, {1, 2}}, callbacks, 1e9, 10, + simgrid::s4u::Link::SharingPolicy::SHARED), std::invalid_argument); } SECTION("Invalid up links") { - REQUIRE_THROWS_AS(create_fatTree_zone("test", e.e.get_netzone_root(), {2, {4, 4}, {1}, {1, 2}}, 1e9, 10, - simgrid::s4u::Link::SharingPolicy::SHARED, create_host), + REQUIRE_THROWS_AS(create_fatTree_zone("test", e.e.get_netzone_root(), {2, {4, 4}, {1}, {1, 2}}, callbacks, 1e9, 10, + simgrid::s4u::Link::SharingPolicy::SHARED), std::invalid_argument); } SECTION("Invalid link count") { - REQUIRE_THROWS_AS(create_fatTree_zone("test", e.e.get_netzone_root(), {2, {4, 4}, {1, 2}, {1}}, 1e9, 10, - simgrid::s4u::Link::SharingPolicy::SHARED, create_host), + REQUIRE_THROWS_AS(create_fatTree_zone("test", e.e.get_netzone_root(), {2, {4, 4}, {1, 2}, {1}}, callbacks, 1e9, 10, + simgrid::s4u::Link::SharingPolicy::SHARED), std::invalid_argument); } SECTION("Down links with zeroes") { - REQUIRE_THROWS_AS(create_fatTree_zone("test", e.e.get_netzone_root(), {2, {4, 0}, {1, 2}, {1, 2}}, 1e9, 10, - simgrid::s4u::Link::SharingPolicy::SHARED, create_host), + REQUIRE_THROWS_AS(create_fatTree_zone("test", e.e.get_netzone_root(), {2, {4, 0}, {1, 2}, {1, 2}}, callbacks, 1e9, + 10, simgrid::s4u::Link::SharingPolicy::SHARED), std::invalid_argument); } SECTION("Up links with zeroes") { - REQUIRE_THROWS_AS(create_fatTree_zone("test", e.e.get_netzone_root(), {2, {4, 4}, {0, 2}, {1, 2}}, 1e9, 10, - simgrid::s4u::Link::SharingPolicy::SHARED, create_host), + REQUIRE_THROWS_AS(create_fatTree_zone("test", e.e.get_netzone_root(), {2, {4, 4}, {0, 2}, {1, 2}}, callbacks, 1e9, + 10, simgrid::s4u::Link::SharingPolicy::SHARED), std::invalid_argument); } SECTION("Link count with zeroes") { - REQUIRE_THROWS_AS(create_fatTree_zone("test", e.e.get_netzone_root(), {2, {4, 4}, {1, 2}, {1, 0}}, 1e9, 10, - simgrid::s4u::Link::SharingPolicy::SHARED, create_host), + REQUIRE_THROWS_AS(create_fatTree_zone("test", e.e.get_netzone_root(), {2, {4, 4}, {1, 2}, {1, 0}}, callbacks, 1e9, + 10, simgrid::s4u::Link::SharingPolicy::SHARED), std::invalid_argument); } SECTION("0 bandwidth") { - REQUIRE_THROWS_AS(create_fatTree_zone("test", e.e.get_netzone_root(), {2, {4, 4}, {1, 2}, {1, 2}}, 0, 10, - simgrid::s4u::Link::SharingPolicy::SHARED, create_host), + REQUIRE_THROWS_AS(create_fatTree_zone("test", e.e.get_netzone_root(), {2, {4, 4}, {1, 2}, {1, 2}}, callbacks, 0, 10, + simgrid::s4u::Link::SharingPolicy::SHARED), std::invalid_argument); } SECTION("Negative latency") { - REQUIRE_THROWS_AS(create_fatTree_zone("test", e.e.get_netzone_root(), {2, {4, 4}, {1, 2}, {1, 2}}, 1e9, -10, - simgrid::s4u::Link::SharingPolicy::SHARED, create_host), + REQUIRE_THROWS_AS(create_fatTree_zone("test", e.e.get_netzone_root(), {2, {4, 4}, {1, 2}, {1, 2}}, callbacks, 1e9, + -10, simgrid::s4u::Link::SharingPolicy::SHARED), std::invalid_argument); } } \ No newline at end of file diff --git a/src/kernel/routing/TorusZone.cpp b/src/kernel/routing/TorusZone.cpp index f8bf90a35a..793e9a6fd8 100644 --- a/src/kernel/routing/TorusZone.cpp +++ b/src/kernel/routing/TorusZone.cpp @@ -21,7 +21,7 @@ namespace simgrid { namespace kernel { namespace routing { -void TorusZone::create_links_for_node(int id, int rank, unsigned int position) +void TorusZone::create_links(int id, int rank, unsigned 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 @@ -197,10 +197,8 @@ void TorusZone::get_local_route(NetPoint* src, NetPoint* dst, RouteCreationArgs* namespace s4u { NetZone* create_torus_zone(const std::string& name, const NetZone* parent, const std::vector& dimensions, - double bandwidth, double latency, Link::SharingPolicy sharing_policy, - const std::function& set_netpoint, - const std::function& set_loopback, - const std::function& set_limiter) + const ClusterCallbacks& set_callbacks, double bandwidth, double latency, + Link::SharingPolicy sharing_policy) { int tot_elements = std::accumulate(dimensions.begin(), dimensions.end(), 1, std::multiplies<>()); if (dimensions.empty() || tot_elements <= 0) @@ -223,9 +221,9 @@ NetZone* create_torus_zone(const std::string& name, const NetZone* parent, const kernel::routing::NetPoint* netpoint; Link* limiter; Link* loopback; - zone->fill_leaf_from_cb(i, dimensions, set_netpoint, set_loopback, set_limiter, &netpoint, &loopback, &limiter); + zone->fill_leaf_from_cb(i, dimensions, set_callbacks, &netpoint, &loopback, &limiter); - zone->create_links_for_node(netpoint->id(), i, zone->node_pos_with_loopback_limiter(netpoint->id())); + zone->create_links(netpoint->id(), i, zone->node_pos_with_loopback_limiter(netpoint->id())); } return zone->get_iface(); diff --git a/src/kernel/routing/TorusZone_test.cpp b/src/kernel/routing/TorusZone_test.cpp index 4bc09ca3f4..526794d27b 100644 --- a/src/kernel/routing/TorusZone_test.cpp +++ b/src/kernel/routing/TorusZone_test.cpp @@ -32,37 +32,39 @@ TEST_CASE("kernel::routing::TorusZone: Creating Zone", "") { using namespace simgrid::s4u; EngineWrapper e("test"); - REQUIRE(create_torus_zone("test", e.e.get_netzone_root(), {3, 3, 3}, 1e9, 10, - simgrid::s4u::Link::SharingPolicy::SHARED, create_host)); + ClusterCallbacks callbacks(create_host); + REQUIRE(create_torus_zone("test", e.e.get_netzone_root(), {3, 3, 3}, callbacks, 1e9, 10, + simgrid::s4u::Link::SharingPolicy::SHARED)); } TEST_CASE("kernel::routing::TorusZone: Invalid params", "") { using namespace simgrid::s4u; EngineWrapper e("test"); + ClusterCallbacks callbacks(create_host); SECTION("Empty dimensions") { - REQUIRE_THROWS_AS(create_torus_zone("test", e.e.get_netzone_root(), {}, 1e9, 10, - simgrid::s4u::Link::SharingPolicy::SHARED, create_host), + REQUIRE_THROWS_AS(create_torus_zone("test", e.e.get_netzone_root(), {}, callbacks, 1e9, 10, + simgrid::s4u::Link::SharingPolicy::SHARED), std::invalid_argument); } SECTION("One 0 dimension") { - REQUIRE_THROWS_AS(create_torus_zone("test", e.e.get_netzone_root(), {3, 0, 2}, 1e9, 10, - simgrid::s4u::Link::SharingPolicy::SHARED, create_host), + REQUIRE_THROWS_AS(create_torus_zone("test", e.e.get_netzone_root(), {3, 0, 2}, callbacks, 1e9, 10, + simgrid::s4u::Link::SharingPolicy::SHARED), std::invalid_argument); } SECTION("Invalid bandwidth") { - REQUIRE_THROWS_AS(create_torus_zone("test", e.e.get_netzone_root(), {3, 2, 2}, 0, 10, - simgrid::s4u::Link::SharingPolicy::SHARED, create_host), + REQUIRE_THROWS_AS(create_torus_zone("test", e.e.get_netzone_root(), {3, 2, 2}, callbacks, 0, 10, + simgrid::s4u::Link::SharingPolicy::SHARED), std::invalid_argument); } SECTION("Invalid latency") { - REQUIRE_THROWS_AS(create_torus_zone("test", e.e.get_netzone_root(), {3, 2, 2}, 1e9, -10, - simgrid::s4u::Link::SharingPolicy::SHARED, create_host), + REQUIRE_THROWS_AS(create_torus_zone("test", e.e.get_netzone_root(), {3, 2, 2}, callbacks, 1e9, -10, + simgrid::s4u::Link::SharingPolicy::SHARED), std::invalid_argument); } } \ No newline at end of file diff --git a/src/surf/sg_platf.cpp b/src/surf/sg_platf.cpp index cf04a3b4cd..4df101cd62 100644 --- a/src/surf/sg_platf.cpp +++ b/src/surf/sg_platf.cpp @@ -217,8 +217,8 @@ static void sg_platf_new_cluster_hierarchical(const simgrid::kernel::routing::Cl using simgrid::kernel::routing::TorusZone; auto set_host = std::bind(sg_platf_cluster_create_host, cluster, _1, _2, _3); - std::function set_loopback{}; - std::function set_limiter{}; + std::function set_loopback{}; + std::function set_limiter{}; if (cluster->loopback_bw > 0 || cluster->loopback_lat > 0) { set_loopback = std::bind(sg_platf_cluster_create_loopback, cluster, _1, _2, _3); @@ -233,18 +233,18 @@ static void sg_platf_new_cluster_hierarchical(const simgrid::kernel::routing::Cl switch (cluster->topology) { case simgrid::kernel::routing::ClusterTopology::TORUS: zone = simgrid::s4u::create_torus_zone( - cluster->id, parent, TorusZone::parse_topo_parameters(cluster->topo_parameters), cluster->bw, cluster->lat, - cluster->sharing_policy, set_host, set_loopback, set_limiter); + cluster->id, parent, TorusZone::parse_topo_parameters(cluster->topo_parameters), + {set_host, set_loopback, set_limiter}, cluster->bw, cluster->lat, cluster->sharing_policy); break; case simgrid::kernel::routing::ClusterTopology::DRAGONFLY: zone = simgrid::s4u::create_dragonfly_zone( - cluster->id, parent, DragonflyZone::parse_topo_parameters(cluster->topo_parameters), cluster->bw, - cluster->lat, cluster->sharing_policy, set_host, set_loopback, set_limiter); + cluster->id, parent, DragonflyZone::parse_topo_parameters(cluster->topo_parameters), + {set_host, set_loopback, set_limiter}, cluster->bw, cluster->lat, cluster->sharing_policy); break; case simgrid::kernel::routing::ClusterTopology::FAT_TREE: zone = simgrid::s4u::create_fatTree_zone( - cluster->id, parent, FatTreeZone::parse_topo_parameters(cluster->topo_parameters), cluster->bw, cluster->lat, - cluster->sharing_policy, set_host, set_loopback, set_limiter); + cluster->id, parent, FatTreeZone::parse_topo_parameters(cluster->topo_parameters), + {set_host, set_loopback, set_limiter}, cluster->bw, cluster->lat, cluster->sharing_policy); break; default: THROW_IMPOSSIBLE;