1 #include "smpi/smpi_utils.hpp"
2 #include "src/smpi/SmpiHost.hpp"
3 #include <simgrid/s4u/VirtualMachine.hpp>
7 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi_host, smpi, "Logging specific to SMPI (host)");
12 simgrid::xbt::Extension<simgrid::s4u::Host, SmpiHost> SmpiHost::EXTENSION_ID;
14 double SmpiHost::orecv(size_t size)
16 double current = orecv_parsed_values.empty() ? 0.0 : orecv_parsed_values.front().values[0] +
17 orecv_parsed_values.front().values[1] * size;
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);
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;
32 XBT_DEBUG("smpi_or: %zu is larger than largest boundary, return %.10f", size, current);
37 double SmpiHost::osend(size_t size)
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);
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;
55 XBT_DEBUG("Searching for smpi/os: %zu is larger than the largest boundary, return %.10f", size, current);
60 double SmpiHost::oisend(size_t size)
63 oisend_parsed_values.empty() ? 0.0 : oisend_parsed_values[0].values[0] + oisend_parsed_values[0].values[1] * size;
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);
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;
78 XBT_DEBUG("Searching for smpi/ois: %zu is larger than the largest boundary, return %.10f", size, current);
83 SmpiHost::SmpiHost(simgrid::s4u::Host *ptr) : host(ptr)
85 if (!SmpiHost::EXTENSION_ID.valid())
86 SmpiHost::EXTENSION_ID = simgrid::s4u::Host::extension_create<SmpiHost>();
88 const char* orecv_string = host->property("smpi/or");
89 if (orecv_string != nullptr) {
90 orecv_parsed_values = parse_factor(orecv_string);
92 orecv_parsed_values = parse_factor(xbt_cfg_get_string("smpi/or"));
95 const char* osend_string = host->property("smpi/os");
96 if (osend_string != nullptr) {
97 osend_parsed_values = parse_factor(osend_string);
99 osend_parsed_values = parse_factor(xbt_cfg_get_string("smpi/os"));
102 const char* oisend_string = host->property("smpi/ois");
103 if (oisend_string != nullptr) {
104 oisend_parsed_values = parse_factor(oisend_string);
106 oisend_parsed_values = parse_factor(xbt_cfg_get_string("smpi/ois"));
110 SmpiHost::~SmpiHost()=default;
112 static void onCreation(simgrid::s4u::Host& host)
116 static void onHostDestruction(simgrid::s4u::Host& host)
118 // Ignore virtual machines
119 if (dynamic_cast<simgrid::s4u::VirtualMachine*>(&host))
123 void sg_smpi_host_init()
125 simgrid::s4u::Host::onCreation.connect(&onCreation);
126 simgrid::s4u::Host::onDestruction.connect(&onHostDestruction);