Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Move FactorSet from smpi::utils to kernel::resource
authorMartin Quinson <martin.quinson@ens-rennes.fr>
Sun, 23 Oct 2022 14:46:56 +0000 (16:46 +0200)
committerMartin Quinson <martin.quinson@ens-rennes.fr>
Sun, 23 Oct 2022 14:47:05 +0000 (16:47 +0200)
This fixes non-SMPI builds.

Also fix clang builds on the way (initializer_list must be given explicitly)

MANIFEST.in
src/kernel/resource/FactorSet.cpp [new file with mode: 0644]
src/kernel/resource/FactorSet.hpp [new file with mode: 0644]
src/kernel/resource/NetworkModel.cpp
src/smpi/include/smpi_host.hpp
src/smpi/include/smpi_utils.hpp
src/smpi/internals/smpi_utils.cpp
tools/cmake/DefinePackages.cmake

index af4314f..2406d6f 100644 (file)
@@ -2240,6 +2240,8 @@ include src/kernel/resource/CpuImpl.cpp
 include src/kernel/resource/CpuImpl.hpp
 include src/kernel/resource/DiskImpl.cpp
 include src/kernel/resource/DiskImpl.hpp
+include src/kernel/resource/FactorSet.cpp
+include src/kernel/resource/FactorSet.hpp
 include src/kernel/resource/LinkImpl.hpp
 include src/kernel/resource/Model.cpp
 include src/kernel/resource/NetworkModel.cpp
