--- /dev/null
+/* 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 "xbt/str.h"
+#include <simgrid/s4u.hpp>
+#include <string>
+#include <unordered_map>
+#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::unordered_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;
+ 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())
+ /* 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());
+
+ 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->name());
+ simgrid::s4u::this_actor::send(neighbor_mailbox, xbt_strdup("Token"), task_comm_size);
+ char* res = static_cast<char*>(simgrid::s4u::this_actor::recv(my_mailbox));
+ XBT_INFO("Host \"%u\" received \"%s\"", rank, res);
+ } else {
+ char* res = static_cast<char*>(simgrid::s4u::this_actor::recv(my_mailbox));
+ XBT_INFO("Host \"%u\" received \"%s\"", rank, res);
+ XBT_INFO("Host \"%u\" send 'Token' to Host \"%s\"", rank, neighbor_mailbox->name());
+ simgrid::s4u::this_actor::send(neighbor_mailbox, res, task_comm_size);
+ }
+ }
+};
+
+int main(int argc, char** argv)
+{
+ simgrid::s4u::Engine* e = new simgrid::s4u::Engine(&argc, 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());
+
+ int id = 0;
+ for (auto h : host_list) {
+ simgrid::s4u::Host* host = h.second;
+ /* - 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());
+ return 0;
+}
--- /dev/null
+#! ./tesh
+
+$ $SG_TEST_EXENV ${bindir:=.}/s4u_app-token-ring ${srcdir:=.}/routing_cluster.xml "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n"
+> [ 0.000000] (0:maestro@) Number of hosts '6'
+> [ 0.000000] (0:0@host5) Host "0" send 'Token' to Host "1"
+> [ 0.030364] (0:1@host1) Host "1" received "Token"
+> [ 0.030364] (0:1@host1) Host "1" send 'Token' to Host "2"
+> [ 0.048131] (0:2@host3) Host "2" received "Token"
+> [ 0.048131] (0:2@host3) Host "2" send 'Token' to Host "3"
+> [ 0.065898] (0:3@host2) Host "3" received "Token"
+> [ 0.065898] (0:3@host2) Host "3" send 'Token' to Host "4"
+> [ 0.096675] (0:4@host6) Host "4" received "Token"
+> [ 0.096675] (0:4@host6) Host "4" send 'Token' to Host "5"
+> [ 0.114442] (0:5@host4) Host "5" received "Token"
+> [ 0.114442] (0:5@host4) Host "5" send 'Token' to Host "0"
+> [ 0.131796] (0:0@host5) Host "0" received "Token"
+> [ 0.131796] (0:maestro@) Simulation time 0.131796
+
+$ $SG_TEST_EXENV ${bindir:=.}/s4u_app-token-ring ${srcdir:=.}/two_peers.xml "--log=root.fmt:[%12.6r]%e(%i:%P@%h)%e%m%n"
+> [ 0.000000] (0:maestro@) Number of hosts '2'
+> [ 0.000000] (0:0@100036570) Host "0" send 'Token' to Host "1"
+> [ 0.624423] (0:1@100030591) Host "1" received "Token"
+> [ 0.624423] (0:1@100030591) Host "1" send 'Token' to Host "0"
+> [ 1.248846] (0:0@100036570) Host "0" received "Token"
+> [ 1.248846] (0:maestro@) Simulation time 1.24885
+
+$ $SG_TEST_EXENV ${bindir:=.}/s4u_app-token-ring ${srcdir:=.}/meta_cluster.xml "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n"
+> [ 0.000000] (0:maestro@) Number of hosts '60'
+> [ 0.000000] (0:0@host-28.cluster2) Host "0" send 'Token' to Host "1"
+> [ 0.017354] (0:1@host-27.cluster2) Host "1" received "Token"
+> [ 0.017354] (0:1@host-27.cluster2) Host "1" send 'Token' to Host "2"
+> [ 0.034709] (0:2@host-29.cluster2) Host "2" received "Token"
+> [ 0.034709] (0:2@host-29.cluster2) Host "2" send 'Token' to Host "3"
+> [ 0.052063] (0:3@host-26.cluster2) Host "3" received "Token"
+> [ 0.052063] (0:3@host-26.cluster2) Host "3" send 'Token' to Host "4"
+> [ 0.069418] (0:4@host-25.cluster2) Host "4" received "Token"
+> [ 0.069418] (0:4@host-25.cluster2) Host "4" send 'Token' to Host "5"
+> [ 0.086772] (0:5@host-24.cluster2) Host "5" received "Token"
+> [ 0.086772] (0:5@host-24.cluster2) Host "5" send 'Token' to Host "6"
+> [ 0.104127] (0:6@host-23.cluster2) Host "6" received "Token"
+> [ 0.104127] (0:6@host-23.cluster2) Host "6" send 'Token' to Host "7"
+> [ 0.121481] (0:7@host-22.cluster2) Host "7" received "Token"
+> [ 0.121481] (0:7@host-22.cluster2) Host "7" send 'Token' to Host "8"
+> [ 0.138835] (0:8@host-20.cluster2) Host "8" received "Token"
+> [ 0.138835] (0:8@host-20.cluster2) Host "8" send 'Token' to Host "9"
+> [ 0.156190] (0:9@host-18.cluster2) Host "9" received "Token"
+> [ 0.156190] (0:9@host-18.cluster2) Host "9" send 'Token' to Host "10"
+> [ 0.173544] (0:10@host-17.cluster2) Host "10" received "Token"
+> [ 0.173544] (0:10@host-17.cluster2) Host "10" send 'Token' to Host "11"
+> [ 0.203909] (0:11@host-23.cluster1) Host "11" received "Token"
+> [ 0.203909] (0:11@host-23.cluster1) Host "11" send 'Token' to Host "12"
+> [ 0.221263] (0:12@host-20.cluster1) Host "12" received "Token"
+> [ 0.221263] (0:12@host-20.cluster1) Host "12" send 'Token' to Host "13"
+> [ 0.238617] (0:13@host-8.cluster1) Host "13" received "Token"
+> [ 0.238617] (0:13@host-8.cluster1) Host "13" send 'Token' to Host "14"
+> [ 0.255972] (0:14@host-19.cluster1) Host "14" received "Token"
+> [ 0.255972] (0:14@host-19.cluster1) Host "14" send 'Token' to Host "15"
+> [ 0.286336] (0:15@host-30.cluster2) Host "15" received "Token"
+> [ 0.286336] (0:15@host-30.cluster2) Host "15" send 'Token' to Host "16"
+> [ 0.316701] (0:16@host-21.cluster1) Host "16" received "Token"
+> [ 0.316701] (0:16@host-21.cluster1) Host "16" send 'Token' to Host "17"
+> [ 0.334055] (0:17@host-14.cluster1) Host "17" received "Token"
+> [ 0.334055] (0:17@host-14.cluster1) Host "17" send 'Token' to Host "18"
+> [ 0.364420] (0:18@host-3.cluster2) Host "18" received "Token"
+> [ 0.364420] (0:18@host-3.cluster2) Host "18" send 'Token' to Host "19"
+> [ 0.394784] (0:19@host-3.cluster1) Host "19" received "Token"
+> [ 0.394784] (0:19@host-3.cluster1) Host "19" send 'Token' to Host "20"
+> [ 0.412138] (0:20@host-5.cluster1) Host "20" received "Token"
+> [ 0.412138] (0:20@host-5.cluster1) Host "20" send 'Token' to Host "21"
+> [ 0.429493] (0:21@host-2.cluster1) Host "21" received "Token"
+> [ 0.429493] (0:21@host-2.cluster1) Host "21" send 'Token' to Host "22"
+> [ 0.446847] (0:22@host-22.cluster1) Host "22" received "Token"
+> [ 0.446847] (0:22@host-22.cluster1) Host "22" send 'Token' to Host "23"
+> [ 0.464202] (0:23@host-18.cluster1) Host "23" received "Token"
+> [ 0.464202] (0:23@host-18.cluster1) Host "23" send 'Token' to Host "24"
+> [ 0.481556] (0:24@host-16.cluster1) Host "24" received "Token"
+> [ 0.481556] (0:24@host-16.cluster1) Host "24" send 'Token' to Host "25"
+> [ 0.498911] (0:25@host-29.cluster1) Host "25" received "Token"
+> [ 0.498911] (0:25@host-29.cluster1) Host "25" send 'Token' to Host "26"
+> [ 0.529275] (0:26@host-15.cluster2) Host "26" received "Token"
+> [ 0.529275] (0:26@host-15.cluster2) Host "26" send 'Token' to Host "27"
+> [ 0.559639] (0:27@host-4.cluster1) Host "27" received "Token"
+> [ 0.559639] (0:27@host-4.cluster1) Host "27" send 'Token' to Host "28"
+> [ 0.576994] (0:28@host-12.cluster1) Host "28" received "Token"
+> [ 0.576994] (0:28@host-12.cluster1) Host "28" send 'Token' to Host "29"
+> [ 0.594348] (0:29@host-1.cluster1) Host "29" received "Token"
+> [ 0.594348] (0:29@host-1.cluster1) Host "29" send 'Token' to Host "30"
+> [ 0.624713] (0:30@host-5.cluster2) Host "30" received "Token"
+> [ 0.624713] (0:30@host-5.cluster2) Host "30" send 'Token' to Host "31"
+> [ 0.655077] (0:31@host-7.cluster1) Host "31" received "Token"
+> [ 0.655077] (0:31@host-7.cluster1) Host "31" send 'Token' to Host "32"
+> [ 0.672432] (0:32@host-15.cluster1) Host "32" received "Token"
+> [ 0.672432] (0:32@host-15.cluster1) Host "32" send 'Token' to Host "33"
+> [ 0.689786] (0:33@host-24.cluster1) Host "33" received "Token"
+> [ 0.689786] (0:33@host-24.cluster1) Host "33" send 'Token' to Host "34"
+> [ 0.707140] (0:34@host-6.cluster1) Host "34" received "Token"
+> [ 0.707140] (0:34@host-6.cluster1) Host "34" send 'Token' to Host "35"
+> [ 0.724495] (0:35@host-10.cluster1) Host "35" received "Token"
+> [ 0.724495] (0:35@host-10.cluster1) Host "35" send 'Token' to Host "36"
+> [ 0.741849] (0:36@host-17.cluster1) Host "36" received "Token"
+> [ 0.741849] (0:36@host-17.cluster1) Host "36" send 'Token' to Host "37"
+> [ 0.772214] (0:37@host-14.cluster2) Host "37" received "Token"
+> [ 0.772214] (0:37@host-14.cluster2) Host "37" send 'Token' to Host "38"
+> [ 0.789568] (0:38@host-19.cluster2) Host "38" received "Token"
+> [ 0.789568] (0:38@host-19.cluster2) Host "38" send 'Token' to Host "39"
+> [ 0.819932] (0:39@host-25.cluster1) Host "39" received "Token"
+> [ 0.819932] (0:39@host-25.cluster1) Host "39" send 'Token' to Host "40"
+> [ 0.837287] (0:40@host-9.cluster1) Host "40" received "Token"
+> [ 0.837287] (0:40@host-9.cluster1) Host "40" send 'Token' to Host "41"
+> [ 0.854641] (0:41@host-27.cluster1) Host "41" received "Token"
+> [ 0.854641] (0:41@host-27.cluster1) Host "41" send 'Token' to Host "42"
+> [ 0.885006] (0:42@host-2.cluster2) Host "42" received "Token"
+> [ 0.885006] (0:42@host-2.cluster2) Host "42" send 'Token' to Host "43"
+> [ 0.915370] (0:43@host-26.cluster1) Host "43" received "Token"
+> [ 0.915370] (0:43@host-26.cluster1) Host "43" send 'Token' to Host "44"
+> [ 0.945735] (0:44@host-9.cluster2) Host "44" received "Token"
+> [ 0.945735] (0:44@host-9.cluster2) Host "44" send 'Token' to Host "45"
+> [ 0.976099] (0:45@host-28.cluster1) Host "45" received "Token"
+> [ 0.976099] (0:45@host-28.cluster1) Host "45" send 'Token' to Host "46"
+> [ 0.993453] (0:46@host-30.cluster1) Host "46" received "Token"
+> [ 0.993453] (0:46@host-30.cluster1) Host "46" send 'Token' to Host "47"
+> [ 1.010808] (0:47@host-13.cluster1) Host "47" received "Token"
+> [ 1.010808] (0:47@host-13.cluster1) Host "47" send 'Token' to Host "48"
+> [ 1.041172] (0:48@host-1.cluster2) Host "48" received "Token"
+> [ 1.041172] (0:48@host-1.cluster2) Host "48" send 'Token' to Host "49"
+> [ 1.058527] (0:49@host-10.cluster2) Host "49" received "Token"
+> [ 1.058527] (0:49@host-10.cluster2) Host "49" send 'Token' to Host "50"
+> [ 1.075881] (0:50@host-4.cluster2) Host "50" received "Token"
+> [ 1.075881] (0:50@host-4.cluster2) Host "50" send 'Token' to Host "51"
+> [ 1.106246] (0:51@host-11.cluster1) Host "51" received "Token"
+> [ 1.106246] (0:51@host-11.cluster1) Host "51" send 'Token' to Host "52"
+> [ 1.136610] (0:52@host-7.cluster2) Host "52" received "Token"
+> [ 1.136610] (0:52@host-7.cluster2) Host "52" send 'Token' to Host "53"
+> [ 1.153964] (0:53@host-8.cluster2) Host "53" received "Token"
+> [ 1.153964] (0:53@host-8.cluster2) Host "53" send 'Token' to Host "54"
+> [ 1.171319] (0:54@host-21.cluster2) Host "54" received "Token"
+> [ 1.171319] (0:54@host-21.cluster2) Host "54" send 'Token' to Host "55"
+> [ 1.188673] (0:55@host-6.cluster2) Host "55" received "Token"
+> [ 1.188673] (0:55@host-6.cluster2) Host "55" send 'Token' to Host "56"
+> [ 1.206028] (0:56@host-13.cluster2) Host "56" received "Token"
+> [ 1.206028] (0:56@host-13.cluster2) Host "56" send 'Token' to Host "57"
+> [ 1.223382] (0:57@host-11.cluster2) Host "57" received "Token"
+> [ 1.223382] (0:57@host-11.cluster2) Host "57" send 'Token' to Host "58"
+> [ 1.240737] (0:58@host-12.cluster2) Host "58" received "Token"
+> [ 1.240737] (0:58@host-12.cluster2) Host "58" send 'Token' to Host "59"
+> [ 1.258091] (0:59@host-16.cluster2) Host "59" received "Token"
+> [ 1.258091] (0:59@host-16.cluster2) Host "59" send 'Token' to Host "0"
+> [ 1.275445] (0:0@host-28.cluster2) Host "0" received "Token"
+> [ 1.275445] (0:maestro@) Simulation time 1.27545