X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/b1444ba3a67f5b0c1c514533d499eb5ad32d7edd..cf74b06c924b9d0f18728553e832fec6aecc5ca7:/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 bffce7f7d3..4a9efdb4e3 100644 --- a/examples/s4u/app-token-ring/s4u_app-token-ring.cpp +++ b/examples/s4u/app-token-ring/s4u_app-token-ring.cpp @@ -5,13 +5,14 @@ #include "xbt/str.h" #include +#include #include -#include +#include #include 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::unordered_map host_list; +extern std::map host_list; class RelayRunner { public: @@ -25,13 +26,13 @@ public: { 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()); + my_mailbox = simgrid::s4u::Mailbox::byName(std::to_string(rank)); if (rank + 1 == host_list.size()) /* 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 */ @@ -39,6 +40,7 @@ public: simgrid::s4u::this_actor::send(neighbor_mailbox, xbt_strdup("Token"), task_comm_size); char* res = static_cast(simgrid::s4u::this_actor::recv(my_mailbox)); XBT_INFO("Host \"%u\" received \"%s\"", rank, res); + xbt_free(res); } else { char* res = static_cast(simgrid::s4u::this_actor::recv(my_mailbox)); XBT_INFO("Host \"%u\" received \"%s\"", rank, res); @@ -54,8 +56,7 @@ 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 '%lu'", host_list.size()); - + XBT_INFO("Number of hosts '%zu'", host_list.size()); int id = 0; for (auto h : host_list) { simgrid::s4u::Host* host = h.second;