Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
more strings
authorFrederic Suter <frederic.suter@cc.in2p3.fr>
Thu, 10 Aug 2017 12:47:40 +0000 (14:47 +0200)
committerFrederic Suter <frederic.suter@cc.in2p3.fr>
Thu, 10 Aug 2017 12:47:40 +0000 (14:47 +0200)
src/kernel/routing/TorusZone.cpp
src/surf/xml/platf.hpp
src/surf/xml/surfxml_sax_cb.cpp

index e5c6ce7..cf31241 100644 (file)
@@ -81,12 +81,11 @@ void TorusZone::parse_specific_arguments(sg_platf_cluster_cbarg_t cluster)
 
   if (not dimensions.empty()) {
     /* We are in a torus cluster
-     * Parse attribute dimensions="dim1,dim2,dim3,...,dimN" and safe it in a vector.
+     * Parse attribute dimensions="dim1,dim2,dim3,...,dimN" and save them into a vector.
      * Additionally, we need to know how many ranks we have in total
      */
-    for (auto group : dimensions) {
-      dimensions_.push_back(surf_parse_get_int(group.c_str()));
-    }
+    for (auto group : dimensions)
+      dimensions_.push_back(surf_parse_get_int(group));
 
     linkCountPerNode_ = dimensions_.size();
   }
