Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Move the files related to the platform parsing to kernel/xml
[simgrid.git] / src / smpi / internals / smpi_utils.cpp
index e4cbc80..09688d8 100644 (file)
@@ -1,5 +1,4 @@
-/* Copyright (c) 2016-2022. The SimGrid Team.
- * All rights reserved.                                                     */
+/* Copyright (c) 2016-2023. 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. */
@@ -8,23 +7,19 @@
 
 #include "private.hpp"
 #include "smpi_config.hpp"
-#include "src/surf/xml/platf.hpp"
+#include "src/kernel/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>
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi_utils, smpi, "Logging specific to SMPI (utils)");
 
-extern std::string surf_parsed_filename;
-extern int surf_parse_lineno;
-
-namespace simgrid {
-namespace smpi {
-namespace utils {
+namespace {
 
 double total_benched_time=0;
 unsigned long total_malloc_size=0;
@@ -43,7 +38,7 @@ struct current_buffer_metadata_t {
 };
 
 alloc_metadata_t max_malloc;
-F2C* current_handle = nullptr;
+simgrid::smpi::F2C* current_handle = nullptr;
 current_buffer_metadata_t current_buffer1;
 current_buffer_metadata_t current_buffer2;
 
@@ -51,69 +46,15 @@ std::unordered_map<const void*, alloc_metadata_t> allocs;
 
 std::unordered_map<int, std::vector<std::string>> collective_calls;
 
-std::vector<s_smpi_factor_t> parse_factor(const std::string& smpi_coef_string)
-{
-  std::vector<s_smpi_factor_t> smpi_factor;
-
-  /** 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(smpi_coef_string, 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 smpi factor: '%s'",
-               smpi_coef_string.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(smpi_factor.size() + 1) +
-                                      ": " + *factor_iter);
-        }
-      } 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(smpi_factor.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]);
-  }
-  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]);
-  }
-  smpi_factor.shrink_to_fit();
+} // namespace
 
-  return smpi_factor;
-}
+namespace simgrid::smpi::utils {
 
 void add_benched_time(double time){
   total_benched_time += time;
 }
 
-void account_malloc_size(size_t size, const std::string& file, int line, const void* ptr)
+void account_malloc_size(size_t size, std::string_view file, int line, const void* ptr)
 {
   if (smpi_cfg_display_alloc()) {
     alloc_metadata_t metadata;
@@ -349,8 +290,7 @@ int check_collectives_ordering(MPI_Comm comm, const std::string& call)
 {
   unsigned int count = comm->get_collectives_count();
   comm->increment_collectives_count();
-  auto vec = collective_calls.find(comm->id());
-  if (vec == collective_calls.end()) {
+  if (auto vec = collective_calls.find(comm->id()); vec == collective_calls.end()) {
     collective_calls.try_emplace(comm->id(), std::vector<std::string>{call});
   } else {
     // are we the first ? add the call
@@ -368,6 +308,4 @@ int check_collectives_ordering(MPI_Comm comm, const std::string& call)
   }
   return MPI_SUCCESS;
 }
-}
-}
-} // namespace simgrid
+} // namespace simgrid::smpi::utils