Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
make it clear to static analyzers that this mem is not leaked
[simgrid.git] / examples / s4u / app-token-ring / s4u_app-token-ring.cpp
index 3b6b1b7..c2d375b 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2017. The SimGrid Team. All rights reserved.          */
+/* Copyright (c) 2017. 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 <vector>
 
 XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_app_token_ring, "Messages specific for this s4u example");
-// FIXME: The following duplicates the content of s4u::Host
-extern std::map<std::string, simgrid::s4u::Host*> host_list;
 
 class RelayRunner {
-public:
   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()()
   {
     rank = xbt_str_parse_int(simgrid::s4u::this_actor::name().c_str(),
                              "Any process of this example must have a numerical name, not %s");
-    my_mailbox = simgrid::s4u::Mailbox::byName((std::to_string(rank)).c_str());
-    if (rank + 1 == host_list.size())
+    my_mailbox = simgrid::s4u::Mailbox::byName(std::to_string(rank));
+    if (rank + 1 == simgrid::s4u::Engine::instance()->hostCount())
       /* The last process, which sends the token back to rank 0 */
       neighbor_mailbox = simgrid::s4u::Mailbox::byName("0");
     else
       /* The others processes send to their right neighbor (rank+1) */
-      neighbor_mailbox = simgrid::s4u::Mailbox::byName((std::to_string(rank + 1)).c_str());
+      neighbor_mailbox = simgrid::s4u::Mailbox::byName(std::to_string(rank + 1));
 
     if (rank == 0) {
       /* The root process (rank 0) first sends the token then waits to receive it back */
@@ -56,15 +55,18 @@ int main(int argc, char** argv)
   xbt_assert(argc > 1, "Usage: %s platform.xml\n", argv[0]);
   e->loadPlatform(argv[1]);
 
-  XBT_INFO("Number of hosts '%zu'", host_list.size());
+  XBT_INFO("Number of hosts '%zu'", e->hostCount());
   int id = 0;
-  for (auto h : host_list) {
-    simgrid::s4u::Host* host = h.second;
+  std::vector<simgrid::s4u::Host*> list;
+  e->hostList(&list);
+  for (auto 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());
     id++;
   }
   e->run();
   XBT_INFO("Simulation time %g", e->getClock());
+
+  delete e;
   return 0;
 }