diff --git a/src/kernel/resource/FactorSet.cpp b/src/kernel/resource/FactorSet.cpp
new file mode 100644 (file)
index 0000000..19e9c33
--- /dev/null
@@ -0,0 +1,121 @@
+/* Copyright (c) 2016-2022. The SimGrid Team. All rights reserved.          */
+
+/* This program is free software; you can redistribute it and/or modify it
+ * under the terms of the license (GNU LGPL) which comes with this package. */
+
+#include "src/kernel/resource/FactorSet.hpp"
+#include "xbt/ex.h"
+#include "xbt/file.hpp"
+#include "xbt/log.h"
+#include "xbt/parse_units.hpp"
+#include "xbt/str.h"
+#include "xbt/sysdep.h"
+
+#include <algorithm>
+//#include <function>
+#include <boost/tokenizer.hpp>
+
+XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(ker_resource);
+
+extern std::string surf_parsed_filename;
+extern int surf_parse_lineno;
+
+namespace simgrid::kernel::resource {
+
+void FactorSet::parse(const std::string& values)
+{
+  const char* str = values.c_str();
+  initialized_    = true;
+
+  if (strchr(str, ':') == nullptr && strchr(str, ';') == nullptr) { // Single value
+    default_value_ = xbt_str_parse_double(str, name_.c_str());
+    return;
+  }
+
+  /** Setup the tokenizer that parses the string **/
+  using Tokenizer = boost::tokenizer<boost::char_separator<char>>;
+  boost::char_separator<char> sep(";");
+  boost::char_separator<char> factor_separator(":");
+  Tokenizer tokens(values, sep);
+
+  /**
+   * Iterate over patterns like A:B:C:D;E:F;G:H
+   * These will be broken down into:
+   * A --> B, C, D
+   * E --> F
+   * G --> H
+   */
+  for (auto token_iter = tokens.begin(); token_iter != tokens.end(); ++token_iter) {
+    XBT_DEBUG("token: %s", token_iter->c_str());
+    Tokenizer factor_values(*token_iter, factor_separator);
+    s_smpi_factor_t fact;
+    xbt_assert(factor_values.begin() != factor_values.end(), "Malformed radical for %s: '%s'", name_.c_str(),
+               values.c_str());
+    unsigned int iteration = 0;
+    for (auto factor_iter = factor_values.begin(); factor_iter != factor_values.end(); ++factor_iter) {
+      iteration++;
+
+      if (factor_iter == factor_values.begin()) { /* first element */
+        try {
+          fact.factor = std::stoi(*factor_iter);
+        } catch (const std::invalid_argument&) {
+          throw std::invalid_argument(std::string("Invalid factor in chunk ") + std::to_string(factors_.size() + 1) +
+                                      ": " + *factor_iter + " for " + name_);
+        }
+      } else {
+        try {
+          fact.values.push_back(xbt_parse_get_time(surf_parsed_filename, surf_parse_lineno, *factor_iter, ""));
+        } catch (const std::invalid_argument&) {
+          throw std::invalid_argument(std::string("Invalid factor value ") + std::to_string(iteration) + " in chunk " +
+                                      std::to_string(factors_.size() + 1) + ": " + *factor_iter + " for " + name_);
+        }
+      }
+    }
+
+    factors_.push_back(fact);
+    XBT_DEBUG("smpi_factor:\t%zu: %zu values, first: %f", fact.factor, factors_.size(), fact.values[0]);
+  }
+  std::sort(factors_.begin(), factors_.end(),
+            [](const s_smpi_factor_t& pa, const s_smpi_factor_t& pb) { return (pa.factor < pb.factor); });
+  for (auto const& fact : factors_) {
+    XBT_DEBUG("smpi_factor:\t%zu: %zu values, first: %f", fact.factor, factors_.size(), fact.values[0]);
+  }
+  factors_.shrink_to_fit();
+}
+
+FactorSet::FactorSet(const std::string& name, double default_value,
+                     std::function<double(std::vector<double> const&, double)> const& lambda)
+    : name_(name), default_value_(default_value), lambda_(lambda)
+{
+}
+
+double FactorSet::operator()()
+{
+  return default_value_;
+}
+
+double FactorSet::operator()(double size)
+{
+  if (factors_.empty())
+    return default_value_;
+
+  for (long unsigned i = 0; i < factors_.size(); i++) {
+    auto const& fact = factors_[i];
+
+    if (size <= fact.factor) { // Too large already, use the previous value
+
+      if (i == 0) { // Before the first boundary: use the default value
+        XBT_DEBUG("%s: %f <= %zu return default %f", name_.c_str(), size, fact.factor, default_value_);
+        return default_value_;
+      }
+      double val = lambda_(factors_[i - 1].values, size);
+      XBT_DEBUG("%s: %f <= %zu return %f", name_.c_str(), size, fact.factor, val);
+      return val;
+    }
+  }
+  double val = lambda_(factors_.back().values, size);
+
+  XBT_DEBUG("%s: %f > %zu return %f", name_.c_str(), size, factors_.back().factor, val);
+  return val;
+}
+} // namespace simgrid::kernel::resource
diff --git a/src/kernel/resource/FactorSet.hpp b/src/kernel/resource/FactorSet.hpp
new file mode 100644 (file)
index 0000000..fb90236
--- /dev/null
@@ -0,0 +1,46 @@
+/* Copyright (c) 2016-2022. The SimGrid Team. All rights reserved.          */
+
+/* This program is free software; you can redistribute it and/or modify it
+ * under the terms of the license (GNU LGPL) which comes with this package. */
+
+#ifndef RESOURCE_FACTORSET_HPP
+#define RESOURCE_FACTORSET_HPP
+#include <xbt/base.h>
+
+#include <cstddef>
+#include <functional>
+#include <string>
+#include <string_view>
+#include <vector>
+
+// Methods used to parse and store the values for timing injections in smpi
+struct s_smpi_factor_t {
+  size_t factor = 0;
+  std::vector<double> values;
+};
+
+namespace simgrid::kernel::resource {
+
+class FactorSet {
+  const std::string& name_;
+  std::vector<s_smpi_factor_t> factors_;
+  double default_value_;
+  const std::function<double(std::vector<double> const&, double)> lambda_;
+  bool initialized_ = false;
+
+public:
+  // Parse the factor from a string
+  FactorSet(
+      const std::string& name, double default_value = 1,
+      std::function<double(std::vector<double> const&, double)> const& lambda = [](std::vector<double> const& values,
+                                                                                   double) { return values.front(); });
+  void parse(const std::string& string_values);
+  bool is_initialized() const { return initialized_; }
+  // Get the default value
+  double operator()();
+  // Get the factor to use for the provided size
+  double operator()(double size);
+};
+
+} // namespace simgrid::kernel::resource
+#endif
index 0e5aa79..69dd1dc 100644 (file)
@@ -6,9 +6,9 @@
 #include <simgrid/s4u/Engine.hpp>
 
 #include "simgrid/sg_config.hpp"
+#include "src/kernel/resource/FactorSet.hpp"
 #include "src/kernel/resource/NetworkModel.hpp"
 #include "src/kernel/resource/profile/Profile.hpp"
