Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Update copyright lines for 2022.
[simgrid.git] / examples / cpp / engine-run-partial / s4u-engine-run-partial.cpp
1 /* Copyright (c) 2007-2022. The SimGrid Team. All rights reserved.          */
2
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. */
5
6 /* This example is to show how to use Engine::run(date) to simulate only up to that point in time */
7
8 #include "simgrid/s4u.hpp"
9
10 XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_test, "Messages specific for this s4u example");
11
12 /* This actor simply executes and waits the activity it got as a parameter. */
13 static void runner(simgrid::s4u::ExecPtr activity)
14 {
15   activity->start();
16   activity->wait();
17
18   XBT_INFO("Goodbye now!");
19 }
20
21 int main(int argc, char* argv[])
22 {
23   simgrid::s4u::Engine e(&argc, argv);
24   e.load_platform(argv[1]);
25
26   simgrid::s4u::Host* fafard = e.host_by_name("Fafard");
27
28   simgrid::s4u::ExecPtr activity = simgrid::s4u::this_actor::exec_init(fafard->get_speed() * 10.)->set_host(fafard);
29   simgrid::s4u::Actor::create("runner", fafard, runner, activity);
30
31   while (activity->get_remaining() > 0) {
32     XBT_INFO("Remaining amount of flops: %g (%.0f%%)", activity->get_remaining(),
33              100 * activity->get_remaining_ratio());
34     e.run_until(simgrid::s4u::Engine::get_clock() + 1);
35   }
36
37   XBT_INFO("Simulation time %g", simgrid::s4u::Engine::get_clock());
38
39   return 0;
40 }