1 /* Copyright (c) 2010-2022. The SimGrid Team.
2 * All rights reserved. */
4 /* This program is free software; you can redistribute it and/or modify it
5 * under the terms of the license (GNU LGPL) which comes with this package. */
7 #include "simgrid/s4u.hpp"
9 XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_test, "Messages specific for this example");
13 simgrid::s4u::Mailbox* mailbox = simgrid::s4u::Mailbox::by_name("comm");
14 simgrid::s4u::Host* jupiter = simgrid::s4u::Host::by_name("Jupiter");
16 XBT_INFO("Master starting");
17 simgrid::s4u::this_actor::sleep_for(0.5);
19 auto* payload = new std::string("COMM");
20 simgrid::s4u::CommPtr comm = mailbox->put_async(payload, 1E8);
22 simgrid::s4u::this_actor::sleep_for(0.5);
24 XBT_INFO("Turning off the worker host");
29 } catch (const simgrid::NetworkFailureException&) {
33 XBT_INFO("Master has finished");
38 simgrid::s4u::Mailbox* mailbox = simgrid::s4u::Mailbox::by_name("comm");
40 XBT_INFO("Worker receiving");
42 auto payload = mailbox->get_unique<std::string>();
43 XBT_DEBUG("Received message: %s", payload->c_str());
44 } catch (const simgrid::HostFailureException&) {
45 XBT_DEBUG("The host has been turned off, this was expected");
49 XBT_ERROR("Worker should be off already.");
52 int main(int argc, char* argv[])
54 simgrid::s4u::Engine e(&argc, argv);
55 xbt_assert(argc == 2, "Usage: %s platform_file\n\tExample: %s small_platform.xml\n", argv[0], argv[0]);
57 e.load_platform(argv[1]);
59 simgrid::s4u::Actor::create("master", e.host_by_name("Tremblay"), master);
60 simgrid::s4u::Actor::create("worker", e.host_by_name("Jupiter"), worker);
64 XBT_INFO("Simulation time %g", simgrid::s4u::Engine::get_clock());