Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[SMPI] Added SmpiHost.cpp and .hpp
authorChristian Heinrich <franz-christian.heinrich@inria.fr>
Fri, 6 Jan 2017 13:31:08 +0000 (14:31 +0100)
committerChristian Heinrich <franz-christian.heinrich@inria.fr>
Wed, 12 Apr 2017 09:53:18 +0000 (11:53 +0200)
The SmpiHost is not yet fully implemented but is
the first step towards a more configurable SMPI.

src/smpi/SmpiHost.cpp [new file with mode: 0644]
src/smpi/SmpiHost.hpp [new file with mode: 0644]
tools/cmake/DefinePackages.cmake

diff --git a/src/smpi/SmpiHost.cpp b/src/smpi/SmpiHost.cpp
new file mode 100644 (file)
index 0000000..962ea77
--- /dev/null
@@ -0,0 +1,82 @@
+#include "smpi/smpi_utils.hpp"
+#include "src/smpi/SmpiHost.hpp"
+#include "src/surf/virtual_machine.hpp"
+
+#include <string>
+#include <vector>
+
+XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi_host, smpi, "Logging specific to SMPI (host)");
+
+namespace simgrid {
+namespace smpi {
+
+simgrid::xbt::Extension<simgrid::s4u::Host, SmpiHost> SmpiHost::EXTENSION_ID;
+
+double SmpiHost::orecv(size_t size)
+{
+  if (orecv_parsed_values.empty()) {
+    if (orecv_.empty())  {
+      std::string test = xbt_cfg_get_string("smpi/or");
+      orecv_parsed_values = parse_factor(xbt_cfg_get_string("smpi/or"));
+    }
+    else 
+      orecv_parsed_values = parse_factor(orecv_.c_str());
+  }
+  
+  double current=orecv_parsed_values.empty()?0.0:orecv_parsed_values.front().values[0]+orecv_parsed_values.front().values[1]*size;
+  
+  // Iterate over all the sections that were specified and find the right value. (fact.factor represents the interval
+  // sizes; we want to find the section that has fact.factor <= size and no other such fact.factor <= size)
+  // Note: parse_factor() (used before) already sorts the vector we iterate over!
+  for (auto fact : orecv_parsed_values) {
+    if (size <= fact.factor) { // Values already too large, use the previously computed value of current!
+      XBT_DEBUG("or : %zu <= %zu return %.10f", size, fact.factor, current);
+      return current;
+    } else {
+      // If the next section is too large, the current section must be used.
+      // Hence, save the cost, as we might have to use it.
+      current=fact.values[0]+fact.values[1]*size;
+    }
+  }
+  XBT_DEBUG("smpi_or: %zu is larger than largest boundary, return %.10f", size, current);
+
+  return current;
+}
+
+SmpiHost::SmpiHost(simgrid::s4u::Host *ptr) : host(ptr)
+{
+  if (!SmpiHost::EXTENSION_ID.valid())
+    SmpiHost::EXTENSION_ID = simgrid::s4u::Host::extension_create<SmpiHost>();
+
+ // if (host->properties() != nullptr) {
+ //   char* off_power_str = (char*)xbt_dict_get_or_null(host->properties(), "watt_off");
+ //   if (off_power_str != nullptr) {
+ //     char *msg = bprintf("Invalid value for property watt_off of host %s: %%s",host->name().c_str());
+ //     watts_off = xbt_str_parse_double(off_power_str, msg);
+ //     xbt_free(msg);
+ //   }
+ //   else
+ //     watts_off = 0;
+ // }
+}
+
+SmpiHost::~SmpiHost()=default;
+
+static void onCreation(simgrid::s4u::Host& host) {
+}
+
+static void onHostDestruction(simgrid::s4u::Host& host) {
+  // Ignore virtual machines
+  simgrid::surf::HostImpl* surf_host = host.extension<simgrid::surf::HostImpl>();
+  if (dynamic_cast<simgrid::surf::VirtualMachine*>(surf_host))
+    return;
+}
+
+void sg_smpi_host_init()
+{
+  simgrid::s4u::Host::onCreation.connect(&onCreation);
+  simgrid::s4u::Host::onDestruction.connect(&onHostDestruction);
+}
+
+}
+}
diff --git a/src/smpi/SmpiHost.hpp b/src/smpi/SmpiHost.hpp
new file mode 100644 (file)
index 0000000..1d6daa5
--- /dev/null
@@ -0,0 +1,42 @@
+#ifndef SMPI_HOST_HPP_
+#define SMPI_HOST_HPP_
+
+#include "src/include/smpi/smpi_utils.hpp"
+
+#include <simgrid/s4u/host.hpp>
+#include <string>
+#include <vector>
+#include <xbt/Extendable.hpp>
+
+
+
+namespace simgrid {
+namespace smpi {
+
+void sg_smpi_host_init();
+static void onHostDestruction(simgrid::s4u::Host& host);
+static void onCreation(simgrid::s4u::Host& host);
+
+class SmpiHost {
+
+  private:
+  std::vector<s_smpi_factor_t> orecv_parsed_values;
+  simgrid::s4u::Host *host = nullptr;
+
+  public:
+  static simgrid::xbt::Extension<simgrid::s4u::Host, SmpiHost> EXTENSION_ID;
+
+  explicit SmpiHost(simgrid::s4u::Host *ptr);
+  ~SmpiHost();
+
+  double wtime;
+  double osend;
+  double oisend;
+  std::string orecv_;
+  double orecv(size_t size);
+
+};
+
+}
+}
+#endif
index 7da60c6..e2e680a 100644 (file)
@@ -220,6 +220,8 @@ set(SMPI_SRC
   src/smpi/smpi_f2c.hpp
   src/smpi/smpi_group.cpp
   src/smpi/smpi_group.hpp
+  src/smpi/SmpiHost.cpp
+  src/smpi/SmpiHost.hpp
   src/smpi/smpi_mpi.cpp
   src/smpi/smpi_datatype.cpp
   src/smpi/smpi_datatype.hpp