Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
962ea77cb66a70bfd61bba2f2d11fb3c37220a27
[simgrid.git] / src / smpi / SmpiHost.cpp
1 #include "smpi/smpi_utils.hpp"
2 #include "src/smpi/SmpiHost.hpp"
3 #include "src/surf/virtual_machine.hpp"
4
5 #include <string>
6 #include <vector>
7
8 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi_host, smpi, "Logging specific to SMPI (host)");
9
10 namespace simgrid {
11 namespace smpi {
12
13 simgrid::xbt::Extension<simgrid::s4u::Host, SmpiHost> SmpiHost::EXTENSION_ID;
14
15 double SmpiHost::orecv(size_t size)
16 {
17   if (orecv_parsed_values.empty()) {
18     if (orecv_.empty())  {
19       std::string test = xbt_cfg_get_string("smpi/or");
20       orecv_parsed_values = parse_factor(xbt_cfg_get_string("smpi/or"));
21     }
22     else 
23       orecv_parsed_values = parse_factor(orecv_.c_str());
24   }
25   
26   double current=orecv_parsed_values.empty()?0.0:orecv_parsed_values.front().values[0]+orecv_parsed_values.front().values[1]*size;
27   
28   // Iterate over all the sections that were specified and find the right value. (fact.factor represents the interval
29   // sizes; we want to find the section that has fact.factor <= size and no other such fact.factor <= size)
30   // Note: parse_factor() (used before) already sorts the vector we iterate over!
31   for (auto fact : orecv_parsed_values) {
32     if (size <= fact.factor) { // Values already too large, use the previously computed value of current!
33       XBT_DEBUG("or : %zu <= %zu return %.10f", size, fact.factor, current);
34       return current;
35     } else {
36       // If the next section is too large, the current section must be used.
37       // Hence, save the cost, as we might have to use it.
38       current=fact.values[0]+fact.values[1]*size;
39     }
40   }
41   XBT_DEBUG("smpi_or: %zu is larger than largest boundary, return %.10f", size, current);
42
43   return current;
44 }
45
46 SmpiHost::SmpiHost(simgrid::s4u::Host *ptr) : host(ptr)
47 {
48   if (!SmpiHost::EXTENSION_ID.valid())
49     SmpiHost::EXTENSION_ID = simgrid::s4u::Host::extension_create<SmpiHost>();
50
51  // if (host->properties() != nullptr) {
52  //   char* off_power_str = (char*)xbt_dict_get_or_null(host->properties(), "watt_off");
53  //   if (off_power_str != nullptr) {
54  //     char *msg = bprintf("Invalid value for property watt_off of host %s: %%s",host->name().c_str());
55  //     watts_off = xbt_str_parse_double(off_power_str, msg);
56  //     xbt_free(msg);
57  //   }
58  //   else
59  //     watts_off = 0;
60  // }
61 }
62
63 SmpiHost::~SmpiHost()=default;
64
65 static void onCreation(simgrid::s4u::Host& host) {
66 }
67
68 static void onHostDestruction(simgrid::s4u::Host& host) {
69   // Ignore virtual machines
70   simgrid::surf::HostImpl* surf_host = host.extension<simgrid::surf::HostImpl>();
71   if (dynamic_cast<simgrid::surf::VirtualMachine*>(surf_host))
72     return;
73 }
74
75 void sg_smpi_host_init()
76 {
77   simgrid::s4u::Host::onCreation.connect(&onCreation);
78   simgrid::s4u::Host::onDestruction.connect(&onHostDestruction);
79 }
80
81 }
82 }