Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add a add_route with s4u::Link instead of LinkInRoute
authorMartin Quinson <martin.quinson@ens-rennes.fr>
Wed, 19 Jul 2023 23:54:23 +0000 (01:54 +0200)
committerMartin Quinson <martin.quinson@ens-rennes.fr>
Wed, 19 Jul 2023 23:54:23 +0000 (01:54 +0200)
27 files changed:
ChangeLog
examples/cpp/comm-failure/s4u-comm-failure.cpp
examples/cpp/comm-failure/s4u-comm-failure.tesh
examples/cpp/network-factors/s4u-network-factors.cpp
examples/cpp/network-nonlinear/s4u-network-nonlinear.cpp
examples/cpp/platform-comm-serialize/s4u-platform-comm-serialize.cpp
examples/cpp/platform-failures/s4u-platform-failures.cpp
examples/cpp/plugin-prodcons/s4u-plugin-prodcons.cpp
examples/python/comm-failure/comm-failure.py
examples/python/comm-failure/comm-failure.tesh
examples/python/network-nonlinear/network-nonlinear.py
examples/python/platform-comm-serialize/platform-comm-serialize.py
examples/smpi/comm_dynamic_costs/comm-dynamic-cost.cpp
include/simgrid/s4u/NetZone.hpp
src/bindings/python/simgrid_python.cpp
src/kernel/xml/sg_platf.cpp
src/s4u/s4u_Netzone.cpp
teshsuite/models/cm02-set-lat-bw/cm02-set-lat-bw.cpp
teshsuite/models/cm02-tcpgamma/cm02-tcpgamma.cpp
teshsuite/models/issue105/issue105.cpp
teshsuite/models/ptask-subflows/ptask-subflows.cpp
teshsuite/python/platform-mix/platform-mix.py
teshsuite/s4u/comm-fault-scenarios/comm-fault-scenarios.cpp
teshsuite/s4u/monkey-masterworkers/monkey-masterworkers.cpp
teshsuite/s4u/monkey-masterworkers/monkey-masterworkers.py
teshsuite/s4u/monkey-semaphore/monkey-semaphore.cpp
teshsuite/s4u/seal-platform/seal-platform.cpp

index 4015db4..3e54838 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -3,6 +3,8 @@ SimGrid (3.34.1) not released (Target: fall 2023)
 S4U:
  - New class ActivitySet to ease wait_any()/test_any()/wait_all()
  - New function NetZone::add_route(host1, host2, links) when you don't need gateways
+   Also add a variant with s4u::Link, when you don't want to specify the directions
+   on symmetric routes.
 
 Python:
  - Make the host_load plugin available from Python. See examples/python/plugin-host-load
index 8544a4c..0ce5522 100644 (file)
@@ -82,12 +82,11 @@ int main(int argc, char** argv)
   auto* host1 = zone->create_host("Host1", "1f");
   auto* host2 = zone->create_host("Host2", "1f");
   auto* host3 = zone->create_host("Host3", "1f");
+  auto* link2 = zone->create_link("linkto2", "1bps")->seal();
+  auto* link3 = zone->create_link("linkto3", "1bps")->seal();
 
-  sg4::LinkInRoute linkto2{zone->create_link("linkto2", "1bps")->seal()};
-  sg4::LinkInRoute linkto3{zone->create_link("linkto3", "1bps")->seal()};
-
-  zone->add_route(host1, host2, {linkto2}, false);
-  zone->add_route(host1, host3, {linkto3}, false);
+  zone->add_route(host1, host2, {link2});
+  zone->add_route(host1, host3, {link3});
   zone->seal();
 
   sg4::Actor::create("Sender", host1, Sender("mailbox2", "mailbox3"));
index f3dcc62..8a58871 100644 (file)
@@ -14,4 +14,4 @@ $ ${bindir:=.}/s4u-comm-failure "--log=root.fmt:[%10.6r]%e(%i:%a@%h)%e%m%n"
 > [ 10.000000] (1:Sender@Host1)   Comm to mailbox3 has state: STARTED
 > [ 10.000000] (1:Sender@Host1) Waiting on a FAILED comm raises an exception: 'Cannot wait for a failed communication'
 > [ 10.000000] (1:Sender@Host1) Wait for remaining comm, just to be nice
