1 /* Copyright (c) 2007-2018. 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 XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_app_pingpong, "Messages specific for this s4u example");
10 static void pinger(std::vector<std::string> args)
12 xbt_assert(args.size() == 1, "The pinger function one argument from the XML deployment file");
13 XBT_INFO("Ping -> %s", args[0].c_str());
14 xbt_assert(simgrid::s4u::Host::by_name_or_null(args[0]) != nullptr, "Unknown host %s. Stopping Now! ",
17 /* - Do the ping with a 1-Byte task (latency bound) ... */
18 double* payload = new double();
19 *payload = simgrid::s4u::Engine::getClock();
21 simgrid::s4u::Mailbox::byName(args[0])->put(payload, 1);
22 /* - ... then wait for the (large) pong */
24 static_cast<double*>(simgrid::s4u::Mailbox::byName(simgrid::s4u::this_actor::get_host()->get_name())->get());
26 double communication_time = simgrid::s4u::Engine::getClock() - *sender_time;
27 XBT_INFO("Task received : large communication (bandwidth bound)");
28 XBT_INFO("Pong time (bandwidth bound): %.3f", communication_time);
32 static void ponger(std::vector<std::string> args)
34 xbt_assert(args.size() == 1, "The ponger function one argument from the XML deployment file");
35 XBT_INFO("Pong -> %s", args[0].c_str());
36 xbt_assert(simgrid::s4u::Host::by_name_or_null(args[0]) != nullptr, "Unknown host %s. Stopping Now! ",
39 /* - Receive the (small) ping first ....*/
41 static_cast<double*>(simgrid::s4u::Mailbox::byName(simgrid::s4u::this_actor::get_host()->get_name())->get());
42 double communication_time = simgrid::s4u::Engine::getClock() - *sender_time;
43 XBT_INFO("Task received : small communication (latency bound)");
44 XBT_INFO(" Ping time (latency bound) %f", communication_time);
47 /* - ... Then send a 1GB pong back (bandwidth bound) */
48 double* payload = new double();
49 *payload = simgrid::s4u::Engine::getClock();
50 XBT_INFO("task_bw->data = %.3f", *payload);
52 simgrid::s4u::Mailbox::byName(args[0])->put(payload, 1e9);
55 int main(int argc, char* argv[])
57 simgrid::s4u::Engine e(&argc, argv);
59 e.load_platform(argv[1]);
60 std::vector<std::string> args;
61 args.push_back("Jupiter");
62 simgrid::s4u::Actor::create("pinger", simgrid::s4u::Host::by_name("Tremblay"), pinger, args);
65 args.push_back("Tremblay");
67 simgrid::s4u::Actor::create("ponger", simgrid::s4u::Host::by_name("Jupiter"), ponger, args);
71 XBT_INFO("Total simulation time: %.3f", e.getClock());