1 /* Copyright (c) 2013-2022. 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. */
7 * Test for issue105: https://framagit.org/simgrid/simgrid/-/issues/105
10 #include <simgrid/kernel/ProfileBuilder.hpp>
11 #include <simgrid/s4u.hpp>
13 namespace sg4 = simgrid::s4u;
15 XBT_LOG_NEW_DEFAULT_CATEGORY(issue105, "Issue105");
16 static void load_generator(sg4::Mailbox* mailbox)
18 std::vector<sg4::CommPtr> comms;
20 // Send the task messages
21 for (int i = 0; i < 100; i++) {
22 auto* payload = new int(i);
23 sg4::CommPtr comm = mailbox->put_async(payload, 1024);
24 comms.push_back(comm);
25 sg4::this_actor::sleep_for(1.0);
28 // send shutdown messages
29 auto* payload = new int(-1);
30 sg4::CommPtr comm = mailbox->put_async(payload, 1024);
31 XBT_INFO("Sent shutdown");
32 comms.push_back(comm);
34 // Wait for all messages to be consumed before ending the simulation
35 sg4::Comm::wait_all(comms);
36 XBT_INFO("Load generator finished");
39 static void receiver(sg4::Mailbox* mailbox)
41 bool shutdown = false;
42 while (not shutdown) {
43 auto msg = mailbox->get_unique<int>();
45 XBT_INFO("Started Task: %d", *msg);
46 sg4::this_actor::execute(1e9);
51 XBT_INFO("Receiver finished");
54 int main(int argc, char* argv[])
56 sg4::Engine e(&argc, argv);
58 sg4::NetZone* world = sg4::create_full_zone("world");
59 sg4::Host* hostGl01 = world->create_host("host-gl01", "98Mf")->seal();
60 sg4::Host* hostSa01 = world->create_host("host-sa01", "98Mf")->seal();
62 // create latency and bandwidth profiles
63 auto* linkSaLatencyProfile = simgrid::kernel::profile::ProfileBuilder::from_string("link-sa-latency-profile",
67 auto* linkSaBandwidthProfile = simgrid::kernel::profile::ProfileBuilder::from_string("link-sa-bandwidth-profile",
72 const sg4::Link* linkSa = world->create_link("link-front-sa", "42MBps")
74 ->set_latency_profile(linkSaLatencyProfile)
75 ->set_bandwidth_profile(linkSaBandwidthProfile)
78 world->add_route(hostGl01->get_netpoint(), hostSa01->get_netpoint(), nullptr, nullptr,
79 {{linkSa, sg4::LinkInRoute::Direction::NONE}}, true);
82 sg4::Mailbox* mb1 = e.mailbox_by_name_or_create("Mailbox 1");
83 sg4::Actor::create("load-generator", hostGl01, load_generator, mb1);
84 sg4::Actor::create("cluster-node-sa01", hostSa01, receiver, mb1);
88 XBT_INFO("Total simulation time: %.3f", e.get_clock());