1 /* Copyright (c) 2007-2019. 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/msg.h"
8 #include "simgrid/plugins/load.h"
10 XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test, "Messages specific for this msg example");
12 static int execute_load_test(XBT_ATTRIB_UNUSED int argc, XBT_ATTRIB_UNUSED char* argv[])
14 msg_host_t host = MSG_host_by_name("MyHost1");
16 XBT_INFO("Initial peak speed: %.0E flop/s; number of flops computed so far: %.0E (should be 0)",
17 MSG_host_get_speed(host), sg_host_get_computed_flops(host));
19 double start = MSG_get_clock();
20 XBT_INFO("Sleep for 10 seconds");
21 MSG_process_sleep(10);
23 XBT_INFO("Done sleeping %.2fs; peak speed: %.0E flop/s; number of flops computed so far: %.0E (nothing should have "
25 MSG_get_clock() - start, MSG_host_get_speed(host), sg_host_get_computed_flops(host));
28 start = MSG_get_clock();
29 msg_task_t task1 = MSG_task_create("t1", 100E6, 0, NULL);
30 XBT_INFO("Run a task of %.0E flops", MSG_task_get_flops_amount(task1));
31 MSG_task_execute(task1);
32 MSG_task_destroy(task1);
34 XBT_INFO("Done working on my task; this took %.2fs; current peak speed: %.0E flop/s; number of flops computed so "
36 MSG_get_clock() - start, MSG_host_get_speed(host), sg_host_get_computed_flops(host));
38 // ========= Change power peak =========
40 sg_host_set_pstate(host, pstate);
41 XBT_INFO("========= Requesting pstate %d (speed should be of %.0E flop/s and is of %.0E flop/s)", pstate,
42 MSG_host_get_power_peak_at(host, pstate), MSG_host_get_speed(host));
45 start = MSG_get_clock();
46 task1 = MSG_task_create("t2", 100E6, 0, NULL);
47 XBT_INFO("Run a task of %.0E flops", MSG_task_get_flops_amount(task1));
48 MSG_task_execute(task1);
49 MSG_task_destroy(task1);
50 XBT_INFO("Done working on my task; this took %.2fs; current peak speed: %.0E flop/s; number of flops computed so "
52 MSG_get_clock() - start, MSG_host_get_speed(host), sg_host_get_computed_flops(host));
54 start = MSG_get_clock();
55 XBT_INFO("========= Requesting a reset of the computation counter");
56 sg_host_load_reset(host);
57 XBT_INFO("Sleep for 4 seconds");
59 XBT_INFO("Done sleeping %.2f s; peak speed: %.0E flop/s; number of flops computed so far: %.0E",
60 MSG_get_clock() - start, MSG_host_get_speed(host), sg_host_get_computed_flops(host));
62 // =========== Turn the other host off ==========
63 XBT_INFO("Turning MyHost2 off, and sleeping another 10 seconds. MyHost2 computed %.0f flops so far.",
64 MSG_host_get_computed_flops(MSG_host_by_name("MyHost2")));
65 MSG_host_off(MSG_host_by_name("MyHost2"));
66 start = MSG_get_clock();
67 MSG_process_sleep(10);
68 XBT_INFO("Done sleeping %.2f s; peak speed: %.0E flop/s; number of flops computed so far: %.0E",
69 MSG_get_clock() - start, MSG_host_get_speed(host), sg_host_get_computed_flops(host));
73 int main(int argc, char* argv[])
75 sg_host_load_plugin_init();
76 MSG_init(&argc, argv);
78 xbt_assert(argc == 2, "Usage: %s platform_file\n\tExample: %s msg_platform.xml\n", argv[0], argv[0]);
80 MSG_create_environment(argv[1]);
81 MSG_process_create("load_test", execute_load_test, NULL, MSG_get_host_by_name("MyHost1"));
83 msg_error_t res = MSG_main();
85 XBT_INFO("Total simulation time: %.2f", MSG_get_clock());