1 /* Copyright (c) 2010-2021. 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/kernel/ProfileBuilder.hpp"
8 #include "simgrid/s4u.hpp"
10 namespace sg4 = simgrid::s4u;
12 XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_test, "Messages specific for this s4u example");
14 static void run_activities(int n, double size, double rate = -1.0)
16 double start = sg4::Engine::get_clock();
17 std::vector<sg4::ExecPtr> activities;
19 // initialize exec activities
20 for (int i = 0; i < n; i++) {
21 sg4::ExecPtr op = sg4::this_actor::exec_init(size);
25 activities.emplace_back(op);
28 // waiting for executions
29 for (const auto& act : activities)
31 XBT_INFO("Finished running 2 activities, elapsed %lf", sg4::Engine::get_clock() - start);
36 XBT_INFO("Running 1 tasks (1.5e6) in a 2*(1e6) speed host. Should take 2s (1 (limited by core) + 1 (limited by speed "
38 run_activities(1, 1.5e6);
40 XBT_INFO("Running 1 tasks (.8e6) in a 2*(1e6) speed host with limited rate (.4e6). Should take 2s (limited by rate)");
41 run_activities(1, .8e6, .4e6);
43 XBT_INFO("Running 1 tasks (1.1e6) in a 2*(1e6) speed host with limited rate (.6e6). Should take 2s (.6 limited by "
44 "rate + .5 limited by speed file)");
45 run_activities(1, 1.1e6, .6e6);
47 XBT_INFO("Running 2 tasks (1e6) in a 2*(1e6) speed host. Should take 1s");
48 run_activities(2, 1e6);
50 XBT_INFO("Running 2 tasks (.5e6) in a .5*2*(1e6) speed host. Should take 1s");
51 run_activities(2, .5e6);
53 XBT_INFO("Running 2 tasks (1.1e6) with limited rate (.6e6). Should take 2s (0.6 limited by rate + 0.5 limited by "
55 run_activities(2, 1.1e6, .6e6);
57 XBT_INFO("Running 2 tasks (.8e6) with limited rate (.4e6). Should take 2s (limited by rate)");
58 run_activities(2, .8e6, .4e6);
60 XBT_INFO("I'm done. See you!");
63 static void failed_worker()
65 XBT_INFO("Running a 2 tasks: a small .5e6 and a big 2e6.");
66 sg4::ExecPtr ok = sg4::this_actor::exec_init(.5e6);
67 sg4::ExecPtr fail = sg4::this_actor::exec_init(2e6);
69 XBT_INFO("Finished the small task");
71 XBT_INFO("Waiting big task to finish");
73 } catch (const simgrid::ForcefulKillException&) {
74 XBT_INFO("Unable to finish big task, host went down");
78 int main(int argc, char* argv[])
80 sg4::Engine e(&argc, argv);
82 /* speed and state file description */
83 const char* erin_state_file = R"(
89 const char* carol_speed_file = R"(
93 /* simple platform containing 1 host and 2 disk */
94 auto* zone = sg4::create_full_zone("red");
95 zone->create_host("erin", 1e6)
97 ->set_state_profile(simgrid::kernel::profile::ProfileBuilder::from_string("erin_state", erin_state_file, 0))
99 zone->create_host("carol", 1e6)
101 ->set_speed_profile(simgrid::kernel::profile::ProfileBuilder::from_string("carol_speed", carol_speed_file, 1))
105 sg4::Actor::create("carol", e.host_by_name("carol"), worker);
106 sg4::Actor::create("erin", e.host_by_name("erin"), failed_worker)->set_auto_restart(true);
110 XBT_INFO("Simulation time %g", sg4::Engine::get_clock());