Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
5483c2fa0f58256d780bd137b5309a5cf388ba5c
[simgrid.git] / examples / s4u / platform-profile / s4u-platform-profile.cpp
1 /* Copyright (c) 2017-2019. The SimGrid Team. All rights reserved.          */
2
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. */
5
6 #include "simgrid/s4u.hpp"
7
8 /* This example demonstrates how to attach a profile to an host or a link,
9  * to specify external changes to the resource speed. The first way to do
10  * so is to use a file in the XML, while the second is to use the programmatic interface.
11  */
12
13 XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_platform_profile, "Messages specific for this s4u example");
14
15 /* Main function of the Yielder process */
16 static void watcher()
17 {
18   simgrid::s4u::Host* jupiter = simgrid::s4u::Host::by_name("Jupiter");
19   simgrid::s4u::Host* fafard  = simgrid::s4u::Host::by_name("Fafard");
20   simgrid::s4u::Link* link1   = simgrid::s4u::Link::by_name("1");
21   simgrid::s4u::Link* link2   = simgrid::s4u::Link::by_name("2");
22
23   for (int i = 0; i < 10; i++) {
24     XBT_INFO("Fafard: %.0fGflops, Jupiter: % 3.0fGflops, Link1: (%.2fMB/s %.0fms), Link2: (%.2fMB/s %.0fms)",
25              fafard->get_speed() * fafard->get_available_speed() / 1000000,
26              jupiter->get_speed() * jupiter->get_available_speed() / 1000000, link1->get_bandwidth() / 1000,
27              link1->get_latency() * 1000, link2->get_bandwidth() / 1000, link2->get_latency() * 1000);
28     simgrid::s4u::this_actor::sleep_for(1);
29   }
30 }
31
32 int main(int argc, char* argv[])
33 {
34   simgrid::s4u::Engine e(&argc, argv);
35
36   xbt_assert(argc > 1, "Usage: %s platform_file\n\tExample: %s platform.xml deployment.xml\n", argv[0], argv[0]);
37
38   e.load_platform(argv[1]);
39
40   simgrid::s4u::Actor::create("watcher", simgrid::s4u::Host::by_name("Tremblay"), watcher);
41
42   e.run(); /* - Run the simulation */
43
44   return 0;
45 }