1 /* Copyright (c) 2007-2021. 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>
7 namespace sg4 = simgrid::s4u;
9 XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_app_pingpong, "Messages specific for this s4u example");
11 static void pinger(sg4::Mailbox* mailbox_in, sg4::Mailbox* mailbox_out)
13 XBT_INFO("Ping from mailbox %s to mailbox %s", mailbox_in->get_name().c_str(), mailbox_out->get_name().c_str());
15 /* - Do the ping with a 1-Byte payload (latency bound) ... */
16 auto* payload = new double(sg4::Engine::get_clock());
18 mailbox_out->put(payload, 1);
19 /* - ... then wait for the (large) pong */
20 auto sender_time = mailbox_in->get_unique<double>();
22 double communication_time = sg4::Engine::get_clock() - *sender_time;
23 XBT_INFO("Payload received : large communication (bandwidth bound)");
24 XBT_INFO("Pong time (bandwidth bound): %.3f", communication_time);
27 static void ponger(sg4::Mailbox* mailbox_in, sg4::Mailbox* mailbox_out)
29 XBT_INFO("Pong from mailbox %s to mailbox %s", mailbox_in->get_name().c_str(), mailbox_out->get_name().c_str());
31 /* - Receive the (small) ping first ....*/
32 auto sender_time = mailbox_in->get_unique<double>();
33 double communication_time = sg4::Engine::get_clock() - *sender_time;
34 XBT_INFO("Payload received : small communication (latency bound)");
35 XBT_INFO("Ping time (latency bound) %f", communication_time);
37 /* - ... Then send a 1GB pong back (bandwidth bound) */
38 auto* payload = new double(sg4::Engine::get_clock());
39 XBT_INFO("payload = %.3f", *payload);
41 mailbox_out->put(payload, 1e9);
44 int main(int argc, char* argv[])
46 sg4::Engine e(&argc, argv);
47 e.load_platform(argv[1]);
49 sg4::Mailbox* mb1 = sg4::Mailbox::by_name("Mailbox 1");
50 sg4::Mailbox* mb2 = sg4::Mailbox::by_name("Mailbox 2");
52 sg4::Actor::create("pinger", sg4::Host::by_name("Tremblay"), pinger, mb1, mb2);
53 sg4::Actor::create("ponger", sg4::Host::by_name("Jupiter"), ponger, mb2, mb1);
57 XBT_INFO("Total simulation time: %.3f", sg4::Engine::get_clock());