1 /* Copyright (c) 2007-2020. 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_comm_dependent, "Messages specific for this s4u example");
10 static void sender(simgrid::s4u::Mailbox* mailbox)
12 double* computation_amount = new double();
13 *computation_amount = simgrid::s4u::this_actor::get_host()->get_speed();
14 simgrid::s4u::ExecPtr exec = simgrid::s4u::this_actor::exec_init(2 * (*computation_amount));
15 simgrid::s4u::CommPtr comm = mailbox->put_init(computation_amount, 7e6);
17 exec->set_name("exec on sender")->add_successor(comm)->start();
18 comm->set_name("comm to receiver")->vetoable_start();
23 static void receiver(simgrid::s4u::Mailbox* mailbox)
25 double* received = nullptr;
26 double computation_amount = simgrid::s4u::this_actor::get_host()->get_speed();
27 simgrid::s4u::ExecPtr exec = simgrid::s4u::this_actor::exec_init(2 * computation_amount);
28 simgrid::s4u::CommPtr comm = mailbox->get_init()->set_dst_data((void**)&received, sizeof(double));
30 comm->set_name("comm from sender")->add_successor(exec)->start();
31 exec->set_name("exec on receiver")->vetoable_start();
35 XBT_INFO("Received: %.0f flops were computed on sender", *received);
39 int main(int argc, char* argv[])
41 simgrid::s4u::Engine e(&argc, argv);
42 e.load_platform(argv[1]);
44 simgrid::s4u::Mailbox* mbox = simgrid::s4u::Mailbox::by_name("Mailbox");
46 simgrid::s4u::Actor::create("sender", simgrid::s4u::Host::by_name("Tremblay"), sender, mbox);
47 simgrid::s4u::Actor::create("receiver", simgrid::s4u::Host::by_name("Jupiter"), receiver, mbox);
51 XBT_INFO("Simulation time: %.3f", e.get_clock());