Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[sonar] Implicit casts should not lower precision.
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Thu, 22 Apr 2021 13:37:36 +0000 (15:37 +0200)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Thu, 22 Apr 2021 14:11:34 +0000 (16:11 +0200)
include/simgrid/smpi/smpi_replay.hpp
src/plugins/link_energy_wifi.cpp
src/smpi/internals/smpi_replay.cpp
src/surf/network_ib.cpp

index eabde00..b9ff2c2 100644 (file)
@@ -97,10 +97,10 @@ public:
 class CollCommParser : public ActionArgParser {
 public:
   double size;
-  double comm_size;
   double comp_size;
   int send_size;
   int recv_size;
+  unsigned comm_size; // size of communicator
   int root               = 0;
   MPI_Datatype datatype1 = MPI_DEFAULT_TYPE;
   MPI_Datatype datatype2 = MPI_DEFAULT_TYPE;
index 9396746..8a227c3 100644 (file)
@@ -147,7 +147,7 @@ void LinkEnergyWifi::update(const kernel::resource::NetworkAction&)
               action->get_variable()->get_value(), wifi_link->get_host_rate(&action->get_src()),
               wifi_link->get_host_rate(&action->get_dst()));
 
-    if(action->get_variable()->get_value()) {
+    if (action->get_variable()->get_value() != 0.0) {
       auto it = flowTmp.find(action);
 
       // if the flow has not been registered, initialize it: 0 bytes sent, and not updated since its creation timestamp
@@ -191,13 +191,13 @@ void LinkEnergyWifi::update(const kernel::resource::NetworkAction&)
    *  - if idle i.e. get_usage = 0, update P_{stat}
    * P_{tot} = P_{dyn}+P_{stat}
    */
-  if(link_->get_usage()){
+  if (link_->get_usage() != 0.0) {
     eDyn_ += /*duration * */ durUsage * ((wifi_link->get_host_count() * pRx_) + pTx_);
     eStat_ += (duration - durUsage) * pIdle_ * (wifi_link->get_host_count() + 1);
     XBT_DEBUG("eDyn +=  %f * ((%d * %f) + %f) | eDyn = %f (durusage =%f)", durUsage, wifi_link->get_host_count(), pRx_,
               pTx_, eDyn_, durUsage);
     dur_TxRx_ += duration;
-  }else{
+  } else {
     dur_idle_ += duration;
     eStat_ += (duration - (duration * control_duration_)) * pIdle_ * (wifi_link->get_host_count() + 1);
   }
index 75852d5..d171c70 100644 (file)
 #include <simgrid/smpi/smpi_replay.hpp>
 #include <src/smpi/include/private.hpp>
 
+#include <cmath>
+#include <limits>
 #include <memory>
 #include <numeric>
+#include <tuple>
 #include <unordered_map>
 #include <vector>
 
-#include <tuple>
-
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi_replay, smpi, "Trace Replay with SMPI");
 
 // From https://stackoverflow.com/questions/7110301/generic-hash-for-tuples-in-unordered-map-unordered-set
@@ -182,7 +183,9 @@ void BcastArgParser::parse(simgrid::xbt::ReplayAction& action, const std::string
 void ReduceArgParser::parse(simgrid::xbt::ReplayAction& action, const std::string&)
 {
   CHECK_ACTION_PARAMS(action, 2, 2)
-  comm_size = parse_double(action[2]);
+  double arg2 = trunc(parse_double(action[2]));
+  xbt_assert(0.0 <= arg2 && arg2 <= static_cast<double>(std::numeric_limits<unsigned>::max()));
+  comm_size = static_cast<unsigned>(arg2);
   comp_size = parse_double(action[3]);
   root      = (action.size() > 4) ? std::stoi(action[4]) : 0;
   if (action.size() > 5)
@@ -192,7 +195,9 @@ void ReduceArgParser::parse(simgrid::xbt::ReplayAction& action, const std::strin
 void AllReduceArgParser::parse(simgrid::xbt::ReplayAction& action, const std::string&)
 {
   CHECK_ACTION_PARAMS(action, 2, 1)
-  comm_size = parse_double(action[2]);
+  double arg2 = trunc(parse_double(action[2]));
+  xbt_assert(0.0 <= arg2 && arg2 <= static_cast<double>(std::numeric_limits<unsigned>::max()));
+  comm_size = static_cast<unsigned>(arg2);
   comp_size = parse_double(action[3]);
   if (action.size() > 4)
     datatype1 = simgrid::smpi::Datatype::decode(action[4]);
index ab61d8e..c62ea55 100644 (file)
@@ -108,7 +108,7 @@ NetworkIBModel::NetworkIBModel(const std::string& name) : NetworkSmpiModel(name)
 
 void NetworkIBModel::compute_IB_factors(IBNode* root) const
 {
-  double num_comm_out    = root->active_comms_up_.size();
+  size_t num_comm_out    = root->active_comms_up_.size();
   double max_penalty_out = 0.0;
   // first, compute all outbound penalties to get their max
   for (ActiveComm const* comm : root->active_comms_up_) {