Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Misc code simplifications guided by Sonar smells.
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Sat, 30 Apr 2022 13:07:03 +0000 (15:07 +0200)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Tue, 3 May 2022 19:04:32 +0000 (21:04 +0200)
21 files changed:
examples/cpp/exec-cpu-factors/s4u-exec-cpu-factors.cpp
src/instr/instr_paje_trace.cpp
src/instr/instr_paje_types.cpp
src/instr/instr_platform.cpp
src/kernel/EngineImpl.cpp
src/kernel/lmm/bmf.cpp
src/kernel/resource/VirtualMachineImpl.cpp
src/kernel/resource/profile/FutureEvtSet.cpp
src/kernel/routing/ClusterZone.cpp
src/mc/ModelChecker.cpp
src/mc/compare.cpp
src/mc/inspect/mc_dwarf.cpp
src/smpi/bindings/smpi_pmpi.cpp
src/smpi/bindings/smpi_pmpi_request.cpp
src/smpi/include/smpi_file.hpp
src/smpi/mpi/smpi_request.cpp
src/surf/HostImpl.cpp
src/surf/cpu_ti.cpp
src/surf/network_ib.cpp
src/surf/ptask_L07.cpp
src/xbt/config.cpp

index c62b7c3..6f6ce53 100644 (file)
@@ -31,11 +31,7 @@ static double cpu_variability(const sg4::Host* host, double flops)
 {
   /* creates variability for tasks smaller than 1% of CPU power.
    * unrealistic, for learning purposes */
-  double factor = 1.0;
-  double speed  = host->get_speed();
-  if (flops < speed / 100) {
-    factor = 0.5;
-  }
+  double factor = (flops < host->get_speed() / 100) ? 0.5 : 1.0;
   XBT_INFO("Host %s, task with %lf flops, new factor %lf", host->get_cname(), flops, factor);
   return factor;
 }
