1 /* Copyright (c) 2007-2022. The SimGrid Team. All rights reserved. */
3 /* This program is free software; you can redistribute it and/or modify it
4 * under the terms of the license (GNU LGPL) which comes with this package. */
6 #include "simgrid/s4u.hpp"
8 #include <unordered_map>
10 XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_test, "Messages specific for this s4u example");
13 std::unordered_map<int, std::string> workernames;
14 std::unordered_map<int, std::string> masternames;
16 static void master(std::vector<std::string> args)
18 xbt_assert(args.size() == 4, "Strange number of arguments expected 3 got %zu", args.size() - 1);
20 XBT_DEBUG("Master started");
23 double msg_size = std::stod(args[1]);
24 int id = std::stoi(args[3]); // unique id to control statistics
27 workernames[id] = args[2];
29 simgrid::s4u::Mailbox* mbox = simgrid::s4u::Mailbox::by_name(args[3]);
31 masternames[id] = simgrid::s4u::Host::current()->get_name();
33 auto* payload = new double(msg_size);
35 /* time measurement */
36 start_time = simgrid::s4u::Engine::get_clock();
37 mbox->put(payload, static_cast<uint64_t>(msg_size));
39 XBT_DEBUG("Finished");
42 static void worker(std::vector<std::string> args)
44 xbt_assert(args.size() == 2, "Strange number of arguments expected 1 got %zu", args.size() - 1);
46 int id = std::stoi(args[1]);
47 simgrid::s4u::Mailbox* mbox = simgrid::s4u::Mailbox::by_name(args[1]);
49 XBT_DEBUG("Worker started");
51 auto payload = mbox->get_unique<double>();
53 double elapsed_time = simgrid::s4u::Engine::get_clock() - start_time;
55 XBT_INFO("FLOW[%d] : Receive %.0f bytes from %s to %s", id, *payload, masternames.at(id).c_str(),
56 workernames.at(id).c_str());
57 XBT_DEBUG("FLOW[%d] : transferred in %f seconds", id, elapsed_time);
59 XBT_DEBUG("Finished");
62 int main(int argc, char* argv[])
64 simgrid::s4u::Engine e(&argc, argv);
66 "Usage: %s platform_file deployment_file\n"
67 "\tExample: %s platform.xml deployment.xml\n",
70 e.load_platform(argv[1]);
72 e.register_function("master", master);
73 e.register_function("worker", worker);
75 e.load_deployment(argv[2]);