Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
399efa7b38fdb2b0c8c5e0506ba91d000795b118
[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 namespace sg4 = simgrid::s4u;
12
13 /* This actor simply executes and waits the activity it got as a parameter. */
14 static void runner(sg4::ExecPtr activity)
15 {
16   activity->start();
17   activity->wait();
18
19   XBT_INFO("Goodbye now!");
20 }
21
22 int main(int argc, char* argv[])
23 {
24   sg4::Engine e(&argc, argv);
25   e.load_platform(argv[1]);
26
27   sg4::Host* fafard = e.host_by_name("Fafard");
28
29   sg4::ExecPtr activity = sg4::this_actor::exec_init(fafard->get_speed() * 10.)->set_host(fafard);
30   sg4::Actor::create("runner", fafard, runner, activity);
31
32   while (activity->get_remaining() > 0) {
33     XBT_INFO("Remaining amount of flops: %g (%.0f%%)", activity->get_remaining(),
34              100 * activity->get_remaining_ratio());
35     e.run_until(sg4::Engine::get_clock() + 1);
36   }
37
38   XBT_INFO("Simulation time %g", sg4::Engine::get_clock());
39
40   return 0;
41 }