Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
79ea6b199d7e4735dbf4e78fe1798cb4f9d60484
[simgrid.git] / src / smpi / SmpiHost.cpp
1 #include "smpi/smpi_utils.hpp"
2 #include "src/smpi/SmpiHost.hpp"
3 #include <simgrid/s4u/VirtualMachine.hpp>
4 #include <string>
5 #include <vector>
6
7 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi_host, smpi, "Logging specific to SMPI (host)");
8
9 namespace simgrid {
10 namespace smpi {
11
12 simgrid::xbt::Extension<simgrid::s4u::Host, SmpiHost> SmpiHost::EXTENSION_ID;
13
14 double SmpiHost::orecv(size_t size)
15 {
16   double current = orecv_parsed_values.empty() ? 0.0 : orecv_parsed_values.front().values[0] +
17                                                            orecv_parsed_values.front().values[1] * size;
18
19   // Iterate over all the sections that were specified and find the right value. (fact.factor represents the interval
20   // sizes; we want to find the section that has fact.factor <= size and no other such fact.factor <= size)
21   // Note: parse_factor() (used before) already sorts the vector we iterate over!
22   for (auto fact : orecv_parsed_values) {
23     if (size <= fact.factor) { // Values already too large, use the previously computed value of current!
24       XBT_DEBUG("or : %zu <= %zu return %.10f", size, fact.factor, current);
25       return current;
26     } else {
27       // If the next section is too large, the current section must be used.
28       // Hence, save the cost, as we might have to use it.
29       current=fact.values[0]+fact.values[1]*size;
30     }
31   }
32   XBT_DEBUG("smpi_or: %zu is larger than largest boundary, return %.10f", size, current);
33
34   return current;
35 }
36
37 double SmpiHost::osend(size_t size)
38 {
39   double current =
40       osend_parsed_values.empty() ? 0.0 : osend_parsed_values[0].values[0] + osend_parsed_values[0].values[1] * size;
41   // Iterate over all the sections that were specified and find the right
42   // value. (fact.factor represents the interval sizes; we want to find the
43   // section that has fact.factor <= size and no other such fact.factor <= size)
44   // Note: parse_factor() (used before) already sorts the vector we iterate over!
45   for (auto& fact : osend_parsed_values) {
46     if (size <= fact.factor) { // Values already too large, use the previously computed value of current!
47       XBT_DEBUG("os : %zu <= %zu return %.10f", size, fact.factor, current);
48       return current;
49     } else {
50       // If the next section is too large, the current section must be used.
51       // Hence, save the cost, as we might have to use it.
52       current = fact.values[0] + fact.values[1] * size;
53     }
54   }
55   XBT_DEBUG("Searching for smpi/os: %zu is larger than the largest boundary, return %.10f", size, current);
56
57   return current;
58 }
59
60 double SmpiHost::oisend(size_t size)
61 {
62   double current =
63       oisend_parsed_values.empty() ? 0.0 : oisend_parsed_values[0].values[0] + oisend_parsed_values[0].values[1] * size;
64
65   // Iterate over all the sections that were specified and find the right value. (fact.factor represents the interval
66   // sizes; we want to find the section that has fact.factor <= size and no other such fact.factor <= size)
67   // Note: parse_factor() (used before) already sorts the vector we iterate over!
68   for (auto& fact : oisend_parsed_values) {
69     if (size <= fact.factor) { // Values already too large, use the previously  computed value of current!
70       XBT_DEBUG("ois : %zu <= %zu return %.10f", size, fact.factor, current);
71       return current;
72     } else {
73       // If the next section is too large, the current section must be used.
74       // Hence, save the cost, as we might have to use it.
75       current = fact.values[0] + fact.values[1] * size;
76     }
77   }
78   XBT_DEBUG("Searching for smpi/ois: %zu is larger than the largest boundary, return %.10f", size, current);
79
80   return current;
81 }
82
83 SmpiHost::SmpiHost(simgrid::s4u::Host *ptr) : host(ptr)
84 {
85   if (!SmpiHost::EXTENSION_ID.valid())
86     SmpiHost::EXTENSION_ID = simgrid::s4u::Host::extension_create<SmpiHost>();
87
88   const char* orecv_string = host->property("smpi/or");
89   if (orecv_string != nullptr) {
90     orecv_parsed_values = parse_factor(orecv_string);
91   } else {
92     orecv_parsed_values = parse_factor(xbt_cfg_get_string("smpi/or"));
93   }
94
95   const char* osend_string = host->property("smpi/os");
96   if (osend_string != nullptr) {
97     osend_parsed_values = parse_factor(osend_string);
98   } else {
99     osend_parsed_values = parse_factor(xbt_cfg_get_string("smpi/os"));
100   }
101
102   const char* oisend_string = host->property("smpi/ois");
103   if (oisend_string != nullptr) {
104     oisend_parsed_values = parse_factor(oisend_string);
105   } else {
106     oisend_parsed_values = parse_factor(xbt_cfg_get_string("smpi/ois"));
107   }
108 }
109
110 SmpiHost::~SmpiHost()=default;
111
112 static void onCreation(simgrid::s4u::Host& host)
113 {
114 }
115
116 static void onHostDestruction(simgrid::s4u::Host& host)
117 {
118   // Ignore virtual machines
119   if (dynamic_cast<simgrid::s4u::VirtualMachine*>(&host))
120     return;
121 }
122
123 void sg_smpi_host_init()
124 {
125   simgrid::s4u::Host::onCreation.connect(&onCreation);
126   simgrid::s4u::Host::onDestruction.connect(&onHostDestruction);
127 }
128
129 }
130 }