1 /* Copyright (c) 2010-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 /* This example shows how to simulate variability for CPUs, using multiplicative factors
9 #include <simgrid/s4u.hpp>
11 namespace sg4 = simgrid::s4u;
13 XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_test, "Messages specific for this s4u example");
15 /*************************************************************************************************/
18 double computation_amount = sg4::this_actor::get_host()->get_speed();
20 XBT_INFO("Executing 1 tasks of %g flops, should take 1 second.", computation_amount);
21 sg4::this_actor::execute(computation_amount);
22 XBT_INFO("Executing 1 tasks of %g flops, it would take .001s without factor. It'll take .002s",
23 computation_amount / 10);
24 sg4::this_actor::execute(computation_amount / 1000);
26 XBT_INFO("Finished executing. Goodbye now!");
28 /*************************************************************************************************/
29 /** @brief Variability for CPU */
30 static double cpu_variability(const sg4::Host* host, double flops)
32 /* creates variability for tasks smaller than 1% of CPU power.
33 * unrealistic, for learning purposes */
35 double speed = host->get_speed();
36 if (flops < speed / 100) {
39 XBT_INFO("Host %s, task with %lf flops, new factor %lf", host->get_cname(), flops, factor);
43 /** @brief Create a simple 1-host platform */
44 static void load_platform()
46 auto* zone = sg4::create_empty_zone("Zone1");
47 auto* runner_host = zone->create_host("runner", 1e6);
48 runner_host->set_factor_cb(std::bind(&cpu_variability, runner_host, std::placeholders::_1))->seal();
51 /* create actor runner */
52 sg4::Actor::create("runner", runner_host, runner);
55 /*************************************************************************************************/
56 int main(int argc, char* argv[])
58 sg4::Engine e(&argc, argv);
63 /* runs the simulation */