1 /* Copyright (c) 2019-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"
8 XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_exec_waitfor, "Messages specific for this s4u example");
12 simgrid::s4u::ExecPtr exec;
13 double amount = 5 * simgrid::s4u::this_actor::get_host()->get_speed();
14 XBT_INFO("Create an activity that should run for 5 seconds");
16 exec = simgrid::s4u::this_actor::exec_async(amount);
18 /* Now that execution is started, wait for 3 seconds. */
19 XBT_INFO("But let it end after 3 seconds");
22 XBT_INFO("Execution complete");
23 } catch (const simgrid::TimeoutException&) {
24 XBT_INFO("Execution Timeout!");
27 /* do it again, but this time with a timeout greater than the duration of the execution */
28 XBT_INFO("Create another activity that should run for 5 seconds and wait for it for 6 seconds");
29 exec = simgrid::s4u::this_actor::exec_async(amount);
32 XBT_INFO("Execution complete");
33 } catch (const simgrid::TimeoutException&) {
34 XBT_INFO("Execution Timeout!");
37 XBT_INFO("Finally test with a parallel execution");
38 auto hosts = simgrid::s4u::Engine::get_instance()->get_all_hosts();
39 size_t hosts_count = hosts.size();
40 std::vector<double> computation_amounts;
41 std::vector<double> communication_amounts;
43 computation_amounts.assign(hosts_count, 1e9 /*1Gflop*/);
44 communication_amounts.assign(hosts_count * hosts_count, 0);
45 for (size_t i = 0; i < hosts_count; i++)
46 for (size_t j = i + 1; j < hosts_count; j++)
47 communication_amounts[i * hosts_count + j] = 1e7; // 10 MB
49 exec = simgrid::s4u::this_actor::exec_init(hosts, computation_amounts, communication_amounts);
52 XBT_INFO("Parallel Execution complete");
53 } catch (const simgrid::TimeoutException&) {
54 XBT_INFO("Parallel Execution Timeout!");
58 int main(int argc, char* argv[])
60 simgrid::s4u::Engine e(&argc, argv);
61 e.load_platform(argv[1]);
62 simgrid::s4u::Actor::create("worker", simgrid::s4u::Host::by_name("Tremblay"), worker);