@@ -117,21 +116,16 @@ void TorusZone::getLocalRoute(NetPoint* src, NetPoint* dst, sg_platf_route_cbarg
   unsigned int current_node = src->id();
   unsigned int next_node    = 0;
   /*
-   * Arrays that hold the coordinates of the current node and
-   * the target; comparing the values at the i-th position of
-   * both arrays, we can easily assess whether we need to route
-   * into this dimension or not.
+   * Arrays that hold the coordinates of the current node andthe target; comparing the values at the i-th position of
+   * both arrays, we can easily assess whether we need to route into this dimension or not.
    */
   unsigned int myCoords[4];
   rankId_to_coords(src->id(), dimensions_, &myCoords);
   unsigned int targetCoords[4];
   rankId_to_coords(dst->id(), dimensions_, &targetCoords);
   /*
-   * linkOffset describes the offset where the link
-   * we want to use is stored
-   * (+1 is added because each node has a link from itself to itself,
-   * which can only be the case if src->m_id == dst->m_id -- see above
-   * for this special case)
+   * linkOffset describes the offset where the link we want to use is stored(+1 is added because each node has a link
+   * from itself to itself, which can only be the case if src->m_id == dst->m_id -- see above for this special case)
    */
   int nodeOffset = (dimensions_.size() + 1) * src->id();
 
index 1a7dc48..159aa1a 100644 (file)
@@ -3,11 +3,9 @@
 /* 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 SURF_SURFXML_PARSE_H
-#define SURF_SURFXML_PARSE_H
+#ifndef SURF_SURFXML_PARSE_HPP
+#define SURF_SURFXML_PARSE_HPP
 
-#include <xbt/function_types.h>
-#include <xbt/misc.h>
 #include <xbt/signal.hpp>
 
 SG_BEGIN_DECL()
@@ -20,11 +18,11 @@ XBT_PUBLIC(void) surf_parse_open(const char *file);
 XBT_PUBLIC(void) surf_parse_close();
 XBT_PUBLIC(void) surf_parse_assert(bool cond, std::string msg);
 XBT_PUBLIC(void) XBT_ATTRIB_NORETURN surf_parse_error(std::string msg);
-XBT_PUBLIC(void) surf_parse_assert_netpoint(char* hostname, const char* pre, const char* post);
-XBT_PUBLIC(void) surf_parse_warn(const char *msg,...) XBT_ATTRIB_PRINTF(1,2);
+XBT_PUBLIC(void) surf_parse_assert_netpoint(std::string hostname, std::string pre, std::string post);
+XBT_PUBLIC(void) surf_parse_warn(std::string msg);
 
-XBT_PUBLIC(double) surf_parse_get_double(const char *string);
-XBT_PUBLIC(int) surf_parse_get_int(const char *string);
+XBT_PUBLIC(double) surf_parse_get_double(std::string s);
+XBT_PUBLIC(int) surf_parse_get_int(std::string s);
 XBT_PUBLIC(double) surf_parse_get_time(const char *string, const char *entity_kind, const char *name);
 XBT_PUBLIC(double) surf_parse_get_size(const char *string, const char *entity_kind, const char *name);
 XBT_PUBLIC(double) surf_parse_get_bandwidth(const char *string, const char *entity_kind, const char *name);
index b28cba8..bd7ffc5 100644 (file)
@@ -40,6 +40,7 @@ void surf_parse_assert(bool cond, std::string msg)
     xbt_die("Exiting now");
   }
 }
+
 void surf_parse_error(std::string msg)
 {
   int lineno = surf_parse_lineno;
@@ -49,15 +50,12 @@ void surf_parse_error(std::string msg)
   xbt_die("Exiting now");
 }
 
-void surf_parse_assert_netpoint(char* hostname, const char* pre, const char* post)
+void surf_parse_assert_netpoint(std::string hostname, std::string pre, std::string post)
 {
-  if (sg_netpoint_by_name_or_null(hostname) != nullptr) // found
+  if (sg_netpoint_by_name_or_null(hostname.c_str()) != nullptr) // found
     return;
 
-  std::string msg = std::string(pre);
-  msg += hostname;
-  msg += post;
-  msg += " Existing netpoints: \n";
+  std::string msg = pre + hostname + post + " Existing netpoints: \n";
 
   std::vector<simgrid::kernel::routing::NetPoint*> list;
   simgrid::s4u::Engine::getInstance()->getNetpointList(&list);
@@ -83,33 +81,33 @@ void surf_parse_assert_netpoint(char* hostname, const char* pre, const char* pos
   surf_parse_error(msg);
 }
 
-void surf_parse_warn(const char *fmt, ...) {
-  va_list va;
-  va_start(va,fmt);
-  char *msg = bvprintf(fmt,va);
-  va_end(va);
-    XBT_WARN("%s:%d: %s", surf_parsed_filename, surf_parse_lineno, msg);
-    free(msg);
+void surf_parse_warn(std::string msg)
+{
+  XBT_WARN("%s:%d: %s", surf_parsed_filename, surf_parse_lineno, msg.c_str());
 }
 
-double surf_parse_get_double(const char *string) {
-  double res;
-  int ret = sscanf(string, "%lg", &res);
-  if (ret != 1)
-    surf_parse_error(std::string(string) + " is not a double");
-  return res;
+double surf_parse_get_double(std::string s)
+{
+  try {
+    return std::stod(s);
+  } catch (std::invalid_argument& ia) {
+    surf_parse_error(s + " is not a double");
+    return -1;
+  }
 }
 
-int surf_parse_get_int(const char *string) {
-  int res;
-  int ret = sscanf(string, "%d", &res);
-  if (ret != 1)
-    surf_parse_error(std::string(string) + " is not an integer");
-  return res;
+int surf_parse_get_int(std::string s)
+{
+  try {
+    return std::stoi(s);
+  } catch (std::invalid_argument& ia) {
+    surf_parse_error(s + " is not a double");
+    return -1;
+  }
 }
 
 /* Turn something like "1-4,6,9-11" into the vector {1,2,3,4,6,9,10,11} */
-static std::vector<int>* explodesRadical(const char* radicals)
+static std::vector<int>* explodesRadical(std::string radicals)
 {
   std::vector<int>* exploded = new std::vector<int>();
 
@@ -119,15 +117,15 @@ static std::vector<int>* explodesRadical(const char* radicals)
   for (auto group : radical_elements) {
     std::vector<std::string> radical_ends;
     boost::split(radical_ends, group, boost::is_any_of("-"));
-    int start                = surf_parse_get_int((radical_ends.front()).c_str());
-    int end                  = 0;
+    int start = surf_parse_get_int(radical_ends.front());
+    int end   = 0;
 
     switch (radical_ends.size()) {
       case 1:
         end = start;
         break;
       case 2:
-        end = surf_parse_get_int((radical_ends.back()).c_str());
+        end = surf_parse_get_int(radical_ends.back());
         break;
       default:
         surf_parse_error(std::string("Malformed radical: ") + group);
@@ -972,7 +970,8 @@ void ETag_surfxml_zone()
 void STag_surfxml_config()
 {
   ZONE_TAG = 0;
-  xbt_assert(current_property_set == nullptr, "Someone forgot to reset the property set to nullptr in its closing tag (or XML malformed)");
+  xbt_assert(current_property_set == nullptr,
+             "Someone forgot to reset the property set to nullptr in its closing tag (or XML malformed)");
   XBT_DEBUG("START configuration name = %s",A_surfxml_config_id);
   if (_sg_cfg_init_status == 2) {
     surf_parse_error("All <config> tags must be given before any platform elements (such as <zone>, <host>, <cluster>, "
@@ -1003,6 +1002,7 @@ void STag_surfxml_process()
   AX_surfxml_actor_function = AX_surfxml_process_function;
   STag_surfxml_actor();
 }
+
 void STag_surfxml_actor()
 {
   ZONE_TAG  = 0;
@@ -1021,6 +1021,7 @@ void ETag_surfxml_process()
   AX_surfxml_actor_on___failure = (AT_surfxml_actor_on___failure)AX_surfxml_process_on___failure;
   ETag_surfxml_actor();
 }
+
 void ETag_surfxml_actor()
 {
   s_sg_platf_process_cbarg_t actor;
@@ -1067,8 +1068,7 @@ void STag_surfxml_model___prop(){
   if (not current_model_property_set)
     current_model_property_set = new std::map<std::string, std::string>();
 
-  current_model_property_set->insert(
-      {std::string(A_surfxml_model___prop_id), std::string(A_surfxml_model___prop_value)});
+  current_model_property_set->insert({A_surfxml_model___prop_id, A_surfxml_model___prop_value});
 }
 
 void ETag_surfxml_prop(){/* Nothing to do */}