const std::function<TorusLinkCb>& set_loopback,
const std::function<TorusLinkCb>& set_limiter)
{
- auto* zone = new kernel::routing::TorusZone(name);
- zone->set_topology(dimensions);
- if (parent)
- zone->set_parent(parent->get_impl());
-
int tot_elements = std::accumulate(dimensions.begin(), dimensions.end(), 1, std::multiplies<>());
- xbt_assert(tot_elements > 0, "TorusZone: incorrect dimensions, unable to create %d elements", tot_elements);
+ if (dimensions.empty() || tot_elements <= 0)
+ throw std::invalid_argument("TorusZone: incorrect dimensions parameter, each value must be > 0");
+ if (bandwidth <= 0)
+ throw std::invalid_argument("TorusZone: incorrect bandwidth for internode communication, bw=" +
+ std::to_string(bandwidth));
+ if (latency < 0)
+ throw std::invalid_argument("TorusZone: incorrect latency for internode communication, lat=" +
+ std::to_string(latency));
+
+ // auxiliary function to get dims from index
auto index_to_dims = [&dimensions](int index) {
std::vector<unsigned int> dims_array(dimensions.size());
for (int i = dimensions.size() - 1; i >= 0 && index > 0; --i) {
return dims_array;
};
+ auto* zone = new kernel::routing::TorusZone(name);
+ zone->set_topology(dimensions);
+ if (parent)
+ zone->set_parent(parent->get_impl());
+
for (int i = 0; i < tot_elements; i++) {
kernel::routing::NetPoint *netpoint = nullptr, *gw = nullptr;
auto dims = index_to_dims(i);
std::tie(netpoint, gw) = set_netpoint(zone->get_iface(), dims, i);
+ xbt_assert(netpoint, "TorusZone::set_netpoint(elem=%d): Invalid netpoint (nullptr)", i);
+ if (netpoint->is_netzone()) {
+ xbt_assert(gw && not gw->is_netzone(),
+ "TorusZone::set_netpoint(elem=%d): Netpoint (%s) is a netzone, but gateway (%s) is invalid", i,
+ netpoint->get_cname(), gw ? gw->get_cname() : "nullptr");
+ } else {
+ xbt_assert(not gw, "TorusZone: Netpoint (%s) isn't netzone, gateway must be nullptr", netpoint->get_cname());
+ }
// FIXME: add gateway if set
+
if (set_loopback) {
Link* loopback = set_loopback(zone->get_iface(), dims, i);
- xbt_assert(loopback, "Invalid loopback link (nullptr) for element %d", i);
+ xbt_assert(loopback, "TorusZone::set_loopback: Invalid loopback link (nullptr) for element %d", i);
zone->set_loopback();
zone->add_private_link_at(zone->node_pos(netpoint->id()), {loopback->get_impl(), loopback->get_impl()});
}
+
if (set_limiter) {
Link* limiter = set_limiter(zone->get_iface(), dims, i);
- xbt_assert(limiter, "Invalid limiter link (nullptr) for element %d", i);
+ xbt_assert(limiter, "TorusZone::set_limiter: Invalid limiter link (nullptr) for element %d", i);
zone->set_limiter();
zone->add_private_link_at(zone->node_pos_with_loopback(netpoint->id()),
{limiter->get_impl(), limiter->get_impl()});
}
+
kernel::routing::ClusterCreationArgs params;
params.id = name;
params.bw = bandwidth;
--- /dev/null
+/* Copyright (c) 2017-2021. The SimGrid Team. All rights reserved. */
+
+/* This program is free software; you can redistribute it and/or modify it
+ * under the terms of the license (GNU LGPL) which comes with this package. */
+
+#include "catch.hpp"
+
+#include "simgrid/kernel/routing/NetPoint.hpp"
+#include "simgrid/kernel/routing/TorusZone.hpp"
+#include "simgrid/s4u/Engine.hpp"
+#include "simgrid/s4u/Host.hpp"
+#include "simgrid/s4u/NetZone.hpp"
+#include "src/surf/network_interface.hpp"
+#include "src/surf/surf_interface.hpp" // create models
+#include "src/surf/xml/platf_private.hpp" // RouteCreationArgs and friends
+
+namespace {
+class EngineWrapper {
+ int argc = 1;
+ char* argv;
+
+public:
+ simgrid::s4u::Engine e;
+ explicit EngineWrapper(std::string name) : argv(&name[0]), e(&argc, &argv)
+ {
+ simgrid::s4u::create_full_zone("root");
+ surf_network_model_init_LegrandVelho();
+ surf_cpu_model_init_Cas01();
+ }
+};
+
+std::pair<simgrid::kernel::routing::NetPoint*, simgrid::kernel::routing::NetPoint*>
+create_host(simgrid::s4u::NetZone* zone, const std::vector<unsigned int>& coord, int id)
+{
+ simgrid::s4u::Host* host = zone->create_host(std::to_string(id), 1e9)->seal();
+ return std::make_pair(host->get_netpoint(), nullptr);
+}
+} // namespace
+
+TEST_CASE("kernel::routing::TorusZone: Creating Zone", "")
+{
+ using namespace simgrid::s4u;
+ EngineWrapper e("test");
+ auto create_host = [](NetZone* zone, const std::vector<unsigned int>& coord,
+ int id) -> std::pair<simgrid::kernel::routing::NetPoint*, simgrid::kernel::routing::NetPoint*> {
+ Host* host = zone->create_host(std::to_string(id), 1e9)->seal();
+ return std::make_pair(host->get_netpoint(), nullptr);
+ };
+ REQUIRE(create_torus_zone("test", e.e.get_netzone_root(), {3, 3, 3}, 1e9, 10,
+ simgrid::s4u::Link::SharingPolicy::SHARED, create_host));
+}
+
+TEST_CASE("kernel::routing::TorusZone: Invalid params", "")
+{
+ SECTION("Empty dimensions")
+ {
+ using namespace simgrid::s4u;
+ EngineWrapper e("test");
+ REQUIRE_THROWS_AS(create_torus_zone("test", e.e.get_netzone_root(), {}, 1e9, 10,
+ simgrid::s4u::Link::SharingPolicy::SHARED, create_host),
+ std::invalid_argument);
+ }
+ SECTION("One 0 dimension")
+ {
+ using namespace simgrid::s4u;
+ EngineWrapper e("test");
+ REQUIRE_THROWS_AS(create_torus_zone("test", e.e.get_netzone_root(), {3, 0, 2}, 1e9, 10,
+ simgrid::s4u::Link::SharingPolicy::SHARED, create_host),
+ std::invalid_argument);
+ }
+ SECTION("Invalid bandwidth")
+ {
+ using namespace simgrid::s4u;
+ EngineWrapper e("test");
+ REQUIRE_THROWS_AS(create_torus_zone("test", e.e.get_netzone_root(), {3, 2, 2}, 0, 10,
+ simgrid::s4u::Link::SharingPolicy::SHARED, create_host),
+ std::invalid_argument);
+ }
+ SECTION("Invalid latency")
+ {
+ using namespace simgrid::s4u;
+ EngineWrapper e("test");
+ REQUIRE_THROWS_AS(create_torus_zone("test", e.e.get_netzone_root(), {3, 2, 2}, 1e9, -10,
+ simgrid::s4u::Link::SharingPolicy::SHARED, create_host),
+ std::invalid_argument);
+ }
+}
\ No newline at end of file