-> [ 16.494845] (3:Receiver@Host3) Receiver has received successfully!
+> [ 17.319588] (3:Receiver@Host3) Receiver has received successfully!
index 36ca183..7cb9437 100644 (file)
@@ -78,8 +78,8 @@ static void load_platform()
     /* add link UP/DOWN for communications from the host */
     root->add_route(host->get_netpoint(), nullptr, nullptr, nullptr, {{l, sg4::LinkInRoute::Direction::UP}}, true);
 
-    const sg4::Link* loopback = root->create_link(hostname + "_loopback", BW_LOCAL)->set_latency(LATENCY)->seal();
-    root->add_route(host, host, {sg4::LinkInRoute(loopback)});
+    sg4::Link* loopback = root->create_link(hostname + "_loopback", BW_LOCAL)->set_latency(LATENCY)->seal();
+    root->add_route(host, host, {loopback});
   }
 
   root->seal();
index 0e1c821..d109be7 100644 (file)
@@ -131,7 +131,7 @@ static void load_platform()
   link->set_latency(10e-6)->seal();
 
   /* create routes between nodes */
-  zone->add_route(sender, receiver, {{link, sg4::LinkInRoute::Direction::UP}}, true);
+  zone->add_route(sender, receiver, {link});
   zone->seal();
 
   /* create actors Sender/Receiver */
index 8db9a7f..1e637ff 100644 (file)
@@ -109,7 +109,7 @@ int main(int argc, char* argv[])
       zone->create_split_duplex_link("link1", 10e9)->set_latency(10e-6)->set_concurrency_limit(2)->seal();
 
   /* create routes between nodes */
-  zone->add_route(sender, receiver, {{link, sg4::LinkInRoute::Direction::UP}}, true);
+  zone->add_route(sender, receiver, {link});
   zone->seal();
 
   /* create actors Sender/Receiver */
index 334bbb7..f622d90 100644 (file)
@@ -118,8 +118,8 @@ int main(int argc, char* argv[])
   // Add a new host programatically, and attach a state profile to it
   auto* root     = e.get_netzone_root();
   auto* lilibeth = root->create_host("Lilibeth", 1e15);
