1 /* Copyright (c) 2016. The SimGrid Team.
2 * All rights reserved. */
4 /* This program is free software; you can redistribute it and/or modify it
5 * under the terms of the license (GNU LGPL) which comes with this package. */
7 #include "smpi/smpi_utils.hpp"
8 #include "xbt/sysdep.h"
11 #include <boost/tokenizer.hpp>
13 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi_utils, smpi, "Logging specific to SMPI (utils)");
15 std::vector<s_smpi_factor_t> parse_factor(const char *smpi_coef_string)
17 std::vector<s_smpi_factor_t> smpi_factor;
19 /** Setup the tokenizer that parses the string **/
20 typedef boost::tokenizer<boost::char_separator<char>> Tokenizer;
21 boost::char_separator<char> sep(";");
22 boost::char_separator<char> factor_separator(":");
23 std::string tmp_string(smpi_coef_string);
24 Tokenizer tokens(tmp_string, sep);
27 * Iterate over patterns like A:B:C:D;E:F;G:H
28 * These will be broken down into:
33 for (Tokenizer::iterator token_iter = tokens.begin(); token_iter != tokens.end(); token_iter++) {
34 XBT_DEBUG("token : %s", token_iter->c_str());
35 Tokenizer factor_values(*token_iter, factor_separator);
37 if (factor_values.begin() == factor_values.end()) {
38 xbt_die("Malformed radical for smpi factor: '%s'", smpi_coef_string);
40 unsigned int iteration = 0;
41 for (Tokenizer::iterator factor_iter = factor_values.begin();
42 factor_iter != factor_values.end(); factor_iter++, iteration++) {
45 if (factor_iter == factor_values.begin()) { /* first element */
46 errmsg = bprintf("Invalid factor in chunk #%zu: %%s", smpi_factor.size()+1);
47 fact.factor = xbt_str_parse_int(factor_iter->c_str(), errmsg);
50 errmsg = bprintf("Invalid factor value %d in chunk #%zu: %%s", iteration, smpi_factor.size()+1);
51 fact.values.push_back(xbt_str_parse_double(factor_iter->c_str(), errmsg));
56 smpi_factor.push_back(fact);
57 XBT_DEBUG("smpi_factor:\t%zu : %zu values, first: %f", fact.factor, smpi_factor.size(), fact.values[0]);
59 std::sort(smpi_factor.begin(), smpi_factor.end(), [](const s_smpi_factor_t &pa, const s_smpi_factor_t &pb) {
60 return (pa.factor < pb.factor);
62 for (auto& fact : smpi_factor) {
63 XBT_DEBUG("smpi_factor:\t%zu : %zu values, first: %f", fact.factor, smpi_factor.size() ,fact.values[0]);
65 smpi_factor.shrink_to_fit();