s4u::Link::on_bandwidth_change_cb([](s4u::Link const& link) {
Container::by_name(link.get_name())
->get_variable("bandwidth")
- ->set_event(simgrid_get_clock(), kernel::resource::NetworkModel::cfg_bandwidth_factor * link.get_bandwidth());
+ ->set_event(
+ simgrid_get_clock(),
+ static_cast<kernel::resource::NetworkModel*>(link.get_impl()->get_model())->get_bandwidth_factor() *
+ link.get_bandwidth());
});
s4u::NetZone::on_seal_cb([](s4u::NetZone const& /*netzone*/) { currentContainer.pop_back(); });
kernel::routing::NetPoint::on_creation.connect([](kernel::routing::NetPoint const& netpoint) {
#include "simgrid/sg_config.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>
*********/
namespace simgrid::kernel::resource {
-double NetworkModel::cfg_latency_factor = 1.0; // default value
-double NetworkModel::cfg_bandwidth_factor = 1.0; // default value
+static smpi::utils::FactorSet cfg_latency_factor("network/latency-factor");
+static smpi::utils::FactorSet cfg_bandwidth_factor("network/bandwidth-factor");
-static config::Flag<std::string> cfg_latency_factor_str(
+config::Flag<std::string> cfg_latency_factor_str(
"network/latency-factor",
- "Correction factor to apply to the provided latency (default value overridden by network model)", "1.0",
- [](std::string str) {
- NetworkModel::cfg_latency_factor =
- xbt_str_parse_double(str.c_str(), "The value of 'network/latency-factor' is not a double");
- });
+ "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",
- "Correction factor to apply to the provided bandwidth (default value overridden by network model)", "1.0",
- [](std::string str) {
- NetworkModel::cfg_bandwidth_factor =
- xbt_str_parse_double(str.c_str(), "The value of 'network/bandwidth-factor' is not a double");
- });
+ "Correction factor to apply to the provided bandwidth (default value overridden by network model)", "1.0");
+
+double NetworkModel::get_latency_factor(double size)
+{
+ if (not cfg_latency_factor.is_initialized()) // lazy initiaization to avoid initialization fiasco
+ cfg_latency_factor.parse(cfg_latency_factor_str.get());
+
+ return cfg_latency_factor(size);
+}
+double NetworkModel::get_bandwidth_factor(double size)
+{
+ if (not cfg_bandwidth_factor.is_initialized())
+ cfg_bandwidth_factor.parse(cfg_bandwidth_factor_str.get());
+
+ return cfg_bandwidth_factor(size);
+}
/** @brief Command-line option 'network/TCP-gamma' -- see @ref options_model_network_gamma */
config::Flag<double> NetworkModel::cfg_tcp_gamma(
public:
static config::Flag<double> cfg_tcp_gamma;
static config::Flag<bool> cfg_crosstraffic;
- static double cfg_latency_factor;
- static double cfg_bandwidth_factor;
static config::Flag<double> cfg_weight_S_parameter;
using Model::Model;
* @param size The size of the message.
* @return The latency factor.
*/
- virtual double get_latency_factor(double /* size */) { return cfg_latency_factor; }
+ virtual double get_latency_factor(double size = 0);
/**
* @brief Get the right multiplicative factor for the bandwidth.
* @param size The size of the message.
* @return The bandwidth factor.
*/
- virtual double get_bandwidth_factor(double /* size*/) { return cfg_bandwidth_factor; }
+ virtual double get_bandwidth_factor(double size = 0);
double next_occurring_event_full(double now) override;
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& values);
+ void parse(const std::string& string_values);
bool is_initialized() const { return initialized_; }
// Get the default value
double operator()();
-/* Copyright (c) 2016-2022. The SimGrid Team.
- * All rights reserved. */
+/* 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 "private.hpp"
#include "smpi_config.hpp"
#include "src/surf/xml/platf.hpp"
+#include "xbt/ex.h"
#include "xbt/file.hpp"
#include "xbt/log.h"
-#include "xbt/ex.h"
#include "xbt/parse_units.hpp"
+#include "xbt/str.h"
#include "xbt/sysdep.h"
#include <algorithm>
#include <boost/tokenizer.hpp>
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(";");
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 smpi factor: '%s'", values.c_str());
+ 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++;
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);
+ ": " + *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);
+ std::to_string(factors_.size() + 1) + ": " + *factor_iter + " for " + name_);
}
}
}
XBT_DEBUG("smpi_factor:\t%zu: %zu values, first: %f", fact.factor, factors_.size(), fact.values[0]);
}
factors_.shrink_to_fit();
-
- initialized_ = true;
}
FactorSet::FactorSet(const std::string& name, double default_value,
action.latency_ = 0.0;
}
}
- action.update_remains(action.get_cost() * delta / cfg_latency_factor);
+ action.update_remains(action.get_cost() * delta / get_latency_factor());
action.update_max_duration(delta);
if ((action.get_remains_no_update() <= 0) ||
NetworkConstantAction::NetworkConstantAction(NetworkConstantModel* model_, s4u::Host& src, s4u::Host& dst, double size)
: NetworkAction(model_, src, dst, size, false)
{
- latency_ = NetworkModel::cfg_latency_factor;
+ latency_ = model_->get_latency_factor();
if (latency_ <= 0.0)
set_state(Action::State::FINISHED);
}
double res = strtod(str, &endptr);
if (endptr[0] != '\0')
- throw std::invalid_argument(simgrid::xbt::string_printf("%s: %s", error_msg, str));
+ throw std::invalid_argument(simgrid::xbt::string_printf("%s: %s (parse error at '%s')", error_msg, str, endptr));
return res;
}