1 /* Copyright (c) 2007-2017. 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::getHost()->getName())->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);
31 static void ponger(std::vector<std::string> args)
33 xbt_assert(args.size() == 1, "The ponger function one argument from the XML deployment file");
34 XBT_INFO("Pong -> %s", args[0].c_str());
35 xbt_assert(simgrid::s4u::Host::by_name_or_null(args[0]) != nullptr, "Unknown host %s. Stopping Now! ",
38 /* - Receive the (small) ping first ....*/
40 (static_cast<double*>(simgrid::s4u::Mailbox::byName(simgrid::s4u::this_actor::getHost()->getName())->get()));
41 double communication_time = simgrid::s4u::Engine::getClock() - *sender_time;
42 XBT_INFO("Task received : small communication (latency bound)");
43 XBT_INFO(" Ping time (latency bound) %f", communication_time);
45 /* - ... Then send a 1GB pong back (bandwidth bound) */
46 double* payload = new double();
47 *payload = simgrid::s4u::Engine::getClock();
48 XBT_INFO("task_bw->data = %.3f", *payload);
50 simgrid::s4u::Mailbox::byName(args[0])->put(payload, 1e9);
53 int main(int argc, char* argv[])
55 simgrid::s4u::Engine* e = new simgrid::s4u::Engine(&argc, argv);
57 e->loadPlatform(argv[1]);
58 std::vector<std::string> args;
59 args.push_back("Jupiter");
60 simgrid::s4u::Actor::createActor("pinger", simgrid::s4u::Host::by_name("Tremblay"), pinger, args);
63 args.push_back("Tremblay");
65 simgrid::s4u::Actor::createActor("ponger", simgrid::s4u::Host::by_name("Jupiter"), ponger, args);
69 XBT_INFO("Total simulation time: %.3f", e->getClock());