Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add a add_route with s4u::Link instead of LinkInRoute
[simgrid.git] / teshsuite / models / cm02-set-lat-bw / cm02-set-lat-bw.cpp
index f0d7e29ca5da7c1c7fe26404eb8e1503a24f454d..1751a7d6e523d4fd7c4412053f8f3a7b11bcdf62 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2017-2021. The SimGrid Team. All rights reserved.          */
+/* Copyright (c) 2017-2023. 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. */
@@ -37,7 +37,7 @@ XBT_LOG_NEW_DEFAULT_CATEGORY(cm02_set_lat_bw, "Messages specific for this simula
 static void sender(const std::string& recv_name, sg4::Link* l4)
 {
   sg4::Mailbox* mbox = sg4::Mailbox::by_name(recv_name);
-  XBT_INFO("Comm to %s, same weight/penalty (w_a == w_b, ~20) for everybody, each comm should take 1s and finish at "
+  XBT_INFO("Send to %s, same weight/penalty (w_a == w_b, ~20) for everybody, each comm should take 1s and finish at "
            "the same time",
            recv_name.c_str());
   auto* payload = new double(sg4::Engine::get_clock());
@@ -46,10 +46,10 @@ static void sender(const std::string& recv_name, sg4::Link* l4)
   sg4::this_actor::sleep_until(10); // synchronize senders
 
   if (recv_name == "C2") {
-    XBT_INFO("Comm Flow B to C2: after 1s, change latency of L4 to increase penalty for flow B (w_b = 2* w_a)");
+    XBT_INFO("Send Flow B to C2: after 1s, change latency of L4 to increase penalty for flow B (w_b = 2* w_a)");
     XBT_INFO("rho_a = 2*rho_b, flow A receives twice the bandwidth than flow B");
   } else {
-    XBT_INFO("Comm Flow A to C1");
+    XBT_INFO("Send Flow A to C1");
   }
   payload = new double(sg4::Engine::get_clock());
   comm    = mbox->put_async(payload, 1e3);
@@ -62,10 +62,10 @@ static void sender(const std::string& recv_name, sg4::Link* l4)
     l4->set_latency(1e-9);
 
   if (recv_name == "C2") {
-    XBT_INFO("Comm Flow B to C2: after 1s, change bandwidth of L4 to increase penalty for flow B (w_b = 2* w_a)");
+    XBT_INFO("Send Flow B to C2: after 1s, change bandwidth of L4 to increase penalty for flow B (w_b = 2* w_a)");
     XBT_INFO("rho_a = 2*rho_b, flow A receives twice the bandwidth than flow B");
   } else {
-    XBT_INFO("Comm Flow A to C1");
+    XBT_INFO("Send Flow A to C1");
   }
   payload = new double(sg4::Engine::get_clock());
   comm    = mbox->put_async(payload, 1e3);
@@ -82,15 +82,11 @@ static void sender(const std::string& recv_name, sg4::Link* l4)
 static void receiver()
 {
   sg4::Mailbox* mbox = sg4::Mailbox::by_name(sg4::this_actor::get_host()->get_name());
-  double* payload    = nullptr;
   while (true) {
-    payload = mbox->get<double>();
-    if (*payload < 0) {
-      delete payload;
+    auto payload = mbox->get_unique<double>();
+    if (*payload < 0)
       break;
-    }
     XBT_INFO("Received data. Elapsed %lf", sg4::Engine::get_clock() - *payload);
-    delete payload;
   }
   XBT_INFO("Bye");
 }
@@ -100,9 +96,9 @@ int main(int argc, char** argv)
 {
   sg4::Engine e(&argc, argv);
   /* keep it simple, no network factors nor crosstrafic */
-  simgrid::s4u::Engine::set_config("network/model:CM02");
-  simgrid::s4u::Engine::set_config("network/weight-S:20537");
-  simgrid::s4u::Engine::set_config("network/crosstraffic:0");
+  sg4::Engine::set_config("network/model:CM02");
+  sg4::Engine::set_config("network/weight-S:20537");
+  sg4::Engine::set_config("network/crosstraffic:0");
 
   /* dog-bone platform */
   std::unordered_map<std::string, sg4::Host*> hosts;
@@ -116,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);