Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Update copyright lines for 2022.
[simgrid.git] / teshsuite / s4u / basic-parsing-test / basic-parsing-test.cpp
1 /* Copyright (c) 2008-2022. 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 <stdio.h>
8 #include <simgrid/s4u.hpp>
9
10 XBT_LOG_NEW_DEFAULT_CATEGORY(basic_parsing_test, "[usage] basic-parsing-test <platform-file>");
11
12 namespace sg4 = simgrid::s4u;
13
14 static void test_one_link(const std::vector<sg4::Host*>& hosts)
15 {
16   const sg4::Host* h1 = hosts[0];
17   const sg4::Host* h2 = hosts[1];
18   std::vector<sg4::Link*> route;
19   double latency = 0;
20   double min_bandwidth = -1;
21
22   XBT_INFO("Route between %s and %s", h1->get_cname(), h2->get_cname());
23   h1->route_to(h2, route, &latency);
24   XBT_INFO("Route size %zu", route.size());
25
26   for (auto link: route) {
27     double bandwidth = link->get_bandwidth();
28     XBT_INFO("  Link %s: latency = %f, bandwidth = %f", link->get_cname(), link->get_latency(), bandwidth);
29     if (bandwidth < min_bandwidth || min_bandwidth < 0.0)
30       min_bandwidth = bandwidth;
31   }
32   XBT_INFO("Route latency = %f, route bandwidth = %f", latency, min_bandwidth);
33 }
34
35 static void test_full_link(const std::vector<sg4::Host*>& hosts)
36 {
37   size_t list_size = hosts.size();
38   for (size_t i = 0; i < list_size; i++) {
39     const sg4::Host* h1 = hosts[i];
40     for (size_t j = 0; j < list_size; j++) {
41       const sg4::Host* h2 = hosts[j];
42       XBT_INFO("Route between %s and %s", h1->get_cname(), h2->get_cname());
43       std::vector<sg4::Link*> route;
44       double latency = 0;
45       double min_bandwidth = -1;
46       h1->route_to(h2, route, &latency);
47       XBT_INFO("  Route size %zu", route.size());
48
49       for (auto link: route) {
50         double bandwidth = link->get_bandwidth();
51         XBT_INFO("  Link %s: latency = %f, bandwidth = %f", link->get_cname(), link->get_latency(), bandwidth);
52         if (bandwidth < min_bandwidth || min_bandwidth < 0.0)
53           min_bandwidth = bandwidth;
54       }
55       XBT_INFO("  Route latency = %f, route bandwidth = %f", latency, min_bandwidth);
56     }
57   }
58 }
59
60 int main(int argc, char** argv)
61 {
62   sg4::Engine e(&argc, argv);
63
64   /* creation of the environment */
65   e.load_platform(argv[1]);
66   e.seal_platform();
67   XBT_INFO("Workstation number: %zu, link number: %zu", e.get_host_count(), e.get_link_count());
68
69   std::vector<sg4::Host*> hosts = e.get_all_hosts();
70   if (argc >= 3) {
71     if (strcmp(argv[2], "ONE_LINK") == 0)
72       test_one_link(hosts);
73     if (strcmp(argv[2], "FULL_LINK") == 0)
74       test_full_link(hosts);
75     if (strcmp(argv[2], "PROP") == 0)
76       XBT_INFO("SG_TEST_mem: %s", e.host_by_name("host1")->get_property("SG_TEST_mem"));
77   }
78
79   return 0;
80 }