Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[SMPI] Use SmpiHost::orecv().
[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   if (orecv_parsed_values.empty()) {
17     if (orecv_.empty())  { /* This is currently always true since orecv_ is not really used yet. */
18       /* Get global value */
19       orecv_parsed_values = parse_factor(xbt_cfg_get_string("smpi/or"));
20     }
21     else /* Can currently not be reached, see above */
22       orecv_parsed_values = parse_factor(orecv_.c_str());
23   }
24   
25   double current=orecv_parsed_values.empty()?0.0:orecv_parsed_values.front().values[0]+orecv_parsed_values.front().values[1]*size;
26   
27   // Iterate over all the sections that were specified and find the right value. (fact.factor represents the interval
28   // sizes; we want to find the section that has fact.factor <= size and no other such fact.factor <= size)
29   // Note: parse_factor() (used before) already sorts the vector we iterate over!
30   for (auto fact : orecv_parsed_values) {
31     if (size <= fact.factor) { // Values already too large, use the previously computed value of current!
32       XBT_DEBUG("or : %zu <= %zu return %.10f", size, fact.factor, current);
33       return current;
34     } else {
35       // If the next section is too large, the current section must be used.
36       // Hence, save the cost, as we might have to use it.
37       current=fact.values[0]+fact.values[1]*size;
38     }
39   }
40   XBT_DEBUG("smpi_or: %zu is larger than largest boundary, return %.10f", size, current);
41
42   return current;
43 }
44
45 SmpiHost::SmpiHost(simgrid::s4u::Host *ptr) : host(ptr)
46 {
47   if (!SmpiHost::EXTENSION_ID.valid())
48     SmpiHost::EXTENSION_ID = simgrid::s4u::Host::extension_create<SmpiHost>();
49
50  // if (host->properties() != nullptr) {
51  //   char* off_power_str = (char*)xbt_dict_get_or_null(host->properties(), "watt_off");
52  //   if (off_power_str != nullptr) {
53  //     char *msg = bprintf("Invalid value for property watt_off of host %s: %%s",host->name().c_str());
54  //     watts_off = xbt_str_parse_double(off_power_str, msg);
55  //     xbt_free(msg);
56  //   }
57  //   else
58  //     watts_off = 0;
59  // }
60 }
61
62 SmpiHost::~SmpiHost()=default;
63
64 static void onCreation(simgrid::s4u::Host& host) {
65 }
66
67 static void onHostDestruction(simgrid::s4u::Host& host) {
68   // Ignore virtual machines
69   if (dynamic_cast<simgrid::s4u::VirtualMachine*>(&host))
70     return;
71 }
72
73 void sg_smpi_host_init()
74 {
75   simgrid::s4u::Host::onCreation.connect(&onCreation);
76   simgrid::s4u::Host::onDestruction.connect(&onHostDestruction);
77 }
78
79 }
80 }