X-Git-Url: http://bilbo.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/bdfa117ce4f85c77d50219cb2e115d88d3f35f8e..8af3607f20f101aafe0eee4ca05f4335b02802d0:/examples/cpp/app-token-ring/s4u-app-token-ring.cpp diff --git a/examples/cpp/app-token-ring/s4u-app-token-ring.cpp b/examples/cpp/app-token-ring/s4u-app-token-ring.cpp index 6766af49c8..7a36d1d1cd 100644 --- a/examples/cpp/app-token-ring/s4u-app-token-ring.cpp +++ b/examples/cpp/app-token-ring/s4u-app-token-ring.cpp @@ -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. */ @@ -10,6 +10,7 @@ #include XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_app_token_ring, "Messages specific for this s4u example"); +namespace sg4 = simgrid::s4u; class RelayRunner { public: @@ -18,22 +19,22 @@ public: void operator()() const { size_t token_size = 1000000; /* The token is 1MB long*/ - simgrid::s4u::Mailbox* my_mailbox; - simgrid::s4u::Mailbox* neighbor_mailbox; + sg4::Mailbox* my_mailbox; + sg4::Mailbox* neighbor_mailbox; unsigned int rank = 0; try { - rank = std::stoi(simgrid::s4u::this_actor::get_name()); + rank = std::stoi(sg4::this_actor::get_name()); } catch (const std::invalid_argument& ia) { throw std::invalid_argument(std::string("Actors of this example must have a numerical name, not ") + ia.what()); } - my_mailbox = simgrid::s4u::Mailbox::by_name(std::to_string(rank)); - if (rank + 1 == simgrid::s4u::Engine::get_instance()->get_host_count()) + my_mailbox = sg4::Mailbox::by_name(std::to_string(rank)); + if (rank + 1 == sg4::Engine::get_instance()->get_host_count()) /* The last actor sends the token back to rank 0 */ - neighbor_mailbox = simgrid::s4u::Mailbox::by_name("0"); + neighbor_mailbox = sg4::Mailbox::by_name("0"); else /* The others actors send to their right neighbor (rank+1) */ - neighbor_mailbox = simgrid::s4u::Mailbox::by_name(std::to_string(rank + 1)); + neighbor_mailbox = sg4::Mailbox::by_name(std::to_string(rank + 1)); if (rank == 0) { /* The root actor (rank 0) first sends the token then waits to receive it back */ @@ -53,20 +54,20 @@ public: int main(int argc, char** argv) { - simgrid::s4u::Engine e(&argc, argv); + sg4::Engine e(&argc, argv); xbt_assert(argc > 1, "Usage: %s platform.xml\n", argv[0]); e.load_platform(argv[1]); XBT_INFO("Number of hosts '%zu'", e.get_host_count()); int id = 0; - std::vector list = e.get_all_hosts(); + std::vector list = e.get_all_hosts(); for (auto const& host : list) { /* - Give a unique rank to each host and create a @ref relay_runner actor on each */ - simgrid::s4u::Actor::create((std::to_string(id)).c_str(), host, RelayRunner()); + sg4::Actor::create((std::to_string(id)).c_str(), host, RelayRunner()); id++; } e.run(); - XBT_INFO("Simulation time %g", simgrid::s4u::Engine::get_clock()); + XBT_INFO("Simulation time %g", sg4::Engine::get_clock()); return 0; }