1 /* Copyright (c) 2007-2017. 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"
7 #include "simgrid/plugins/load.h"
9 XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_test, "Messages specific for this s4u example");
11 static void execute_load_test()
13 s4u_Host* host = simgrid::s4u::Host::by_name("MyHost1");
15 XBT_INFO("Initial peak speed: %.0E flop/s; number of flops computed so far: %.0E (should be 0)", host->getSpeed(),
16 sg_host_get_computed_flops(host));
18 double start = simgrid::s4u::Engine::getClock();
19 XBT_INFO("Sleep for 10 seconds");
20 simgrid::s4u::this_actor::sleep_for(10);
22 XBT_INFO("Done sleeping %.2fs; peak speed: %.0E flop/s; number of flops computed so far: %.0E (nothing should have "
24 simgrid::s4u::Engine::getClock() - start, host->getSpeed(), sg_host_get_computed_flops(host));
27 start = simgrid::s4u::Engine::getClock();
28 XBT_INFO("Run a task of %.0E flops", 100E6);
29 simgrid::s4u::this_actor::execute(100E6);
31 XBT_INFO("Done working on my task; this took %.2fs; current peak speed: %.0E flop/s; number of flops computed so "
33 simgrid::s4u::Engine::getClock() - start, host->getSpeed(), sg_host_get_computed_flops(host));
35 // ========= Change power peak =========
37 host->setPstate(pstate);
38 XBT_INFO("========= Requesting pstate %d (speed should be of %.0E flop/s and is of %.0E flop/s)", pstate,
39 host->getPstateSpeed(pstate), host->getSpeed());
42 start = simgrid::s4u::Engine::getClock();
43 XBT_INFO("Run a task of %.0E flops", 100E6);
44 simgrid::s4u::this_actor::execute(100E6);
45 XBT_INFO("Done working on my task; this took %.2fs; current peak speed: %.0E flop/s; number of flops computed so "
47 simgrid::s4u::Engine::getClock() - start, host->getSpeed(), sg_host_get_computed_flops(host));
49 start = simgrid::s4u::Engine::getClock();
50 XBT_INFO("========= Requesting a reset of the computation counter");
51 sg_host_load_reset(host);
52 XBT_INFO("Sleep for 4 seconds");
53 simgrid::s4u::this_actor::sleep_for(4);
54 XBT_INFO("Done sleeping %.2f s; peak speed: %.0E flop/s; number of flops computed so far: %.0E",
55 simgrid::s4u::Engine::getClock() - start, host->getSpeed(), sg_host_get_computed_flops(host));
57 // =========== Turn the other host off ==========
58 s4u_Host* host2 = simgrid::s4u::Host::by_name("MyHost2");
59 XBT_INFO("Turning MyHost2 off, and sleeping another 10 seconds. MyHost2 computed %.0f flops so far.",
60 sg_host_get_computed_flops(host2));
62 start = simgrid::s4u::Engine::getClock();
63 simgrid::s4u::this_actor::sleep_for(10);
64 XBT_INFO("Done sleeping %.2f s; peak speed: %.0E flop/s; number of flops computed so far: %.0E",
65 simgrid::s4u::Engine::getClock() - start, host->getSpeed(), sg_host_get_computed_flops(host));
68 int main(int argc, char* argv[])
70 sg_host_load_plugin_init();
71 simgrid::s4u::Engine e(&argc, argv);
73 xbt_assert(argc == 2, "Usage: %s platform_file\n\tExample: %s msg_platform.xml\n", argv[0], argv[0]);
74 e.loadPlatform(argv[1]);
76 simgrid::s4u::Actor::createActor("load_test", simgrid::s4u::Host::by_name("MyHost1"), execute_load_test);
80 XBT_INFO("Total simulation time: %.2f", simgrid::s4u::Engine::getClock());