index 60ebc5c..c2b75b1 100644 (file)
@@ -33,8 +33,7 @@ void dump_buffer(bool force)
   } else {
     auto i = buffer.begin();
     for (auto const& event : buffer) {
-      double head_timestamp = event->timestamp_;
-      if (head_timestamp > last_timestamp_to_dump)
+      if (event->timestamp_ > last_timestamp_to_dump)
         break;
       event->print();
       delete event;
index 8817b21..b3486f7 100644 (file)
@@ -68,14 +68,10 @@ void VariableType::instr_event(double now, double delta, const char* resource, d
   // to check if variables were previously set to 0, otherwise paje won't simulate them
   static std::set<std::string, std::less<>> platform_variables;
 
-  // create a key considering the resource and variable
-  std::string key = std::string(resource) + get_name();
-
-  // check if key exists: if it doesn't, set the variable to zero and mark this in the global map.
-  if (platform_variables.find(key) == platform_variables.end()) {
+  // create a key considering the resource and variable, and check if key exists in the global map:
+  // if it doesn't, set the variable to zero.
+  if (platform_variables.emplace(std::string(resource) + get_name()).second)
     set_event(now, 0);
-    platform_variables.insert(key);
-  }
 
   add_event(now, value);
   sub_event(now + delta, value);
index 4d741c9..cbafbe5 100644 (file)
@@ -50,12 +50,9 @@ static simgrid::instr::Container* lowestCommonAncestor(const simgrid::instr::Con
   int j = static_cast<int>(ancestors_a2.size()) - 1;
   while (i >= 0 && j >= 0) {
     simgrid::instr::Container* a1p       = ancestors_a1.at(i);
-    const simgrid::instr::Container* a2p = ancestors_a2.at(j);
-    if (a1p == a2p) {
-      p = a1p;
-    } else {
+    if (a1p != ancestors_a2.at(j))
       break;
-    }
+    p = a1p;
     i--;
     j--;
   }
index 0aba684..874c980 100644 (file)
@@ -436,10 +436,7 @@ void EngineImpl::run_all_actors()
 actor::ActorImpl* EngineImpl::get_actor_by_pid(aid_t pid)
 {
   auto item = actor_list_.find(pid);
-  if (item != actor_list_.end())
-    return item->second;
-
-  return nullptr; // Not found
+  return item == actor_list_.end() ? nullptr : item->second;
 }
 
 void EngineImpl::remove_daemon(actor::ActorImpl* actor)
index 4dfe578..1fe15cb 100644 (file)
@@ -270,8 +270,7 @@ bool BmfSolver::get_alloc(const Eigen::VectorXd& fair_sharing, const allocation_
     }
     alloc[selected_resource].insert(player_idx);
   }
-  bool is_stable = (alloc == last_alloc);
-  if (is_stable)
+  if (alloc == last_alloc) // considered stable
     return true;
 
   std::vector<int> alloc_by_player      = alloc_map_to_vector(alloc);
index 9d829de..ac601e9 100644 (file)
@@ -27,8 +27,7 @@ void surf_vm_model_init_HL13(simgrid::kernel::resource::CpuModel* cpu_pm_model)
   engine->add_model(vm_model, {cpu_pm_model});
   std::shared_ptr<simgrid::kernel::resource::CpuModel> cpu_model_vm;
 
-  auto cpu_optim = simgrid::config::get_value<std::string>("cpu/optim");
-  if (cpu_optim == "TI") {
+  if (simgrid::config::get_value<std::string>("cpu/optim") == "TI") {
     cpu_model_vm = std::make_shared<simgrid::kernel::resource::CpuTiModel>("VmCpu_TI");
   } else {
     cpu_model_vm = std::make_shared<simgrid::kernel::resource::CpuCas01Model>("VmCpu_Cas01");
index 2106c92..d693df2 100644 (file)
@@ -37,8 +37,7 @@ double FutureEvtSet::next_date() const
 /** @brief Retrieves the next occurring event, or nullptr if none happens before date */
 Event* FutureEvtSet::pop_leq(double date, double* value, resource::Resource** resource)
 {
-  double event_date = next_date();
-  if (event_date > date || heap_.empty())
+  if (next_date() > date || heap_.empty())
     return nullptr;
 
   Event* event       = heap_.top().second;
index bd5ac1f..4f02317 100644 (file)
@@ -55,12 +55,8 @@ void ClusterBase::set_gateway(unsigned long position, NetPoint* gateway)
 
 NetPoint* ClusterBase::get_gateway(unsigned long position)
 {
-  NetPoint* res = nullptr;
-  auto it       = gateways_.find(position);
-  if (it != gateways_.end()) {
-    res = it->second;
-  }
-  return res;
+  auto it = gateways_.find(position);
+  return it == gateways_.end() ? nullptr : it->second;
 }
 
 void ClusterBase::fill_leaf_from_cb(unsigned long position, const std::vector<unsigned long>& dimensions,
index 733e1f7..aef3f31 100644 (file)
@@ -123,8 +123,7 @@ void ModelChecker::shutdown()
 
 void ModelChecker::resume()
 {
-  int res = checker_side_.get_channel().send(MessageType::CONTINUE);
-  if (res)
+  if (checker_side_.get_channel().send(MessageType::CONTINUE) != 0)
     throw xbt::errno_error();
   remote_process_->clear_cache();
 }
index 57f0ec7..bbec79b 100644 (file)
@@ -976,11 +976,10 @@ static bool heap_area_differ(const RemoteProcess& process, StateComparator& stat
     return true;
 
   /* Start comparison */
-  bool differ = type ? heap_area_differ_with_type(process, state, area1, area2, snapshot1, snapshot2, previous, type,
-                                                  size, check_ignore, pointer_level)
-                     : heap_area_differ_without_type(process, state, area1, area2, snapshot1, snapshot2, previous, size,
-                                                     check_ignore);
-  if (differ)
+  if (type ? heap_area_differ_with_type(process, state, area1, area2, snapshot1, snapshot2, previous, type, size,
+                                        check_ignore, pointer_level)
+           : heap_area_differ_without_type(process, state, area1, area2, snapshot1, snapshot2, previous, size,
+                                           check_ignore))
     return true;
 
   if (match_pairs)
index b9bee29..419a839 100644 (file)
@@ -990,8 +990,7 @@ static void MC_load_dwarf(simgrid::mc::ObjectInformation* info)
   xbt_assert(elf != nullptr && elf_kind(elf) == ELF_K_ELF, "%s is not an ELF file", info->file_name.c_str());
 
   // Remember if this is a `ET_EXEC` (fixed location) or `ET_DYN`:
-  Elf64_Half type = get_type(elf);
-  if (type == ET_EXEC)
+  if (get_type(elf) == ET_EXEC)
     info->flags |= simgrid::mc::ObjectInformation::Executable;
 
   // Read DWARF debug information in the file:
index 08705cd..56ce529 100644 (file)
@@ -203,13 +203,9 @@ int PMPI_Get_count(const MPI_Status * status, MPI_Datatype datatype, int *count)
     return MPI_ERR_TYPE;
   } else {
     size_t size = datatype->size();
-    if (size == 0) {
-      *count = 0;
-    } else if (status->count % size != 0) {
-      *count = MPI_UNDEFINED;
-    } else {
-      *count = simgrid::smpi::Status::get_count(status, datatype);
-    }
+    *count      = (size == 0)                   ? 0
+                  : (status->count % size != 0) ? MPI_UNDEFINED
+                                                : simgrid::smpi::Status::get_count(status, datatype);
     return MPI_SUCCESS;
   }
 }
index 1509268..96bb98b 100644 (file)
@@ -297,8 +297,7 @@ int PMPI_Bsend(const void* buf, int count, MPI_Datatype datatype, int dst, int t
   int bsend_buf_size = 0;
   void* bsend_buf = nullptr;
   smpi_process()->bsend_buffer(&bsend_buf, &bsend_buf_size);
-  int size = datatype->get_extent() * count;
-  if (bsend_buf == nullptr || bsend_buf_size < size + MPI_BSEND_OVERHEAD)
+  if (bsend_buf == nullptr || bsend_buf_size < datatype->get_extent() * count + MPI_BSEND_OVERHEAD)
     return MPI_ERR_BUFFER;
   TRACE_smpi_comm_in(my_proc_id, __func__,
                      new simgrid::instr::Pt2PtTIData("bsend", MPI_COMM_WORLD->group()->rank(dst_traced),
@@ -322,8 +321,7 @@ int PMPI_Ibsend(const void* buf, int count, MPI_Datatype datatype, int dst, int
   int bsend_buf_size = 0;
   void* bsend_buf = nullptr;
   smpi_process()->bsend_buffer(&bsend_buf, &bsend_buf_size);
-  int size = datatype->get_extent() * count;
-  if (bsend_buf == nullptr || bsend_buf_size < size + MPI_BSEND_OVERHEAD)
+  if (bsend_buf == nullptr || bsend_buf_size < datatype->get_extent() * count + MPI_BSEND_OVERHEAD)
     return MPI_ERR_BUFFER;
   TRACE_smpi_comm_in(my_proc_id, __func__,
                      new simgrid::instr::Pt2PtTIData("ibsend", MPI_COMM_WORLD->group()->rank(trace_dst),
index 7d68971..efda1cd 100644 (file)
@@ -110,8 +110,7 @@ int File::op_all(void* buf, int count, const Datatype* datatype, MPI_Status* sta
       status->count = 0;
     return MPI_SUCCESS;
   }
-  MPI_Offset total = max - min;
-  if (total == tot && (datatype->flags() & DT_FLAG_CONTIGUOUS)) {
+  if (max - min == tot && (datatype->flags() & DT_FLAG_CONTIGUOUS)) {
     // contiguous. Just have each proc perform its read
     if (status != MPI_STATUS_IGNORE)
       status->count = count * datatype->size();
index 57c1aca..8561d66 100644 (file)
@@ -593,8 +593,7 @@ void Request::start()
 
       mailbox = process->mailbox();
       XBT_DEBUG("Is there a corresponding recv already posted in the large mailbox %s?", mailbox->get_cname());
-      simgrid::kernel::activity::ActivityImplPtr action = mailbox->iprobe(1, &match_send, static_cast<void*>(this));
-      if (action == nullptr) {
+      if (not mailbox->iprobe(1, &match_send, static_cast<void*>(this))) {
         if ((flags_ & MPI_REQ_SSEND) == 0) {
           mailbox = process->mailbox_small();
           XBT_DEBUG("No, nothing in the large mailbox, message is to be sent on the small one %s",
@@ -603,8 +602,7 @@ void Request::start()
           mailbox = process->mailbox_small();
           XBT_DEBUG("SSEND : Is there a corresponding recv already posted in the small mailbox %s?",
                     mailbox->get_cname());
-          action = mailbox->iprobe(1, &match_send, static_cast<void*>(this));
-          if (action == nullptr) {
+          if (not mailbox->iprobe(1, &match_send, static_cast<void*>(this))) {
             XBT_DEBUG("No, we are first, send to large mailbox");
             mailbox = process->mailbox();
           }
@@ -730,8 +728,7 @@ int Request::testsome(int incount, MPI_Request requests[], int *count, int *indi
   *count = 0;
   for (int i = 0; i < incount; i++) {
     if (requests[i] != MPI_REQUEST_NULL && not (requests[i]->flags_ & MPI_REQ_FINISHED)) {
-      int ret = test(&requests[i], pstat, &flag);
-      if(ret!=MPI_SUCCESS)
+      if (test(&requests[i], pstat, &flag) != MPI_SUCCESS)
         error = 1;
       if(flag) {
         indices[*count] = i;
index 7f1e102..51f7f98 100644 (file)
@@ -194,9 +194,7 @@ void HostImpl::destroy_vm(const std::string& name)
 VirtualMachineImpl* HostImpl::get_vm_by_name_or_null(const std::string& name) const
 {
   auto vm_it = vms_.find(name);
-  if (vm_it != vms_.end())
-    return vm_it->second;
-  return nullptr;
+  return vm_it == vms_.end() ? nullptr : vm_it->second;
 }
 
 std::vector<s4u::VirtualMachine*> HostImpl::get_vms() const
index 63625bc..d5f2153 100644 (file)
@@ -174,15 +174,12 @@ double CpuTiTmgr::solve(double a, double amount) const
   XBT_DEBUG("Quotient: %g reduced_amount: %f reduced_a: %f", quotient, reduced_amount, reduced_a);
 
   /* Now solve for new_amount which is <= trace_total */
-  double reduced_b;
   XBT_DEBUG("Solve integral: [%.2f, amount=%.2f]", reduced_a, reduced_amount);
-  double amount_till_end = integrate(reduced_a, last_time_);
 
-  if (amount_till_end > reduced_amount) {
-    reduced_b = profile_->solve_simple(reduced_a, reduced_amount);
-  } else {
-    reduced_b = last_time_ + profile_->solve_simple(0.0, reduced_amount - amount_till_end);
-  }
+  double amount_till_end = integrate(reduced_a, last_time_);
+  double reduced_b       = amount_till_end > reduced_amount
+                               ? profile_->solve_simple(reduced_a, reduced_amount)
+                               : last_time_ + profile_->solve_simple(0.0, reduced_amount - amount_till_end);
 
   /* Re-map to the original b and amount */
   return last_time_ * floor(a / last_time_) + (quotient * last_time_) + reduced_b;
index 9c7a7ed..693a90f 100644 (file)
@@ -129,8 +129,7 @@ void NetworkIBModel::compute_IB_factors(IBNode* root) const
   for (ActiveComm* comm : root->active_comms_up_) {
     // compute inbound penalty
     double my_penalty_in = 1.0;
-    int nb_comms         = comm->destination->nb_active_comms_down_; // total number of incoming comms
-    if (nb_comms != 1)
+    if (comm->destination->nb_active_comms_down_ != 1)                      // total number of incoming comms
       my_penalty_in = (comm->destination->active_comms_down_)[root]         // number of comm sent to dest by root node
                       * Be_ * comm->destination->active_comms_down_.size(); // number of different nodes sending to dest
 
index e89e762..88eac8f 100644 (file)
@@ -142,8 +142,7 @@ void HostL07Model::update_actions_state(double /*now*/, double delta)
     const lmm::Constraint* cnst         = action.get_variable()->get_constraint(i);
     while (cnst != nullptr) {
       i++;
-      const Resource* constraint_id = cnst->get_id();
-      if (not constraint_id->is_on()) {
+      if (not cnst->get_id()->is_on()) {
         XBT_DEBUG("Action (%p) Failed!!", &action);
         action.finish(Action::State::FAILED);
         break;
index 0ae2bf8..08b403b 100644 (file)
@@ -386,8 +386,7 @@ void set_parse(const std::string& opt)
     std::string val = name.substr(pos + 1);
     name.erase(pos);
 
-    const std::string path("path");
-    if (name.compare(0, path.length(), path) != 0)
+    if (name.rfind("path", 0) != 0)
       XBT_INFO("Configuration change: Set '%s' to '%s'", name.c_str(), val.c_str());
 
     set_as_string(name.c_str(), val);