X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/29e4e9ad0ffd06f3c3e9a17a4622aae3e31e5e8d..268288cd8cf7b502e05e2a2bcbbdb0122c91de0b:/src/smpi/internals/smpi_utils.cpp diff --git a/src/smpi/internals/smpi_utils.cpp b/src/smpi/internals/smpi_utils.cpp index 8ccf2db3d5..d8c1a34c4e 100644 --- a/src/smpi/internals/smpi_utils.cpp +++ b/src/smpi/internals/smpi_utils.cpp @@ -51,55 +51,11 @@ std::unordered_map> collective_calls; void FactorSet::parse(const std::string& values) { - factors_ = parse_factor(values); - initialized_ = true; -} - -FactorSet::FactorSet(const std::string& name, double default_value, - std::function 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; -} - -std::vector parse_factor(const std::string& smpi_coef_string) -{ - std::vector smpi_factor; - /** Setup the tokenizer that parses the string **/ using Tokenizer = boost::tokenizer>; boost::char_separator sep(";"); boost::char_separator factor_separator(":"); - Tokenizer tokens(smpi_coef_string, sep); + Tokenizer tokens(values, sep); /** * Iterate over patterns like A:B:C:D;E:F;G:H @@ -112,8 +68,7 @@ std::vector parse_factor(const std::string& smpi_coef_string) 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'", - smpi_coef_string.c_str()); + xbt_assert(factor_values.begin() != factor_values.end(), "Malformed radical for smpi factor: '%s'", values.c_str()); unsigned int iteration = 0; for (auto factor_iter = factor_values.begin(); factor_iter != factor_values.end(); ++factor_iter) { iteration++; @@ -122,7 +77,7 @@ std::vector parse_factor(const std::string& smpi_coef_string) 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(smpi_factor.size() + 1) + + throw std::invalid_argument(std::string("Invalid factor in chunk ") + std::to_string(factors_.size() + 1) + ": " + *factor_iter); } } else { @@ -130,23 +85,58 @@ std::vector parse_factor(const std::string& smpi_coef_string) 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(smpi_factor.size() + 1) + ": " + *factor_iter); + std::to_string(factors_.size() + 1) + ": " + *factor_iter); } } } - smpi_factor.push_back(fact); - XBT_DEBUG("smpi_factor:\t%zu: %zu values, first: %f", fact.factor, smpi_factor.size(), fact.values[0]); + factors_.push_back(fact); + XBT_DEBUG("smpi_factor:\t%zu: %zu values, first: %f", fact.factor, factors_.size(), fact.values[0]); } - std::sort(smpi_factor.begin(), smpi_factor.end(), [](const s_smpi_factor_t &pa, const s_smpi_factor_t &pb) { - return (pa.factor < pb.factor); - }); - for (auto const& fact : smpi_factor) { - XBT_DEBUG("smpi_factor:\t%zu: %zu values, first: %f", fact.factor, smpi_factor.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]); } - smpi_factor.shrink_to_fit(); + factors_.shrink_to_fit(); + + initialized_ = true; +} + +FactorSet::FactorSet(const std::string& name, double default_value, + std::function const&, double)> const& lambda) + : name_(name), default_value_(default_value), lambda_(lambda) +{ +} + +double FactorSet::operator()() +{ + return default_value_; +} - return smpi_factor; +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){