1 /* Copyright (c) 2017. The SimGrid Team. All rights reserved. */
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. */
6 #include "src/smpi/SmpiHost.hpp"
7 #include "simgrid/s4u/VirtualMachine.hpp"
8 #include "smpi/smpi_utils.hpp"
13 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi_host, smpi, "Logging specific to SMPI (host)");
18 simgrid::xbt::Extension<simgrid::s4u::Host, SmpiHost> SmpiHost::EXTENSION_ID;
20 double SmpiHost::orecv(size_t size)
22 double current = orecv_parsed_values.empty() ? 0.0 : orecv_parsed_values.front().values[0] +
23 orecv_parsed_values.front().values[1] * size;
25 // Iterate over all the sections that were specified and find the right value. (fact.factor represents the interval
26 // sizes; we want to find the section that has fact.factor <= size and no other such fact.factor <= size)
27 // Note: parse_factor() (used before) already sorts the vector we iterate over!
28 for (auto fact : orecv_parsed_values) {
29 if (size <= fact.factor) { // Values already too large, use the previously computed value of current!
30 XBT_DEBUG("or : %zu <= %zu return %.10f", size, fact.factor, current);
33 // If the next section is too large, the current section must be used.
34 // Hence, save the cost, as we might have to use it.
35 current=fact.values[0]+fact.values[1]*size;
38 XBT_DEBUG("smpi_or: %zu is larger than largest boundary, return %.10f", size, current);
43 double SmpiHost::osend(size_t size)
46 osend_parsed_values.empty() ? 0.0 : osend_parsed_values[0].values[0] + osend_parsed_values[0].values[1] * size;
47 // Iterate over all the sections that were specified and find the right
48 // value. (fact.factor represents the interval sizes; we want to find the
49 // section that has fact.factor <= size and no other such fact.factor <= size)
50 // Note: parse_factor() (used before) already sorts the vector we iterate over!
51 for (auto& fact : osend_parsed_values) {
52 if (size <= fact.factor) { // Values already too large, use the previously computed value of current!
53 XBT_DEBUG("os : %zu <= %zu return %.10f", size, fact.factor, current);
56 // If the next section is too large, the current section must be used.
57 // Hence, save the cost, as we might have to use it.
58 current = fact.values[0] + fact.values[1] * size;
61 XBT_DEBUG("Searching for smpi/os: %zu is larger than the largest boundary, return %.10f", size, current);
66 double SmpiHost::oisend(size_t size)
69 oisend_parsed_values.empty() ? 0.0 : oisend_parsed_values[0].values[0] + oisend_parsed_values[0].values[1] * size;
71 // Iterate over all the sections that were specified and find the right value. (fact.factor represents the interval
72 // sizes; we want to find the section that has fact.factor <= size and no other such fact.factor <= size)
73 // Note: parse_factor() (used before) already sorts the vector we iterate over!
74 for (auto& fact : oisend_parsed_values) {
75 if (size <= fact.factor) { // Values already too large, use the previously computed value of current!
76 XBT_DEBUG("ois : %zu <= %zu return %.10f", size, fact.factor, current);
79 // If the next section is too large, the current section must be used.
80 // Hence, save the cost, as we might have to use it.
81 current = fact.values[0] + fact.values[1] * size;
84 XBT_DEBUG("Searching for smpi/ois: %zu is larger than the largest boundary, return %.10f", size, current);
89 SmpiHost::SmpiHost(simgrid::s4u::Host *ptr) : host(ptr)
91 if (not SmpiHost::EXTENSION_ID.valid())
92 SmpiHost::EXTENSION_ID = simgrid::s4u::Host::extension_create<SmpiHost>();
94 const char* orecv_string = host->property("smpi/or");
95 if (orecv_string != nullptr) {
96 orecv_parsed_values = parse_factor(orecv_string);
98 orecv_parsed_values = parse_factor(xbt_cfg_get_string("smpi/or"));
101 const char* osend_string = host->property("smpi/os");
102 if (osend_string != nullptr) {
103 osend_parsed_values = parse_factor(osend_string);
105 osend_parsed_values = parse_factor(xbt_cfg_get_string("smpi/os"));
108 const char* oisend_string = host->property("smpi/ois");
109 if (oisend_string != nullptr) {
110 oisend_parsed_values = parse_factor(oisend_string);
112 oisend_parsed_values = parse_factor(xbt_cfg_get_string("smpi/ois"));
116 SmpiHost::~SmpiHost()=default;
118 static void onCreation(simgrid::s4u::Host& host)
122 static void onHostDestruction(simgrid::s4u::Host& host)
124 // Ignore virtual machines
125 if (dynamic_cast<simgrid::s4u::VirtualMachine*>(&host))
129 void sg_smpi_host_init()
131 simgrid::s4u::Host::onCreation.connect(&onCreation);
132 simgrid::s4u::Host::onDestruction.connect(&onHostDestruction);