1 /* Copyright (c) 2007-2019. 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(simgrid::s4u::Mailbox* mailbox_in, simgrid::s4u::Mailbox* mailbox_out)
12 XBT_INFO("Ping from mailbox %s to mailbox %s", mailbox_in->get_name().c_str(), mailbox_out->get_name().c_str());
14 /* - Do the ping with a 1-Byte task (latency bound) ... */
15 double* payload = new double();
16 *payload = simgrid::s4u::Engine::get_clock();
18 mailbox_out->put(payload, 1);
19 /* - ... then wait for the (large) pong */
20 double* sender_time = static_cast<double*>(mailbox_in->get());
22 double communication_time = simgrid::s4u::Engine::get_clock() - *sender_time;
23 XBT_INFO("Task received : large communication (bandwidth bound)");
24 XBT_INFO("Pong time (bandwidth bound): %.3f", communication_time);
28 static void ponger(simgrid::s4u::Mailbox* mailbox_in, simgrid::s4u::Mailbox* mailbox_out)
30 XBT_INFO("Pong from mailbox %s to mailbox %s", mailbox_in->get_name().c_str(), mailbox_out->get_name().c_str());
32 /* - Receive the (small) ping first ....*/
33 double* sender_time = static_cast<double*>(mailbox_in->get());
34 double communication_time = simgrid::s4u::Engine::get_clock() - *sender_time;
35 XBT_INFO("Task received : small communication (latency bound)");
36 XBT_INFO(" Ping time (latency bound) %f", communication_time);
39 /* - ... Then send a 1GB pong back (bandwidth bound) */
40 double* payload = new double();
41 *payload = simgrid::s4u::Engine::get_clock();
42 XBT_INFO("task_bw->data = %.3f", *payload);
44 mailbox_out->put(payload, 1e9);
47 int main(int argc, char* argv[])
49 simgrid::s4u::Engine e(&argc, argv);
50 e.load_platform(argv[1]);
52 simgrid::s4u::Mailbox* mb1 = simgrid::s4u::Mailbox::by_name("Mailbox 1");
53 simgrid::s4u::Mailbox* mb2 = simgrid::s4u::Mailbox::by_name("Mailbox 2");
55 simgrid::s4u::Actor::create("pinger", simgrid::s4u::Host::by_name("Tremblay"), pinger, mb1, mb2);
56 simgrid::s4u::Actor::create("ponger", simgrid::s4u::Host::by_name("Jupiter"), ponger, mb2, mb1);
60 XBT_INFO("Total simulation time: %.3f", e.get_clock());