From aa5349f5cacefafa8fb42f88fd7d3e77928b19f3 Mon Sep 17 00:00:00 2001 From: SUTER Frederic Date: Thu, 6 May 2021 10:30:18 +0200 Subject: [PATCH] [sonar] implicit casts --- .../simgrid/kernel/routing/ClusterZone.hpp | 4 ++-- include/simgrid/kernel/routing/FloydZone.hpp | 2 +- include/simgrid/link.h | 2 +- include/simgrid/s4u/Host.hpp | 2 +- src/kernel/routing/DijkstraZone.cpp | 22 +++++++++---------- src/kernel/routing/FloydZone.cpp | 10 ++++----- src/kernel/routing/TorusZone.cpp | 4 ++-- src/plugins/host_dvfs.cpp | 4 ++-- src/s4u/s4u_Host.cpp | 2 +- src/s4u/s4u_Link.cpp | 2 +- src/simdag/sd_global.cpp | 2 +- 11 files changed, 27 insertions(+), 29 deletions(-) diff --git a/include/simgrid/kernel/routing/ClusterZone.hpp b/include/simgrid/kernel/routing/ClusterZone.hpp index 5e4964e407..29b0076662 100644 --- a/include/simgrid/kernel/routing/ClusterZone.hpp +++ b/include/simgrid/kernel/routing/ClusterZone.hpp @@ -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; } diff --git a/include/simgrid/kernel/routing/FloydZone.hpp b/include/simgrid/kernel/routing/FloydZone.hpp index f8ae9290cc..1afe57468e 100644 --- a/include/simgrid/kernel/routing/FloydZone.hpp +++ b/include/simgrid/kernel/routing/FloydZone.hpp @@ -24,7 +24,7 @@ namespace routing { class XBT_PRIVATE FloydZone : public RoutedZone { /* vars to compute the Floyd algorithm. */ std::vector> predecessor_table_; - std::vector> cost_table_; + std::vector> cost_table_; std::vector>> link_table_; void init_tables(unsigned int table_size); diff --git a/include/simgrid/link.h b/include/simgrid/link.h index fa84eb90a5..8e4b014e3d 100644 --- a/include/simgrid/link.h +++ b/include/simgrid/link.h @@ -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 diff --git a/include/simgrid/s4u/Host.hpp b/include/simgrid/s4u/Host.hpp index 07d7cc58da..c5023e8bf0 100644 --- a/include/simgrid/s4u/Host.hpp +++ b/include/simgrid/s4u/Host.hpp @@ -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 get_all_actors() const; /** Turns that host on if it was previously off diff --git a/src/kernel/routing/DijkstraZone.cpp b/src/kernel/routing/DijkstraZone.cpp index 30c7515c75..374536ca26 100644 --- a/src/kernel/routing/DijkstraZone.cpp +++ b/src/kernel/routing/DijkstraZone.cpp @@ -9,7 +9,7 @@ #include "surf/surf.hpp" #include "xbt/string.hpp" -#include +#include #include #include @@ -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(xbt_graph_node_get_data(src_elm))->graph_id_; - int dst_node_id = static_cast(xbt_graph_node_get_data(dst_elm))->graph_id_; + unsigned int src_node_id = static_cast(xbt_graph_node_get_data(src_elm))->graph_id_; + unsigned int dst_node_id = static_cast(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& 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 cost_arr(nr_nodes); /* link cost from src to other hosts */ + unsigned long nr_nodes = xbt_dynar_length(nodes); + std::vector 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; std::priority_queue, 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(xbt_graph_node_get_data(u_node)); int u_id = data->graph_id_; const Route* tmp_e_route = static_cast(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); diff --git a/src/kernel/routing/FloydZone.cpp b/src/kernel/routing/FloydZone.cpp index 4403c60289..5cc4e807f3 100644 --- a/src/kernel/routing/FloydZone.cpp +++ b/src/kernel/routing/FloydZone.cpp @@ -9,8 +9,7 @@ #include "surf/surf.hpp" #include "xbt/string.hpp" -#include -#include +#include 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::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]; } diff --git a/src/kernel/routing/TorusZone.cpp b/src/kernel/routing/TorusZone.cpp index 280febef27..b7c7001a38 100644 --- a/src/kernel/routing/TorusZone.cpp +++ b/src/kernel/routing/TorusZone.cpp @@ -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 myCoords(dsize); std::vector 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; diff --git a/src/plugins/host_dvfs.cpp b/src/plugins/host_dvfs.cpp index e4f1d01b61..5becbc1b3f 100644 --- a/src/plugins/host_dvfs.cpp +++ b/src/plugins/host_dvfs.cpp @@ -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(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); diff --git a/src/s4u/s4u_Host.cpp b/src/s4u/s4u_Host.cpp index abf1d86547..7005ea07de 100644 --- a/src/s4u/s4u_Host.cpp +++ b/src/s4u/s4u_Host.cpp @@ -134,7 +134,7 @@ std::vector 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(); } diff --git a/src/s4u/s4u_Link.cpp b/src/s4u/s4u_Link.cpp index 41a19abdac..ce6ba9d5eb 100644 --- a/src/s4u/s4u_Link.cpp +++ b/src/s4u/s4u_Link.cpp @@ -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(); } diff --git a/src/simdag/sd_global.cpp b/src/simdag/sd_global.cpp index 0670d25f82..c2a20a299b 100644 --- a/src/simdag/sd_global.cpp +++ b/src/simdag/sd_global.cpp @@ -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 -- 2.20.1