Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
finish removing simix.h from C files, and avoid the use of Ptr when not needed
[simgrid.git] / src / smpi / SmpiHost.cpp
1 /* Copyright (c) 2017. 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 "src/smpi/SmpiHost.hpp"
7 #include "simgrid/s4u/VirtualMachine.hpp"
8 #include "smpi/smpi_utils.hpp"
9
10 #include <string>
11 #include <vector>
12
13 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi_host, smpi, "Logging specific to SMPI (host)");
14
15 namespace simgrid {
16 namespace smpi {
17
18 simgrid::xbt::Extension<simgrid::s4u::Host, SmpiHost> SmpiHost::EXTENSION_ID;
19
20 double SmpiHost::orecv(size_t size)
21 {
22   double current = orecv_parsed_values.empty() ? 0.0 : orecv_parsed_values.front().values[0] +
23                                                            orecv_parsed_values.front().values[1] * size;
24
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);
31       return current;
32     } else {
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;
36     }
37   }
38   XBT_DEBUG("smpi_or: %zu is larger than largest boundary, return %.10f", size, current);
39
40   return current;
41 }
42
43 double SmpiHost::osend(size_t size)
44 {
45   double current =
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);
54       return current;
55     } else {
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;
59     }
60   }
61   XBT_DEBUG("Searching for smpi/os: %zu is larger than the largest boundary, return %.10f", size, current);
62
63   return current;
64 }
65
66 double SmpiHost::oisend(size_t size)
67 {
68   double current =
69       oisend_parsed_values.empty() ? 0.0 : oisend_parsed_values[0].values[0] + oisend_parsed_values[0].values[1] * size;
70
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);
77       return current;
78     } else {
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;
82     }
83   }
84   XBT_DEBUG("Searching for smpi/ois: %zu is larger than the largest boundary, return %.10f", size, current);
85
86   return current;
87 }
88
89 SmpiHost::SmpiHost(simgrid::s4u::Host *ptr) : host(ptr)
90 {
91   if (not SmpiHost::EXTENSION_ID.valid())
92     SmpiHost::EXTENSION_ID = simgrid::s4u::Host::extension_create<SmpiHost>();
93
94   const char* orecv_string = host->property("smpi/or");
95   if (orecv_string != nullptr) {
96     orecv_parsed_values = parse_factor(orecv_string);
97   } else {
98     orecv_parsed_values = parse_factor(xbt_cfg_get_string("smpi/or"));
99   }
100
101   const char* osend_string = host->property("smpi/os");
102   if (osend_string != nullptr) {
103     osend_parsed_values = parse_factor(osend_string);
104   } else {
105     osend_parsed_values = parse_factor(xbt_cfg_get_string("smpi/os"));
106   }
107
108   const char* oisend_string = host->property("smpi/ois");
109   if (oisend_string != nullptr) {
110     oisend_parsed_values = parse_factor(oisend_string);
111   } else {
112     oisend_parsed_values = parse_factor(xbt_cfg_get_string("smpi/ois"));
113   }
114 }
115
116 SmpiHost::~SmpiHost()=default;
117
118 static void onCreation(simgrid::s4u::Host& host)
119 {
120 }
121
122 static void onHostDestruction(simgrid::s4u::Host& host)
123 {
124   // Ignore virtual machines
125   if (dynamic_cast<simgrid::s4u::VirtualMachine*>(&host))
126     return;
127 }
128
129 void sg_smpi_host_init()
130 {
131   simgrid::s4u::Host::onCreation.connect(&onCreation);
132   simgrid::s4u::Host::onDestruction.connect(&onHostDestruction);
133 }
134
135 }
136 }