-  auto link      = sg4::LinkInRoute(e.link_by_name("10"));
-  root->add_route(e.host_by_name("Tremblay"), lilibeth, {link}, true);
+  auto link      = e.link_by_name("10");
+  root->add_route(e.host_by_name("Tremblay"), lilibeth, {link});
   lilibeth->set_state_profile(simgrid::kernel::profile::ProfileBuilder::from_string("lilibeth_profile", R"(
 4 0
 5 1
index 4483303..828d3fc 100644 (file)
@@ -70,7 +70,8 @@ int main(int argc, char* argv[])
   }
 
   auto* router = cluster->create_router("cluster_router");
-  cluster->add_route(router, nullptr, nullptr, nullptr, {});
+  std::vector<sg4::LinkInRoute> links; // empty
+  cluster->add_route(router, nullptr, nullptr, nullptr, links);
 
   simgrid::plugin::ProducerConsumerPtr<int> pc = simgrid::plugin::ProducerConsumer<int>::create(2);
 
index 9f6f086..c0ccb67 100644 (file)
@@ -66,11 +66,11 @@ def main():
     host2 = zone.create_host("Host2", "1f")
     host3 = zone.create_host("Host3", "1f")
 
-    link_to_2 = LinkInRoute(zone.create_link("link_to_2", "1bps").seal())
-    link_to_3 = LinkInRoute(zone.create_link("link_to_3", "1bps").seal())
+    link_to_2 = zone.create_link("link_to_2", "1bps").seal()
+    link_to_3 = zone.create_link("link_to_3", "1bps").seal()
 
-    zone.add_route(host1, host2, [link_to_2], False)
-    zone.add_route(host1, host3, [link_to_3], False)
+    zone.add_route(host1, host2, [link_to_2])
+    zone.add_route(host1, host3, [link_to_3])
     zone.seal()
 
     Actor.create("Sender", host1, sender, "mailbox2", "mailbox3")
index ee26ae8..8f4de0e 100644 (file)
@@ -14,4 +14,4 @@ $ ${pythoncmd:=python3} ${PYTHON_TOOL_OPTIONS:=} ${bindir:=.}/comm-failure.py "-
 > [ 10.000000] (1:Sender@Host1)   Comm to mailbox3 has state: STARTED
 > [ 10.000000] (1:Sender@Host1) Waiting on a FAILED comm raises an exception: 'Cannot wait for a failed communication'
 > [ 10.000000] (1:Sender@Host1) Wait for remaining comm, just to be nice
-> [ 16.494845] (3:Receiver-2@Host3) Receiver has received successfully (mailbox3)!
+> [ 17.319588] (3:Receiver-2@Host3) Receiver has received successfully (mailbox3)!
index fc957d8..7bc1218 100644 (file)
@@ -104,8 +104,7 @@ def load_platform():
     link.set_latency(10e-6).seal()
 
     # create routes between nodes
-    zone.add_route(sender.netpoint, receiver.netpoint, None, None,
-                   [LinkInRoute(link, LinkInRoute.Direction.UP)], True)
+    zone.add_route(sender, receiver, [link])
     zone.seal()
 
     # create actors Sender/Receiver
index b50b60c..bbd871d 100644 (file)
@@ -70,14 +70,7 @@ def main():
     link = zone.create_split_duplex_link("link1", 10e9).set_latency(10e-6).set_concurrency_limit(2).seal()
 
     # create routes between nodes
-    zone.add_route(
-        sender_host.netpoint,
-        receiver_host.netpoint,
-        None,
-        None,
-        [LinkInRoute(link, LinkInRoute.UP)],
-        True
-    )
+    zone.add_route(sender_host, receiver_host, [link])
     zone.seal()
 
     # create actors Sender/Receiver
index 9688bed..470836b 100644 (file)
@@ -47,8 +47,7 @@ void load_platform(const sg4::Engine& /*e*/)
 
   const sg4::Link* link9 = root->create_split_duplex_link("9", "7.20975MBps")->set_latency("1.461517ms")->seal();
 
-  root->add_route(tremblay->get_netpoint(), jupiter->get_netpoint(), nullptr, nullptr,
-                  {{link9, sg4::LinkInRoute::Direction::UP}}, true);
+  root->add_route(tremblay, jupiter, {link9});
   root->seal();
 
   /* set cost callback for MPI_Send and MPI_Recv */
index 8552a90..e9b909f 100644 (file)
@@ -81,6 +81,22 @@ public:
    */
   void add_route(kernel::routing::NetPoint* src, kernel::routing::NetPoint* dst, kernel::routing::NetPoint* gw_src,
                  kernel::routing::NetPoint* gw_dst, const std::vector<LinkInRoute>& link_list, bool symmetrical = true);
+  /**
+   * @brief Add a route between 2 netpoints, and same in other direction
+   *
+   * Create a route:
+   * - route between 2 hosts/routers in same netzone, no gateway is needed
+   * - route between 2 netzones, connecting 2 gateways.
+   *
+   * @param src Source netzone's netpoint
+   * @param dst Destination netzone' netpoint
+   * @param gw_src Netpoint of the gateway in the source netzone
+   * @param gw_dst Netpoint of the gateway in the destination netzone
+   * @param link_list List of links
+   */
+  void add_route(kernel::routing::NetPoint* src, kernel::routing::NetPoint* dst, kernel::routing::NetPoint* gw_src,
+                 kernel::routing::NetPoint* gw_dst, const std::vector<const Link*>& links);
+
   /**
    * @brief Add a route between 2 hosts
    *
@@ -90,6 +106,14 @@ public:
    * @param symmetrical Bi-directional communication
    */
   void add_route(const Host* src, const Host* dst, const std::vector<LinkInRoute>& link_list, bool symmetrical = true);
+  /**
+   * @brief Add a route between 2 hosts
+   *
+   * @param src Source host
+   * @param dst Destination host
+   * @param link_list List of links. The UP direction will be used on src->dst and DOWN direction on dst->src
+   */
+  void add_route(const Host* src, const Host* dst, const std::vector<const Link*>& links);
 
   void add_bypass_route(kernel::routing::NetPoint* src, kernel::routing::NetPoint* dst,
                         kernel::routing::NetPoint* gw_src, kernel::routing::NetPoint* gw_dst,
index a2abe30..c431875 100644 (file)
@@ -247,6 +247,10 @@ PYBIND11_MODULE(simgrid, m)
            py::overload_cast<const simgrid::s4u::Host*, const simgrid::s4u::Host*,
                              const std::vector<simgrid::s4u::LinkInRoute>&, bool>(&simgrid::s4u::NetZone::add_route),
            "Add a route between 2 netpoints")
+      .def("add_route",
+           py::overload_cast<const simgrid::s4u::Host*, const simgrid::s4u::Host*,
+                             const std::vector<const simgrid::s4u::Link*>&>(&simgrid::s4u::NetZone::add_route),
+           "Add a route between 2 netpoints")
       .def("create_host", py::overload_cast<const std::string&, double>(&simgrid::s4u::NetZone::create_host),
            "Creates a host")
       .def("create_host",
index b4b4a32..3d85fe3 100644 (file)
@@ -331,7 +331,8 @@ static void sg_platf_new_cluster_flat(simgrid::kernel::routing::ClusterCreationA
   if (cluster->router_id.empty())
     cluster->router_id = cluster->prefix + cluster->id + "_router" + cluster->suffix;
   auto* router = zone->create_router(cluster->router_id);
-  zone->add_route(router, nullptr, nullptr, nullptr, {});
+  std::vector<simgrid::s4u::LinkInRoute> links;
+  zone->add_route(router, nullptr, nullptr, nullptr, links);
 
   simgrid::kernel::routing::on_cluster_creation(*cluster);
 }
index 165b0f3..49b23a0 100644 (file)
@@ -91,11 +91,35 @@ void NetZone::add_route(kernel::routing::NetPoint* src, kernel::routing::NetPoin
 {
   pimpl_->add_route(src, dst, gw_src, gw_dst, link_list, symmetrical);
 }
+void NetZone::add_route(kernel::routing::NetPoint* src, kernel::routing::NetPoint* dst,
+                        kernel::routing::NetPoint* gw_src, kernel::routing::NetPoint* gw_dst,
+                        const std::vector<const Link*>& links)
+{
+  std::vector<LinkInRoute> links_direct;
+  std::vector<LinkInRoute> links_reverse;
+  for (auto* l : links) {
+    links_direct.emplace_back(LinkInRoute(l, LinkInRoute::Direction::UP));
+    links_reverse.emplace_back(LinkInRoute(l, LinkInRoute::Direction::DOWN));
+  }
+  pimpl_->add_route(src, dst, gw_src, gw_dst, links_direct, false);
+  pimpl_->add_route(dst, src, gw_dst, gw_src, links_reverse, false);
+}
 
 void NetZone::add_route(const Host* src, const Host* dst, const std::vector<LinkInRoute>& link_list, bool symmetrical)
 {
   pimpl_->add_route(src->get_netpoint(), dst->get_netpoint(), nullptr, nullptr, link_list, symmetrical);
 }
+void NetZone::add_route(const Host* src, const Host* dst, const std::vector<const Link*>& links)
+{
+  std::vector<LinkInRoute> links_direct;
+  std::vector<LinkInRoute> links_reverse;
+  for (auto* l : links) {
+    links_direct.emplace_back(LinkInRoute(l, LinkInRoute::Direction::UP));
+    links_reverse.emplace_back(LinkInRoute(l, LinkInRoute::Direction::DOWN));
+  }
+  pimpl_->add_route(src->get_netpoint(), dst->get_netpoint(), nullptr, nullptr, links_direct, false);
+  pimpl_->add_route(dst->get_netpoint(), src->get_netpoint(), nullptr, nullptr, links_reverse, false);
+}
 
 void NetZone::add_bypass_route(kernel::routing::NetPoint* src, kernel::routing::NetPoint* dst,
                                kernel::routing::NetPoint* gw_src, kernel::routing::NetPoint* gw_dst,
index 5f2c22e..1751a7d 100644 (file)
@@ -112,11 +112,8 @@ int main(int argc, char** argv)
     links[name] = zone->create_link(name, 1e9)->set_latency(1e-9)->seal();
   }
   links["L0"] = zone->create_link("L0", 1e3)->seal();
-  zone->add_route(hosts["S1"]->get_netpoint(), hosts["C1"]->get_netpoint(), nullptr, nullptr,
-                  {sg4::LinkInRoute(links["L1"]), sg4::LinkInRoute(links["L0"]), sg4::LinkInRoute(links["L2"])});
-  zone->add_route(hosts["S2"]->get_netpoint(), hosts["C2"]->get_netpoint(), nullptr, nullptr,
-                  {sg4::LinkInRoute(links["L3"]), sg4::LinkInRoute(links["L0"]), sg4::LinkInRoute(links["L4"])});
-
+  zone->add_route(hosts["S1"], hosts["C1"], {links["L1"], links["L0"], links["L2"]});
+  zone->add_route(hosts["S2"], hosts["C2"], {links["L3"], links["L0"], links["L4"]});
   zone->seal();
 
   sg4::Actor::create("", hosts["S1"], sender, "C1", nullptr);
index 966f548..4dfd24f 100644 (file)
@@ -86,7 +86,7 @@ int main(int argc, char** argv)
   auto const* host1 = zone->create_host("host1", 1e6)->seal();
   auto const* host2 = zone->create_host("host2", 1e6)->seal();
   auto* testlink    = zone->create_link("L1", 1e10)->seal();
-  zone->add_route(host1->get_netpoint(), host2->get_netpoint(), nullptr, nullptr, {sg4::LinkInRoute(testlink)});
+  zone->add_route(host1, host2, {testlink});
 
   simgrid::s4u::Actor::create("dispatcher", engine.host_by_name("host1"), main_dispatcher, testlink);
   engine.run();
index 8268a37..940248f 100644 (file)
@@ -75,8 +75,7 @@ int main(int argc, char* argv[])
                                 ->set_bandwidth_profile(linkSaBandwidthProfile)
                                 ->seal();
 
-  world->add_route(hostGl01->get_netpoint(), hostSa01->get_netpoint(), nullptr, nullptr,
-                   {{linkSa, sg4::LinkInRoute::Direction::NONE}}, true);
+  world->add_route(hostGl01, hostSa01, {{linkSa, sg4::LinkInRoute::Direction::NONE}}, true);
   world->seal();
 
   sg4::Mailbox* mb1 = e.mailbox_by_name_or_create("Mailbox 1");
index 4a13429..4cea0bb 100644 (file)
@@ -47,8 +47,8 @@ int main(int argc, char* argv[])
   auto* rootzone = sg4::create_full_zone("root");
   auto* hostA    = rootzone->create_host("hostA", 1e9);
   auto* hostB    = rootzone->create_host("hostB", 1e9);
-  sg4::LinkInRoute link(rootzone->create_link("backbone", "1")->set_latency("1s")->seal());
-  rootzone->add_route(hostA->get_netpoint(), hostB->get_netpoint(), nullptr, nullptr, {link}, true);
+  auto* backb    = rootzone->create_link("backbone", "1")->set_latency("1s")->seal();
+  rootzone->add_route(hostA, hostB, {backb});
   rootzone->seal();
 
   sg4::Actor::create("ptask", hostA, ptask, hostA, hostB);
index a28a532..5bab3cb 100644 (file)
@@ -63,8 +63,8 @@ def load_platform():
     hosts.append(host2)
     link1 = dijkstra.create_link("link1_up", [1e9]).set_latency(1e-3).set_concurrency_limit(10).seal()
     link2 = dijkstra.create_link("link1_down", ["1GBps"]).set_latency("1ms").seal()
-    dijkstra.add_route(host1.netpoint, host2.netpoint, None, None, [LinkInRoute(link1)], False)
-    dijkstra.add_route(host2.netpoint, host1.netpoint, None, None, [LinkInRoute(link2)], False)
+    dijkstra.add_route(host1, host2, [LinkInRoute(link1)], False)
+    dijkstra.add_route(host2, host1, [LinkInRoute(link2)], False)
     dijkstra.seal()
 
     # vivaldi
index 1723741..b996076 100644 (file)
@@ -409,8 +409,7 @@ int main(int argc, char* argv[])
   pr::Profile* profile_link = pr::ProfileBuilder::from_string("link_profile", ctx.link_profile.str(), 0);
   sg4::Link const* link =
       zone->create_link("link", LinkBandwidth)->set_latency(LinkLatency)->set_state_profile(profile_link)->seal();
-  zone->add_route(sender_host->get_netpoint(), receiver_host->get_netpoint(), nullptr, nullptr,
-                  {sg4::LinkInRoute{link}}, false);
+  zone->add_route(sender_host, receiver_host, {link});
   zone->seal();
 
   sg4::Host::on_onoff_cb([mbox](sg4::Host const& host) {
index 72bbbec..4a4fca3 100644 (file)
@@ -114,8 +114,8 @@ int main(int argc, char* argv[])
   for (int i = 1; i < cfg_host_count; i++) {
     auto hostname = "lilibeth " + std::to_string(i);
     auto* host    = rootzone->create_host(hostname, 1e9);
-    sg4::LinkInRoute link(rootzone->create_link(hostname, "1MBps")->set_latency("24us")->seal());
-    rootzone->add_route(master_host->get_netpoint(), host->get_netpoint(), nullptr, nullptr, {link}, true);
+    auto* link    = rootzone->create_link(hostname, "1MBps")->set_latency("24us")->seal();
+    rootzone->add_route(master_host, host, {link});
     worker_hosts.push_back(host);
   }
   rootzone->seal();
index 26944b7..863b392 100644 (file)
@@ -92,7 +92,7 @@ if __name__ == '__main__':
   for i in range(1, host_count):
     link = rootzone.create_split_duplex_link(f"link {i}", "1MBps").set_latency("24us")
     host = rootzone.create_host(f"lilibeth {i}", 1e9)
-    rootzone.add_route(main.netpoint, host.netpoint, None, None, [LinkInRoute(link, LinkInRoute.Direction.UP)], True)
+    rootzone.add_route(main, host, [link])
     Actor.create("worker", host, worker, i).set_auto_restart(True)
 
   e.netzone_root.seal()
index 828303a..6e73575 100644 (file)
@@ -116,8 +116,8 @@ int main(int argc, char** argv)
   auto* rootzone = sg4::create_full_zone("root");
   auto* paul     = rootzone->create_host("Paul", 1e9);
   auto* carol    = rootzone->create_host("Carol", 1e9);
-  sg4::LinkInRoute link(rootzone->create_link("link", "1MBps")->set_latency("24us")->seal());
-  rootzone->add_route(paul->get_netpoint(), carol->get_netpoint(), nullptr, nullptr, {link}, true);
+  auto* link     = rootzone->create_link("link", "1MBps")->set_latency("24us")->seal();
+  rootzone->add_route(paul, carol, {link});
 
   SharedBuffer buffer;
   sg4::Actor::create("producer", paul, producer, std::ref(buffer))->set_auto_restart();
index a3315e6..6d49d7d 100644 (file)
@@ -68,7 +68,7 @@ static sg4::NetZone* create_zone(const sg4::NetZone* root, const std::string& id
     auto* host           = zone->create_host(hostname, 1e9);
     host->create_disk("disk-" + hostname, 1e9, 1e6);
     const auto* link = zone->create_link("link-" + hostname, 1e9);
-    zone->add_route(host->get_netpoint(), router, nullptr, nullptr, {sg4::LinkInRoute(link)});
+    zone->add_route(host->get_netpoint(), router, nullptr, nullptr, {link});
   }
   return zone;
 }