Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Reduce scope for variables.
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Mon, 22 Mar 2021 10:08:56 +0000 (11:08 +0100)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Mon, 22 Mar 2021 10:49:09 +0000 (11:49 +0100)
src/kernel/lmm/maxmin.cpp
src/plugins/link_energy_wifi.cpp
src/simix/smx_global.cpp
src/surf/cpu_cas01.cpp
src/surf/network_cm02.cpp
src/surf/network_interface.cpp
src/surf/ptask_L07.cpp
src/surf/surf_c_bindings.cpp

index bd13a0a..793c0f7 100644 (file)
@@ -141,16 +141,13 @@ System::System(bool selective_update) : selective_update_active(selective_update
 
 System::~System()
 {
-  Variable* var;
-  Constraint* cnst;
-
-  while ((var = extract_variable())) {
+  while (Variable* var = extract_variable()) {
     std::string demangled = boost::core::demangle(var->id_ ? typeid(*var->id_).name() : "(unidentified)");
     XBT_WARN("Probable bug: a %s variable (#%d) not removed before the LMM system destruction.", demangled.c_str(),
              var->rank_);
     var_free(var);
   }
-  while ((cnst = extract_constraint()))
+  while (Constraint* cnst = extract_constraint())
     cnst_free(cnst);
 
   xbt_mallocator_free(variable_mallocator_);
@@ -208,8 +205,7 @@ void System::variable_free(Variable* var)
 
 void System::variable_free_all()
 {
-  Variable* var;
-  while ((var = extract_variable()))
+  while (Variable* var = extract_variable())
     variable_free(var);
 }
 
index c2ff738..08e8a77 100644 (file)
@@ -134,7 +134,6 @@ void LinkEnergyWifi::update(const simgrid::kernel::resource::NetworkAction&)
 
   auto const* wifi_link = static_cast<simgrid::kernel::resource::NetworkWifiLink*>(link_->get_impl());
 
-  const kernel::lmm::Variable* var;
   const kernel::lmm::Element* elem = nullptr;
 
   /**
@@ -147,7 +146,7 @@ void LinkEnergyWifi::update(const simgrid::kernel::resource::NetworkAction&)
    * used by the flow with the longest active time since the previous update
    */
   double durUsage = 0;
-  while((var = wifi_link->get_constraint()->get_variable(&elem))) {
+  while (const auto* var = wifi_link->get_constraint()->get_variable(&elem)) {
     auto* action = static_cast<kernel::resource::NetworkWifiAction*>(var->get_id());
     XBT_DEBUG("cost: %f action value: %f link rate 1: %f link rate 2: %f", action->get_cost(), action->get_variable()->get_value(), wifi_link->get_host_rate(&action->get_src()),wifi_link->get_host_rate(&action->get_dst()));
 
index 97f826d..ca6d7bf 100644 (file)
@@ -215,16 +215,14 @@ void Global::run_all_actors()
 void Global::wake_all_waiting_actors() const
 {
   for (auto const& model : simgrid::kernel::EngineImpl::get_instance()->get_all_models()) {
-    kernel::resource::Action* action;
-
     XBT_DEBUG("Handling the failed actions (if any)");
-    while ((action = model->extract_failed_action())) {
+    while (auto* action = model->extract_failed_action()) {
       XBT_DEBUG("   Handling Action %p", action);
       if (action->get_activity() != nullptr)
         kernel::activity::ActivityImplPtr(action->get_activity())->post();
     }
     XBT_DEBUG("Handling the terminated actions (if any)");
-    while ((action = model->extract_done_action())) {
+    while (auto* action = model->extract_done_action()) {
       XBT_DEBUG("   Handling Action %p", action);
       if (action->get_activity() == nullptr)
         XBT_DEBUG("probably vcpu's action %p, skip", action);
index 8570cff..e11e314 100644 (file)
@@ -86,13 +86,12 @@ bool CpuCas01::is_used() const
 /** @brief take into account changes of speed (either load or max) */
 void CpuCas01::on_speed_change()
 {
-  const lmm::Variable* var;
   const lmm::Element* elem = nullptr;
 
   get_model()->get_maxmin_system()->update_constraint_bound(get_constraint(),
                                                             get_core_count() * speed_.scale * speed_.peak);
-  while ((var = get_constraint()->get_variable(&elem))) {
-    const CpuCas01Action* action = static_cast<CpuCas01Action*>(var->get_id());
+  while (const auto* var = get_constraint()->get_variable(&elem)) {
+    const auto* action = static_cast<CpuCas01Action*>(var->get_id());
 
     get_model()->get_maxmin_system()->update_variable_bound(action->get_variable(),
                                                             action->requested_core() * speed_.scale * speed_.peak);
@@ -121,14 +120,12 @@ void CpuCas01::apply_event(profile::Event* event, double value)
         get_iface()->turn_on();
       }
     } else {
-      const lmm::Constraint* cnst = get_constraint();
-      const lmm::Variable* var;
       const lmm::Element* elem = nullptr;
       double date              = surf_get_clock();
 
       get_iface()->turn_off();
 
-      while ((var = cnst->get_variable(&elem))) {
+      while (const auto* var = get_constraint()->get_variable(&elem)) {
         Action* action = var->get_id();
 
         if (action->get_state() == Action::State::INITED || action->get_state() == Action::State::STARTED ||
index f70895c..c71a379 100644 (file)
@@ -367,11 +367,10 @@ void NetworkCm02Link::set_bandwidth(double value)
   if (sg_weight_S_parameter > 0) {
     double delta = sg_weight_S_parameter / value - sg_weight_S_parameter / (bandwidth_.peak * bandwidth_.scale);
 
-    const kernel::lmm::Variable* var;
     const kernel::lmm::Element* elem     = nullptr;
     const kernel::lmm::Element* nextelem = nullptr;
     int numelem                          = 0;
-    while ((var = get_constraint()->get_variable_safe(&elem, &nextelem, &numelem))) {
+    while (const auto* var = get_constraint()->get_variable_safe(&elem, &nextelem, &numelem)) {
       auto* action = static_cast<NetworkCm02Action*>(var->get_id());
       action->sharing_penalty_ += delta;
       if (not action->is_suspended())
@@ -385,7 +384,6 @@ LinkImpl* NetworkCm02Link::set_latency(double value)
   latency_check(value);
 
   double delta = value - latency_.peak;
-  const kernel::lmm::Variable* var;
   const kernel::lmm::Element* elem     = nullptr;
   const kernel::lmm::Element* nextelem = nullptr;
   int numelem                          = 0;
@@ -393,7 +391,7 @@ LinkImpl* NetworkCm02Link::set_latency(double value)
   latency_.scale = 1.0;
   latency_.peak  = value;
 
-  while ((var = get_constraint()->get_variable_safe(&elem, &nextelem, &numelem))) {
+  while (const auto* var = get_constraint()->get_variable_safe(&elem, &nextelem, &numelem)) {
     auto* action = static_cast<NetworkCm02Action*>(var->get_id());
     action->lat_current_ += delta;
     action->sharing_penalty_ += delta;
index 31147f7..de68776 100644 (file)
@@ -138,10 +138,9 @@ void LinkImpl::turn_off()
     Resource::turn_off();
     s4u::Link::on_state_change(this->piface_);
 
-    const kernel::lmm::Variable* var;
     const kernel::lmm::Element* elem = nullptr;
     double now                       = surf_get_clock();
-    while ((var = get_constraint()->get_variable(&elem))) {
+    while (const auto* var = get_constraint()->get_variable(&elem)) {
       Action* action = var->get_id();
       if (action->get_state() == Action::State::INITED || action->get_state() == Action::State::STARTED) {
         action->set_finish_time(now);
index 14fb47d..027300f 100644 (file)
@@ -282,11 +282,10 @@ bool CpuL07::is_used() const
 /** @brief take into account changes of speed (either load or max) */
 void CpuL07::on_speed_change()
 {
-  const kernel::lmm::Variable* var;
   const kernel::lmm::Element* elem = nullptr;
 
   get_model()->get_maxmin_system()->update_constraint_bound(get_constraint(), speed_.peak * speed_.scale);
-  while ((var = get_constraint()->get_variable(&elem))) {
+  while (const auto* var = get_constraint()->get_variable(&elem)) {
     const kernel::resource::Action* action = var->get_id();
 
     get_model()->get_maxmin_system()->update_variable_bound(action->get_variable(), speed_.scale * speed_.peak);
@@ -368,13 +367,11 @@ void LinkL07::set_bandwidth(double value)
 kernel::resource::LinkImpl* LinkL07::set_latency(double value)
 {
   latency_check(value);
-  const kernel::lmm::Variable* var;
-  L07Action* action;
   const kernel::lmm::Element* elem = nullptr;
 
   latency_.peak = value;
-  while ((var = get_constraint()->get_variable(&elem))) {
-    action = static_cast<L07Action*>(var->get_id());
+  while (const auto* var = get_constraint()->get_variable(&elem)) {
+    auto* action = static_cast<L07Action*>(var->get_id());
     action->updateBound();
   }
   return this;
index c5b9139..771f6a8 100644 (file)
@@ -29,10 +29,9 @@ void surf_presolve()
     if (next_event_date > NOW)
       break;
 
-    simgrid::kernel::profile::Event* event;
     double value                                  = -1.0;
     simgrid::kernel::resource::Resource* resource = nullptr;
-    while ((event = simgrid::kernel::profile::future_evt_set.pop_leq(next_event_date, &value, &resource))) {
+    while (auto* event = simgrid::kernel::profile::future_evt_set.pop_leq(next_event_date, &value, &resource)) {
       if (value >= 0)
         resource->apply_event(event, value);
     }
@@ -67,7 +66,6 @@ double surf_solve(double max_date)
   double time_delta                             = -1.0; /* duration */
   double value                                  = -1.0;
   simgrid::kernel::resource::Resource* resource = nullptr;
-  simgrid::kernel::profile::Event* event        = nullptr;
 
   if (max_date != -1.0) {
     xbt_assert(max_date >= NOW, "You asked to simulate up to %f, but that's in the past already", max_date);
@@ -130,7 +128,7 @@ double surf_solve(double max_date)
 
     XBT_DEBUG("Updating models (min = %g, NOW = %g, next_event_date = %g)", time_delta, NOW, next_event_date);
 
-    while ((event = simgrid::kernel::profile::future_evt_set.pop_leq(next_event_date, &value, &resource))) {
+    while (auto* event = simgrid::kernel::profile::future_evt_set.pop_leq(next_event_date, &value, &resource)) {
       if (resource->is_used() || (watched_hosts().find(resource->get_cname()) != watched_hosts().end())) {
         time_delta = next_event_date - NOW;
         XBT_DEBUG("This event invalidates the next_occurring_event() computation of models. Next event set to %f",