Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
7ef8657abf86de28d7484e8dcb29bd3bf613a1cc
[simgrid.git] / src / smpi / internals / SmpiHost.cpp
1 /* Copyright (c) 2017-2018. The SimGrid Team. All rights reserved.          */
2
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. */
5
6 #include "SmpiHost.hpp"
7 #include "simgrid/s4u/VirtualMachine.hpp"
8 #include "smpi_utils.hpp"
9 #include "xbt/config.hpp"
10
11 #include <string>
12 #include <vector>
13 #include <xbt/log.h>
14
15 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi_host, smpi, "Logging specific to SMPI (host)");
16
17 namespace simgrid {
18 namespace smpi {
19
20 simgrid::xbt::Extension<simgrid::s4u::Host, SmpiHost> SmpiHost::EXTENSION_ID;
21
22 double SmpiHost::orecv(size_t size)
23 {
24   double current = orecv_parsed_values.empty() ? 0.0 : orecv_parsed_values.front().values[0] +
25                                                            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 const& 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 double SmpiHost::osend(size_t size)
46 {
47   double current =
48       osend_parsed_values.empty() ? 0.0 : osend_parsed_values[0].values[0] + osend_parsed_values[0].values[1] * size;
49   // Iterate over all the sections that were specified and find the right
50   // value. (fact.factor represents the interval sizes; we want to find the
51   // section that has fact.factor <= size and no other such fact.factor <= size)
52   // Note: parse_factor() (used before) already sorts the vector we iterate over!
53   for (auto const& fact : osend_parsed_values) {
54     if (size <= fact.factor) { // Values already too large, use the previously computed value of current!
55       XBT_DEBUG("os : %zu <= %zu return %.10f", size, fact.factor, current);
56       return current;
57     } else {
58       // If the next section is too large, the current section must be used.
59       // Hence, save the cost, as we might have to use it.
60       current = fact.values[0] + fact.values[1] * size;
61     }
62   }
63   XBT_DEBUG("Searching for smpi/os: %zu is larger than the largest boundary, return %.10f", size, current);
64
65   return current;
66 }
67
68 double SmpiHost::oisend(size_t size)
69 {
70   double current =
71       oisend_parsed_values.empty() ? 0.0 : oisend_parsed_values[0].values[0] + oisend_parsed_values[0].values[1] * size;
72
73   // Iterate over all the sections that were specified and find the right value. (fact.factor represents the interval
74   // sizes; we want to find the section that has fact.factor <= size and no other such fact.factor <= size)
75   // Note: parse_factor() (used before) already sorts the vector we iterate over!
76   for (auto const& fact : oisend_parsed_values) {
77     if (size <= fact.factor) { // Values already too large, use the previously  computed value of current!
78       XBT_DEBUG("ois : %zu <= %zu return %.10f", size, fact.factor, current);
79       return current;
80     } else {
81       // If the next section is too large, the current section must be used.
82       // Hence, save the cost, as we might have to use it.
83       current = fact.values[0] + fact.values[1] * size;
84     }
85   }
86   XBT_DEBUG("Searching for smpi/ois: %zu is larger than the largest boundary, return %.10f", size, current);
87
88   return current;
89 }
90
91 SmpiHost::SmpiHost(simgrid::s4u::Host *ptr) : host(ptr)
92 {
93   if (not SmpiHost::EXTENSION_ID.valid())
94     SmpiHost::EXTENSION_ID = simgrid::s4u::Host::extension_create<SmpiHost>();
95
96   const char* orecv_string = host->getProperty("smpi/or");
97   if (orecv_string != nullptr) {
98     orecv_parsed_values = parse_factor(orecv_string);
99   } else {
100     orecv_parsed_values = parse_factor(simgrid::config::get_value<std::string>("smpi/or"));
101   }
102
103   const char* osend_string = host->getProperty("smpi/os");
104   if (osend_string != nullptr) {
105     osend_parsed_values = parse_factor(osend_string);
106   } else {
107     osend_parsed_values = parse_factor(simgrid::config::get_value<std::string>("smpi/os"));
108   }
109
110   const char* oisend_string = host->getProperty("smpi/ois");
111   if (oisend_string != nullptr) {
112     oisend_parsed_values = parse_factor(oisend_string);
113   } else {
114     oisend_parsed_values = parse_factor(simgrid::config::get_value<std::string>("smpi/ois"));
115   }
116 }
117
118 SmpiHost::~SmpiHost()=default;
119 }
120 }