X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/815ad0c49675dd68020f3562a2aca3531d81bc80..39c935d6d5ee86d153f6f7e6a10d723ae7c57f6f:/examples/s4u/app-token-ring/s4u-app-token-ring.cpp diff --git a/examples/s4u/app-token-ring/s4u-app-token-ring.cpp b/examples/s4u/app-token-ring/s4u-app-token-ring.cpp index 388e19f6fe..601f0623d3 100644 --- a/examples/s4u/app-token-ring/s4u-app-token-ring.cpp +++ b/examples/s4u/app-token-ring/s4u-app-token-ring.cpp @@ -1,4 +1,4 @@ -/* Copyright (c) 2017. The SimGrid Team. All rights reserved. */ +/* 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. */ @@ -12,42 +12,41 @@ XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_app_token_ring, "Messages specific for this s4u example"); class RelayRunner { - size_t task_comm_size = 1000000; /* The token is 1MB long*/ - simgrid::s4u::MailboxPtr my_mailbox; - simgrid::s4u::MailboxPtr neighbor_mailbox; - unsigned int rank = 0; - public: explicit RelayRunner() = default; - void operator()() + void operator()() const { + size_t token_size = 1000000; /* The token is 1MB long*/ + simgrid::s4u::Mailbox* my_mailbox; + simgrid::s4u::Mailbox* neighbor_mailbox; + unsigned int rank = 0; + try { - rank = std::stoi(simgrid::s4u::this_actor::getName()); - } catch (std::invalid_argument& ia) { - throw std::invalid_argument(std::string("Processes of this example must have a numerical name, not ") + - ia.what()); + rank = std::stoi(simgrid::s4u::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::byName(std::to_string(rank)); - if (rank + 1 == simgrid::s4u::Engine::getInstance()->getHostCount()) - /* The last process, which sends the token back to rank 0 */ - neighbor_mailbox = simgrid::s4u::Mailbox::byName("0"); + my_mailbox = simgrid::s4u::Mailbox::by_name(std::to_string(rank)); + if (rank + 1 == simgrid::s4u::Engine::get_instance()->get_host_count()) + /* The last actor sends the token back to rank 0 */ + neighbor_mailbox = simgrid::s4u::Mailbox::by_name("0"); else - /* The others processes send to their right neighbor (rank+1) */ - neighbor_mailbox = simgrid::s4u::Mailbox::byName(std::to_string(rank + 1)); + /* The others actors send to their right neighbor (rank+1) */ + neighbor_mailbox = simgrid::s4u::Mailbox::by_name(std::to_string(rank + 1)); if (rank == 0) { - /* The root process (rank 0) first sends the token then waits to receive it back */ - XBT_INFO("Host \"%u\" send 'Token' to Host \"%s\"", rank, neighbor_mailbox->getCname()); + /* The root actor (rank 0) first sends the token then waits to receive it back */ + XBT_INFO("Host \"%u\" send 'Token' to Host \"%s\"", rank, neighbor_mailbox->get_cname()); std::string msg = "Token"; - neighbor_mailbox->put(&msg, task_comm_size); - std::string* res = static_cast(my_mailbox->get()); + neighbor_mailbox->put(&msg, token_size); + const auto* res = my_mailbox->get(); XBT_INFO("Host \"%u\" received \"%s\"", rank, res->c_str()); } else { - std::string* res = static_cast(my_mailbox->get()); + auto* res = my_mailbox->get(); XBT_INFO("Host \"%u\" received \"%s\"", rank, res->c_str()); - XBT_INFO("Host \"%u\" send 'Token' to Host \"%s\"", rank, neighbor_mailbox->getCname()); - neighbor_mailbox->put(res, task_comm_size); + XBT_INFO("Host \"%u\" send 'Token' to Host \"%s\"", rank, neighbor_mailbox->get_cname()); + neighbor_mailbox->put(res, token_size); } } }; @@ -56,19 +55,18 @@ int main(int argc, char** argv) { simgrid::s4u::Engine e(&argc, argv); xbt_assert(argc > 1, "Usage: %s platform.xml\n", argv[0]); - e.loadPlatform(argv[1]); + e.load_platform(argv[1]); - XBT_INFO("Number of hosts '%zu'", e.getHostCount()); + XBT_INFO("Number of hosts '%zu'", e.get_host_count()); int id = 0; - std::vector list; - e.getHostList(&list); + 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 process on each */ - simgrid::s4u::Actor::createActor((std::to_string(id)).c_str(), host, RelayRunner()); + /* - 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()); id++; } e.run(); - XBT_INFO("Simulation time %g", e.getClock()); + XBT_INFO("Simulation time %g", e.get_clock()); return 0; }