1 /* Copyright (c) 2007-2010, 2013-2015. The SimGrid Team.
2 * All rights reserved. */
4 /* This program is free software; you can redistribute it and/or modify it
5 * under the terms of the license (GNU LGPL) which comes with this package. */
7 #include "simgrid/s4u.hpp"
8 #include "simgrid/plugins/load.h"
10 XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_test, "Messages specific for this s4u example");
12 static void execute_load_test()
14 s4u_Host* host = simgrid::s4u::Host::by_name("MyHost1");
16 XBT_INFO("Initial peak speed: %.0E flop/s; number of flops computed so far: %.0E (should be 0)", host->getSpeed(),
17 sg_host_get_computed_flops(host));
19 double start = simgrid::s4u::Engine::getClock();
20 XBT_INFO("Sleep for 10 seconds");
21 simgrid::s4u::this_actor::sleep_for(10);
23 XBT_INFO("Done sleeping %.2fs; peak speed: %.0E flop/s; number of flops computed so far: %.0E (nothing should have "
25 simgrid::s4u::Engine::getClock() - start, host->getSpeed(), sg_host_get_computed_flops(host));
28 start = simgrid::s4u::Engine::getClock();
29 XBT_INFO("Run a task of %.0E flops", 100E6);
30 simgrid::s4u::this_actor::execute(100E6);
32 XBT_INFO("Done working on my task; this took %.2fs; current peak speed: %.0E flop/s; number of flops computed so "
34 simgrid::s4u::Engine::getClock() - start, host->getSpeed(), sg_host_get_computed_flops(host));
36 // ========= Change power peak =========
38 host->setPstate(pstate);
39 XBT_INFO("========= Requesting pstate %d (speed should be of %.0E flop/s and is of %.0E flop/s)", pstate,
40 host->getPstateSpeed(pstate), host->getSpeed());
43 start = simgrid::s4u::Engine::getClock();
44 XBT_INFO("Run a task of %.0E flops", 100E6);
45 simgrid::s4u::this_actor::execute(100E6);
46 XBT_INFO("Done working on my task; this took %.2fs; current peak speed: %.0E flop/s; number of flops computed so "
48 simgrid::s4u::Engine::getClock() - start, host->getSpeed(), sg_host_get_computed_flops(host));
50 start = simgrid::s4u::Engine::getClock();
51 XBT_INFO("========= Requesting a reset of the computation counter");
52 sg_host_load_reset(host);
53 XBT_INFO("Sleep for 4 seconds");
54 simgrid::s4u::this_actor::sleep_for(4);
55 XBT_INFO("Done sleeping %.2f s; peak speed: %.0E flop/s; number of flops computed so far: %.0E",
56 simgrid::s4u::Engine::getClock() - start, host->getSpeed(), sg_host_get_computed_flops(host));
58 // =========== Turn the other host off ==========
59 s4u_Host* host2 = simgrid::s4u::Host::by_name("MyHost2");
60 XBT_INFO("Turning MyHost2 off, and sleeping another 10 seconds. MyHost2 computed %.0f flops so far.",
61 sg_host_get_computed_flops(host2));
63 start = simgrid::s4u::Engine::getClock();
64 simgrid::s4u::this_actor::sleep_for(10);
65 XBT_INFO("Done sleeping %.2f s; peak speed: %.0E flop/s; number of flops computed so far: %.0E",
66 simgrid::s4u::Engine::getClock() - start, host->getSpeed(), sg_host_get_computed_flops(host));
69 int main(int argc, char* argv[])
71 sg_host_load_plugin_init();
72 simgrid::s4u::Engine* e = new simgrid::s4u::Engine(&argc, argv);
74 xbt_assert(argc == 2, "Usage: %s platform_file\n\tExample: %s msg_platform.xml\n", argv[0], argv[0]);
75 e->loadPlatform(argv[1]);
77 simgrid::s4u::Actor::createActor("load_test", simgrid::s4u::Host::by_name("MyHost1"), execute_load_test);
81 XBT_INFO("Total simulation time: %.2f", simgrid::s4u::Engine::getClock());