-#include "src/smpi/include/smpi_utils.hpp"
 #include "src/surf/surf_interface.hpp"
 
 #include <numeric>
@@ -23,14 +23,14 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(res_network, ker_resource, "Network resources, t
  *********/
 
 namespace simgrid::kernel::resource {
-static smpi::utils::FactorSet cfg_latency_factor("network/latency-factor");
-static smpi::utils::FactorSet cfg_bandwidth_factor("network/bandwidth-factor");
+static FactorSet cfg_latency_factor("network/latency-factor");
+static FactorSet cfg_bandwidth_factor("network/bandwidth-factor");
 
 config::Flag<std::string> cfg_latency_factor_str(
-    "network/latency-factor", {{"smpi/lat-factor"}},
+    "network/latency-factor", std::initializer_list<const char*>{"smpi/lat-factor"},
     "Correction factor to apply to the provided latency (default value overridden by network model)", "1.0");
 static config::Flag<std::string> cfg_bandwidth_factor_str(
-    "network/bandwidth-factor", {{"smpi/bw-factor"}},
+    "network/bandwidth-factor", std::initializer_list<const char*>{"smpi/bw-factor"},
     "Correction factor to apply to the provided bandwidth (default value overridden by network model)", "1.0");
 
 double NetworkModel::get_latency_factor(double size)
index 48c7ce5..3defe11 100644 (file)
@@ -9,6 +9,7 @@
 #include "smpi_utils.hpp"
 
 #include "simgrid/s4u/Host.hpp"
+#include "src/kernel/resource/FactorSet.hpp"
 #include <string>
 #include <vector>
 #include <xbt/Extendable.hpp>
@@ -19,9 +20,9 @@ static auto factor_lambda(std::vector<double> const& values, double size)
   return values[0] + values[1] * static_cast<size_t>(size);
 }
 class Host {
-  utils::FactorSet orecv_{"smpi/or", 0.0, factor_lambda};
-  utils::FactorSet osend_{"smpi/os", 0.0, factor_lambda};
-  utils::FactorSet oisend_{"smpi/ois", 0.0, factor_lambda};
+  kernel::resource::FactorSet orecv_{"smpi/or", 0.0, factor_lambda};
+  kernel::resource::FactorSet osend_{"smpi/os", 0.0, factor_lambda};
+  kernel::resource::FactorSet oisend_{"smpi/ois", 0.0, factor_lambda};
   s4u::Host* host = nullptr;
   /**
    * @brief Generates warning message if user's config is conflicting (callback vs command line/xml)
index b5dc550..bc55751 100644 (file)
 #include <vector>
 
 // Methods used to parse and store the values for timing injections in smpi
-struct s_smpi_factor_t {
-  size_t factor = 0;
-  std::vector<double> values;
-};
 
 namespace simgrid::smpi::utils {
 
-class FactorSet {
-  const std::string& name_;
-  std::vector<s_smpi_factor_t> factors_;
-  double default_value_;
-  const std::function<double(std::vector<double> const&, double)> lambda_;
-  bool initialized_ = false;
-
-public:
-  // Parse the factor from a string
-  FactorSet(
-      const std::string& name, double default_value = 1,
-      std::function<double(std::vector<double> const&, double)> const& lambda = [](std::vector<double> const& values,
-                                                                                   double) { return values.front(); });
-  void parse(const std::string& string_values);
-  bool is_initialized() const { return initialized_; }
-  // Get the default value
-  double operator()();
-  // Get the factor to use for the provided size
-  double operator()(double size);
-};
 XBT_PUBLIC void add_benched_time(double time);
 XBT_PUBLIC void account_malloc_size(size_t size, std::string_view file, int line, const void* ptr);
 XBT_PUBLIC void account_shared_size(size_t size);
index d023d9b..16672a8 100644 (file)
@@ -49,103 +49,6 @@ std::unordered_map<const void*, alloc_metadata_t> allocs;
 
 std::unordered_map<int, std::vector<std::string>> collective_calls;
 
-void FactorSet::parse(const std::string& values)
-{
-  const char* str = values.c_str();
-  initialized_    = true;
-
-  if (strchr(str, ':') == nullptr && strchr(str, ';') == nullptr) { // Single value
-    default_value_ = xbt_str_parse_double(str, name_.c_str());
-    return;
-  }
-
-  /** Setup the tokenizer that parses the string **/
-  using Tokenizer = boost::tokenizer<boost::char_separator<char>>;
-  boost::char_separator<char> sep(";");
-  boost::char_separator<char> factor_separator(":");
-  Tokenizer tokens(values, sep);
-
-  /**
-   * Iterate over patterns like A:B:C:D;E:F;G:H
-   * These will be broken down into:
-   * A --> B, C, D
-   * E --> F
-   * G --> H
-   */
-  for (auto token_iter = tokens.begin(); token_iter != tokens.end(); ++token_iter) {
-    XBT_DEBUG("token: %s", token_iter->c_str());
-    Tokenizer factor_values(*token_iter, factor_separator);
-    s_smpi_factor_t fact;
-    xbt_assert(factor_values.begin() != factor_values.end(), "Malformed radical for %s: '%s'", name_.c_str(),
-               values.c_str());
-    unsigned int iteration = 0;
-    for (auto factor_iter = factor_values.begin(); factor_iter != factor_values.end(); ++factor_iter) {
-      iteration++;
-
-      if (factor_iter == factor_values.begin()) { /* first element */
-        try {
-          fact.factor = std::stoi(*factor_iter);
-        } catch (const std::invalid_argument&) {
-          throw std::invalid_argument(std::string("Invalid factor in chunk ") + std::to_string(factors_.size() + 1) +
-                                      ": " + *factor_iter + " for " + name_);
-        }
-      } else {
-        try {
-          fact.values.push_back(xbt_parse_get_time(surf_parsed_filename, surf_parse_lineno, *factor_iter, ""));
-        } catch (const std::invalid_argument&) {
-          throw std::invalid_argument(std::string("Invalid factor value ") + std::to_string(iteration) + " in chunk " +
-                                      std::to_string(factors_.size() + 1) + ": " + *factor_iter + " for " + name_);
-        }
-      }
-    }
-
-    factors_.push_back(fact);
-    XBT_DEBUG("smpi_factor:\t%zu: %zu values, first: %f", fact.factor, factors_.size(), fact.values[0]);
-  }
-  std::sort(factors_.begin(), factors_.end(),
-            [](const s_smpi_factor_t& pa, const s_smpi_factor_t& pb) { return (pa.factor < pb.factor); });
-  for (auto const& fact : factors_) {
-    XBT_DEBUG("smpi_factor:\t%zu: %zu values, first: %f", fact.factor, factors_.size(), fact.values[0]);
-  }
-  factors_.shrink_to_fit();
-}
-
-FactorSet::FactorSet(const std::string& name, double default_value,
-                     std::function<double(std::vector<double> const&, double)> const& lambda)
-    : name_(name), default_value_(default_value), lambda_(lambda)
-{
-}
-
-double FactorSet::operator()()
-{
-  return default_value_;
-}
-
-double FactorSet::operator()(double size)
-{
-  if (factors_.empty())
-    return default_value_;
-
-  for (long unsigned i = 0; i < factors_.size(); i++) {
-    auto const& fact = factors_[i];
-
-    if (size <= fact.factor) { // Too large already, use the previous value
-
-      if (i == 0) { // Before the first boundary: use the default value
-        XBT_DEBUG("%s: %f <= %zu return default %f", name_.c_str(), size, fact.factor, default_value_);
-        return default_value_;
-      }
-      double val = lambda_(factors_[i - 1].values, size);
-      XBT_DEBUG("%s: %f <= %zu return %f", name_.c_str(), size, fact.factor, val);
-      return val;
-    }
-  }
-  double val = lambda_(factors_.back().values, size);
-
-  XBT_DEBUG("%s: %f > %zu return %f", name_.c_str(), size, factors_.back().factor, val);
-  return val;
-}
-
 void add_benched_time(double time){
   total_benched_time += time;
 }
index f8dae81..60c15b5 100644 (file)
@@ -315,6 +315,8 @@ set(SURF_SRC
   src/kernel/resource/CpuImpl.hpp
   src/kernel/resource/DiskImpl.cpp
   src/kernel/resource/DiskImpl.hpp
+  src/kernel/resource/FactorSet.cpp
+  src/kernel/resource/FactorSet.hpp
   src/kernel/resource/Model.cpp
   src/kernel/resource/NetworkModel.cpp
   src/kernel/resource/Resource.hpp