Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[sonar] implicit casts
authorSUTER Frederic <frederic.suter@cc.in2p3.fr>
Thu, 6 May 2021 08:30:18 +0000 (10:30 +0200)
committerSUTER Frederic <frederic.suter@cc.in2p3.fr>
Thu, 6 May 2021 08:30:18 +0000 (10:30 +0200)
include/simgrid/kernel/routing/ClusterZone.hpp
include/simgrid/kernel/routing/FloydZone.hpp
include/simgrid/link.h
include/simgrid/s4u/Host.hpp
src/kernel/routing/DijkstraZone.cpp
src/kernel/routing/FloydZone.cpp
src/kernel/routing/TorusZone.cpp
src/plugins/host_dvfs.cpp
src/s4u/s4u_Host.cpp
src/s4u/s4u_Link.cpp
src/simdag/sd_global.cpp

index 5e4964e..29b0076 100644 (file)
@@ -74,14 +74,14 @@ class ClusterZone : public NetZoneImpl {
   NetPoint* router_                = nullptr;
   bool has_limiter_                = false;
   bool has_loopback_               = false;
-  unsigned int num_links_per_node_ = 1; /* may be 1 (if only a private link), 2 or 3 (if limiter and loopback) */
+  unsigned long num_links_per_node_ = 1; /* may be 1 (if only a private link), 2 or 3 (if limiter and loopback) */
 
   s4u::Link::SharingPolicy link_sharing_policy_; //!< cluster links: sharing policy
   double link_bw_;                               //!< cluster links: bandwidth
   double link_lat_;                              //!< cluster links: latency
 
 protected:
-  void set_num_links_per_node(unsigned int num) { num_links_per_node_ = num; }
+  void set_num_links_per_node(unsigned long num) { num_links_per_node_ = num; }
   resource::LinkImpl* get_uplink_from(unsigned int position) const { return private_links_.at(position).first; }
   resource::LinkImpl* get_downlink_to(unsigned int position) const { return private_links_.at(position).second; }
 
index f8ae929..1afe574 100644 (file)
@@ -24,7 +24,7 @@ namespace routing {
 class XBT_PRIVATE FloydZone : public RoutedZone {
   /* vars to compute the Floyd algorithm. */
   std::vector<std::vector<int>> predecessor_table_;
-  std::vector<std::vector<double>> cost_table_;
+  std::vector<std::vector<unsigned long>> cost_table_;
   std::vector<std::vector<std::unique_ptr<Route>>> link_table_;
 
   void init_tables(unsigned int table_size);
index fa84eb9..8e4b014 100644 (file)
@@ -33,7 +33,7 @@ XBT_PUBLIC void sg_link_set_data(sg_link_t link, void* data);
 XBT_ATTRIB_DEPRECATED_v330("Please use sg_link_get_data()") XBT_PUBLIC void* sg_link_data(const_sg_link_t link);
 XBT_ATTRIB_DEPRECATED_v330("Please use sg_link_set_data()") XBT_PUBLIC
     void sg_link_data_set(sg_link_t link, void* data);
-XBT_PUBLIC int sg_link_count();
+XBT_PUBLIC size_t sg_link_count();
 XBT_PUBLIC sg_link_t* sg_link_list();
 SG_END_DECL
 
index 07d7cc5..c5023e8 100644 (file)
@@ -85,7 +85,7 @@ public:
 
   kernel::routing::NetPoint* get_netpoint() const { return pimpl_netpoint_; }
 
-  int get_actor_count() const;
+  size_t get_actor_count() const;
   std::vector<ActorPtr> get_all_actors() const;
 
   /** Turns that host on if it was previously off
index 30c7515..374536c 100644 (file)
@@ -9,7 +9,7 @@
 #include "surf/surf.hpp"
 #include "xbt/string.hpp"
 
-#include <cfloat>
+#include <climits>
 #include <queue>
 #include <vector>
 
@@ -23,7 +23,7 @@ class GraphNodeData {
 public:
   explicit GraphNodeData(int id) : id_(id) {}
   int id_;
-  int graph_id_ = -1; /* used for caching internal graph id's */
+  unsigned long graph_id_ = UINT_MAX; /* used for caching internal graph id's */
 };
 
 void DijkstraZone::route_graph_delete(xbt_graph_t g)
@@ -96,8 +96,8 @@ void DijkstraZone::get_local_route(NetPoint* src, NetPoint* dst, Route* route, d
   const s_xbt_node_t* src_elm = node_map_search(src_id);
   const s_xbt_node_t* dst_elm = node_map_search(dst_id);
 
-  int src_node_id = static_cast<GraphNodeData*>(xbt_graph_node_get_data(src_elm))->graph_id_;
-  int dst_node_id = static_cast<GraphNodeData*>(xbt_graph_node_get_data(dst_elm))->graph_id_;
+  unsigned int src_node_id = static_cast<GraphNodeData*>(xbt_graph_node_get_data(src_elm))->graph_id_;
+  unsigned int dst_node_id = static_cast<GraphNodeData*>(xbt_graph_node_get_data(dst_elm))->graph_id_;
 
   /* if the src and dst are the same */
   if (src_node_id == dst_node_id) {
@@ -121,18 +121,18 @@ void DijkstraZone::get_local_route(NetPoint* src, NetPoint* dst, Route* route, d
   std::vector<int>& pred_arr = elm.first->second;
 
   if (elm.second) { /* new element was inserted (not cached mode, or cache miss) */
-    int nr_nodes = xbt_dynar_length(nodes);
-    std::vector<double> cost_arr(nr_nodes); /* link cost from src to other hosts */
+    unsigned long nr_nodes = xbt_dynar_length(nodes);
+    std::vector<unsigned long> cost_arr(nr_nodes); /* link cost from src to other hosts */
     pred_arr.resize(nr_nodes);              /* predecessors in path from src */
     using Qelt = std::pair<double, int>;
     std::priority_queue<Qelt, std::vector<Qelt>, std::greater<>> pqueue;
 
     /* initialize */
-    cost_arr[src_node_id] = 0.0;
+    cost_arr[src_node_id] = 0;
 
-    for (int i = 0; i < nr_nodes; i++) {
+    for (unsigned long i = 0; i < nr_nodes; i++) {
       if (i != src_node_id) {
-        cost_arr[i] = DBL_MAX;
+        cost_arr[i] = ULONG_MAX;
       }
 
       pred_arr[i] = 0;
@@ -154,7 +154,7 @@ void DijkstraZone::get_local_route(NetPoint* src, NetPoint* dst, Route* route, d
         const GraphNodeData* data            = static_cast<GraphNodeData*>(xbt_graph_node_get_data(u_node));
         int u_id                             = data->graph_id_;
         const Route* tmp_e_route             = static_cast<Route*>(xbt_graph_edge_get_data(edge));
-        int cost_v_u                         = tmp_e_route->link_list_.size(); /* count of links, old model assume 1 */
+        unsigned long cost_v_u               = tmp_e_route->link_list_.size(); /* count of links, old model assume 1 */
 
         if (cost_v_u + cost_arr[v_id] < cost_arr[u_id]) {
           pred_arr[u_id] = v_id;
@@ -169,7 +169,7 @@ void DijkstraZone::get_local_route(NetPoint* src, NetPoint* dst, Route* route, d
   NetPoint* gw_src   = nullptr;
   NetPoint* first_gw = nullptr;
 
-  for (int v = dst_node_id; v != src_node_id; v = pred_arr[v]) {
+  for (unsigned int v = dst_node_id; v != src_node_id; v = pred_arr[v]) {
     const s_xbt_node_t* node_pred_v = xbt_dynar_get_as(nodes, pred_arr[v], xbt_node_t);
     const s_xbt_node_t* node_v      = xbt_dynar_get_as(nodes, v, xbt_node_t);
     const s_xbt_edge_t* edge        = xbt_graph_get_edge(route_graph_.get(), node_pred_v, node_v);
index 4403c60..5cc4e80 100644 (file)
@@ -9,8 +9,7 @@
 #include "surf/surf.hpp"
 #include "xbt/string.hpp"
 
-#include <cfloat>
-#include <limits>
+#include <climits>
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_route_floyd, surf, "Routing part of surf");
 
@@ -26,7 +25,7 @@ void FloydZone::init_tables(unsigned int table_size)
     link_table_.resize(table_size);
     predecessor_table_.resize(table_size);
     for (auto& cost : cost_table_)
-      cost.resize(table_size, DBL_MAX); /* link cost from host to host */
+      cost.resize(table_size, ULONG_MAX); /* link cost from host to host */
     for (auto& link : link_table_)
       link.resize(table_size); /* actual link between src and dst */
     for (auto& predecessor : predecessor_table_)
@@ -150,9 +149,8 @@ void FloydZone::do_seal()
   for (unsigned int c = 0; c < table_size; c++) {
     for (unsigned int a = 0; a < table_size; a++) {
       for (unsigned int b = 0; b < table_size; b++) {
-        if (cost_table_[a][c] < DBL_MAX && cost_table_[c][b] < DBL_MAX &&
-            (fabs(cost_table_[a][b] - DBL_MAX) < std::numeric_limits<double>::epsilon() ||
-             (cost_table_[a][c] + cost_table_[c][b] < cost_table_[a][b]))) {
+        if (cost_table_[a][c] < ULONG_MAX && cost_table_[c][b] < ULONG_MAX &&
+            (cost_table_[a][b] == ULONG_MAX || (cost_table_[a][c] + cost_table_[c][b] < cost_table_[a][b]))) {
           cost_table_[a][b]        = cost_table_[a][c] + cost_table_[c][b];
           predecessor_table_[a][b] = predecessor_table_[c][b];
         }
index 280febe..b7c7001 100644 (file)
@@ -107,11 +107,11 @@ void TorusZone::get_local_route(NetPoint* src, NetPoint* dst, Route* route, doub
    * 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.
    */
-  const unsigned int dsize = dimensions_.size();
+  const unsigned long dsize = dimensions_.size();
   std::vector<unsigned int> myCoords(dsize);
   std::vector<unsigned int> targetCoords(dsize);
   unsigned int dim_size_product = 1;
-  for (unsigned i = 0; i < dsize; i++) {
+  for (unsigned long i = 0; i < dsize; i++) {
     unsigned cur_dim_size = dimensions_[i];
     myCoords[i]           = (src->id() / dim_size_product) % cur_dim_size;
     targetCoords[i]       = (dst->id() / dim_size_product) % cur_dim_size;
index e4f1d01..5becbc1 100644 (file)
@@ -121,7 +121,7 @@ public:
 
     const char* local_max_pstate_config = host_->get_property(cfg_max_pstate.get_name());
     if (local_max_pstate_config != nullptr) {
-      max_pstate = std::stod(local_max_pstate_config);
+      max_pstate = std::stoi(local_max_pstate_config);
     }
     xbt_assert(max_pstate <= host_->get_pstate_count() - 1, "Value for max_pstate too large!");
     xbt_assert(min_pstate <= max_pstate, "min_pstate is larger than max_pstate!");
@@ -206,7 +206,7 @@ public:
        */
       // Load is now < freq_up_threshold; exclude pstate 0 (the fastest)
       // because pstate 0 can only be selected if load > freq_up_threshold_
-      int new_pstate = get_max_pstate() - load * (get_max_pstate() + 1);
+      int new_pstate = static_cast<int>(get_max_pstate() - load * (get_max_pstate() + 1));
       if (new_pstate < get_min_pstate())
         new_pstate = get_min_pstate();
       get_host()->set_pstate(new_pstate);
index abf1d86..7005ea0 100644 (file)
@@ -134,7 +134,7 @@ std::vector<ActorPtr> Host::get_all_actors() const
 }
 
 /** @brief Returns how many actors (daemonized or not) have been launched on this host */
-int Host::get_actor_count() const
+size_t Host::get_actor_count() const
 {
   return pimpl_->get_actor_count();
 }
index 41a19ab..ce6ba9d 100644 (file)
@@ -260,7 +260,7 @@ void sg_link_data_set(sg_link_t link, void* data) // XBT_ATTRIB_DEPRECATED_v330
   sg_link_set_data(link, data);
 }
 
-int sg_link_count()
+size_t sg_link_count()
 {
   return simgrid::s4u::Engine::get_instance()->get_link_count();
 }
index 0670d25..c2a20a2 100644 (file)
@@ -189,7 +189,7 @@ void SD_create_environment(const char* platform_file)
 {
   simgrid::s4u::Engine::get_instance()->load_platform(platform_file);
 
-  XBT_DEBUG("Host number: %zu, link number: %d", sg_host_count(), sg_link_count());
+  XBT_DEBUG("Host number: %zu, link number: %zu", sg_host_count(), sg_link_count());
 #if SIMGRID_HAVE_JEDULE
   jedule_sd_init();
 #endif