Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
deport three other MSG examples
[simgrid.git] / teshsuite / msg / plugin-hostload / plugin-hostload.c
1 /* Copyright (c) 2007-2010, 2013-2015. The SimGrid Team.
2  * All rights reserved.                                                     */
3
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. */
6
7 #include "simgrid/msg.h"
8 #include "simgrid/plugins/load.h"
9
10 XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test, "Messages specific for this msg example");
11
12 static int execute_load_test(int argc, char* argv[])
13 {
14   msg_host_t host = MSG_host_by_name("MyHost1");
15
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));
18
19   double start = MSG_get_clock();
20   XBT_INFO("Sleep for 10 seconds");
21   MSG_process_sleep(10);
22
23   XBT_INFO("Done sleeping %.2fs; peak speed: %.0E flop/s; number of flops computed so far: %.0E (nothing should have "
24            "changed)",
25            MSG_get_clock() - start, MSG_host_get_speed(host), sg_host_get_computed_flops(host));
26
27   // Run a task
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);
33
34   XBT_INFO("Done working on my task; this took %.2fs; current peak speed: %.0E flop/s; number of flops computed so "
35            "far: %.0E",
36            MSG_get_clock() - start, MSG_host_get_speed(host), sg_host_get_computed_flops(host));
37
38   // ========= Change power peak =========
39   int pstate = 2;
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));
43
44   // Run a second task
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 "
51            "far: %.0E",
52            MSG_get_clock() - start, MSG_host_get_speed(host), sg_host_get_computed_flops(host));
53
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");
58   MSG_process_sleep(4);
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));
61
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));
70   return 0;
71 }
72
73 int main(int argc, char* argv[])
74 {
75   sg_host_load_plugin_init();
76   MSG_init(&argc, argv);
77
78   xbt_assert(argc == 2, "Usage: %s platform_file\n\tExample: %s msg_platform.xml\n", argv[0], argv[0]);
79
80   MSG_create_environment(argv[1]);
81   MSG_process_create("load_test", execute_load_test, NULL, MSG_get_host_by_name("MyHost1"));
82
83   msg_error_t res = MSG_main();
84
85   XBT_INFO("Total simulation time: %.2f", MSG_get_clock());
86
87   return res != MSG_OK;
88 }