1 /* Copyright (c) 2007-2020. 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/actor.h"
8 #include "simgrid/engine.h"
9 #include "simgrid/host.h"
10 #include "simgrid/plugins/load.h"
12 #include "xbt/asserts.h"
15 XBT_LOG_NEW_DEFAULT_CATEGORY(hostload_test, "Messages specific for this example");
17 static void execute_load_test(XBT_ATTRIB_UNUSED int argc, XBT_ATTRIB_UNUSED char* argv[])
19 sg_host_t host = sg_host_by_name("MyHost1");
21 XBT_INFO("Initial peak speed: %.0E flop/s; number of flops computed so far: %.0E (should be 0) and current average "
22 "load: %.5f (should be 0)",
23 sg_host_speed(host), sg_host_get_computed_flops(host), sg_host_get_avg_load(host));
25 double start = simgrid_get_clock();
26 XBT_INFO("Sleep for 10 seconds");
27 sg_actor_sleep_for(10);
29 double speed = sg_host_speed(host);
30 XBT_INFO("Done sleeping %.2fs; peak speed: %.0E flop/s; number of flops computed so far: %.0E (nothing should have "
32 simgrid_get_clock() - start, sg_host_speed(host), sg_host_get_computed_flops(host));
35 start = simgrid_get_clock();
36 XBT_INFO("Run a task of %.0E flops at current speed of %.0E flop/s", 200e6, sg_host_speed(host));
37 sg_actor_execute(200e6);
39 XBT_INFO("Done working on my task; this took %.2fs; current peak speed: %.0E flop/s (when I started the computation, "
40 "the speed was set to %.0E flop/s); number of flops computed so "
41 "far: %.2E, average load as reported by the HostLoad plugin: %.5f (should be %.5f)",
42 simgrid_get_clock() - start, sg_host_speed(host), speed, sg_host_get_computed_flops(host),
43 sg_host_get_avg_load(host),
44 200E6 / (10.5 * speed * sg_host_core_count(host) +
45 (simgrid_get_clock() - start - 0.5) * sg_host_speed(host) * sg_host_core_count(host)));
47 // ========= Change power peak =========
49 sg_host_set_pstate(host, pstate);
51 "========= Requesting pstate %d (speed should be of %.0E flop/s and is of %.0E flop/s, average load is %.5f)",
52 pstate, sg_host_get_pstate_speed(host, pstate), sg_host_speed(host), sg_host_get_avg_load(host));
55 start = simgrid_get_clock();
56 XBT_INFO("Run a task of %.0E flops", 100e6);
57 sg_actor_execute(100e6);
58 XBT_INFO("Done working on my task; this took %.2fs; current peak speed: %.0E flop/s; number of flops computed so "
60 simgrid_get_clock() - start, sg_host_speed(host), sg_host_get_computed_flops(host));
62 start = simgrid_get_clock();
63 XBT_INFO("========= Requesting a reset of the computation and load counters");
64 sg_host_load_reset(host);
65 XBT_INFO("After reset: %.0E flops computed; load is %.5f", sg_host_get_computed_flops(host),
66 sg_host_get_avg_load(host));
67 XBT_INFO("Sleep for 4 seconds");
68 sg_actor_sleep_for(4);
69 XBT_INFO("Done sleeping %.2f s; peak speed: %.0E flop/s; number of flops computed so far: %.0E",
70 simgrid_get_clock() - start, sg_host_speed(host), sg_host_get_computed_flops(host));
72 // =========== Turn the other host off ==========
73 XBT_INFO("Turning MyHost2 off, and sleeping another 10 seconds. MyHost2 computed %.0f flops so far and has an "
74 "average load of %.5f.",
75 sg_host_get_computed_flops(sg_host_by_name("MyHost2")), sg_host_get_avg_load(sg_host_by_name("MyHost2")));
76 sg_host_turn_off(sg_host_by_name("MyHost2"));
77 start = simgrid_get_clock();
78 sg_actor_sleep_for(10);
79 XBT_INFO("Done sleeping %.2f s; peak speed: %.0E flop/s; number of flops computed so far: %.0E",
80 simgrid_get_clock() - start, sg_host_speed(host), sg_host_get_computed_flops(host));
83 static void change_speed(XBT_ATTRIB_UNUSED int argc, XBT_ATTRIB_UNUSED char* argv[])
85 sg_host_t host = sg_host_by_name("MyHost1");
86 sg_actor_sleep_for(10.5);
87 XBT_INFO("I slept until now, but now I'll change the speed of this host "
88 "while the other process is still computing! This should slow the computation down.");
89 sg_host_set_pstate(host, 2);
92 int main(int argc, char* argv[])
94 sg_host_load_plugin_init();
95 simgrid_init(&argc, argv);
97 xbt_assert(argc == 2, "Usage: %s platform_file\n\tExample: %s msg_platform.xml\n", argv[0], argv[0]);
99 simgrid_load_platform(argv[1]);
100 sg_actor_t actor = sg_actor_init("load_test", sg_host_by_name("MyHost1"));
101 sg_actor_start(actor, execute_load_test, 0, NULL);
103 sg_actor_t actor2 = sg_actor_init("change_speed", sg_host_by_name("MyHost1"));
104 sg_actor_start(actor2, change_speed, 0, NULL);
108 XBT_INFO("Total simulation time: %.2f", simgrid_get_clock());