Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
simplification commit
authorFrederic Suter <frederic.suter@cc.in2p3.fr>
Wed, 15 Jan 2020 11:40:08 +0000 (12:40 +0100)
committerFrederic Suter <frederic.suter@cc.in2p3.fr>
Wed, 15 Jan 2020 11:44:50 +0000 (12:44 +0100)
* Class methods do not need tu use accessor to own class field
* Prefer model->is_update_lazy() to
         model->get_update_algorithm == Model::UpdateAlgo::LAZY

include/simgrid/kernel/resource/Action.hpp
include/simgrid/kernel/resource/Model.hpp
src/kernel/resource/Action.cpp
src/kernel/resource/Model.cpp
src/surf/cpu_cas01.cpp
src/surf/network_cm02.cpp

index 89b2d6d..a8f2177 100644 (file)
@@ -207,7 +207,7 @@ public:
   /** @brief Get the state set in which the action is */
   StateSet* get_state_set() const { return state_set_; };
 
-  simgrid::kernel::resource::Model* get_model() const { return model_; }
+  Model* get_model() const { return model_; }
 
 private:
   StateSet* state_set_;
index 1eebd94..63c2542 100644 (file)
@@ -34,6 +34,8 @@ public:
 
   virtual ~Model();
 
+  bool is_update_lazy() { return update_algorithm_ == UpdateAlgo::LAZY; }
+
   /** @brief Get the set of [actions](@ref Action) in *inited* state */
   Action::StateSet* get_inited_action_set() { return &inited_action_set_; }
 
@@ -59,7 +61,10 @@ public:
   void set_maxmin_system(lmm::System* system);
 
   /** @brief Get the update algorithm of the current Model */
-  UpdateAlgo get_update_algorithm() const { return update_algorithm_; }
+  XBT_ATTRIB_DEPRECATED_v329("Please use is_update_lazy()") UpdateAlgo get_update_algorithm() const
+  {
+    return update_algorithm_;
+  }
 
   /** @brief Get Action heap */
   ActionHeap& get_action_heap() { return action_heap_; }
index 020d08f..2111104 100644 (file)
@@ -24,9 +24,9 @@ Action::Action(simgrid::kernel::resource::Model* model, double cost, bool failed
     : remains_(cost), start_time_(surf_get_clock()), cost_(cost), model_(model), variable_(var)
 {
   if (failed)
-    state_set_ = get_model()->get_failed_action_set();
+    state_set_ = model_->get_failed_action_set();
   else
-    state_set_ = get_model()->get_started_action_set();
+    state_set_ = model_->get_started_action_set();
 
   state_set_->push_back(*this);
 }
@@ -36,12 +36,12 @@ Action::~Action()
   if (state_set_hook_.is_linked())
     simgrid::xbt::intrusive_erase(*state_set_, *this);
   if (get_variable())
-    get_model()->get_maxmin_system()->variable_free(get_variable());
+    model_->get_maxmin_system()->variable_free(get_variable());
 
   /* remove from heap on need (ie, if selective update) */
-  get_model()->get_action_heap().remove(this);
+  model_->get_action_heap().remove(this);
   if (modified_set_hook_.is_linked())
-    simgrid::xbt::intrusive_erase(*get_model()->get_modified_set(), *this);
+    simgrid::xbt::intrusive_erase(*model_->get_modified_set(), *this);
 }
 
 void Action::finish(Action::State state)
@@ -102,10 +102,10 @@ void Action::set_bound(double bound)
 {
   XBT_IN("(%p,%g)", this, bound);
   if (variable_)
-    get_model()->get_maxmin_system()->update_variable_bound(variable_, bound);
+    model_->get_maxmin_system()->update_variable_bound(variable_, bound);
 
-  if (get_model()->get_update_algorithm() == Model::UpdateAlgo::LAZY && get_last_update() != surf_get_clock())
-    get_model()->get_action_heap().remove(this);
+  if (model_->is_update_lazy() && get_last_update() != surf_get_clock())
+    model_->get_action_heap().remove(this);
   XBT_OUT();
 }
 
@@ -117,28 +117,28 @@ void Action::ref()
 void Action::set_max_duration(double duration)
 {
   max_duration_ = duration;
-  if (get_model()->get_update_algorithm() == Model::UpdateAlgo::LAZY) // remove action from the heap
-    get_model()->get_action_heap().remove(this);
+  if (model_->is_update_lazy()) // remove action from the heap
+    model_->get_action_heap().remove(this);
 }
 
 void Action::set_sharing_penalty(double sharing_penalty)
 {
   XBT_IN("(%p,%g)", this, sharing_penalty);
   sharing_penalty_ = sharing_penalty;
-  get_model()->get_maxmin_system()->update_variable_penalty(get_variable(), sharing_penalty);
+  model_->get_maxmin_system()->update_variable_penalty(get_variable(), sharing_penalty);
 
-  if (get_model()->get_update_algorithm() == Model::UpdateAlgo::LAZY)
-    get_model()->get_action_heap().remove(this);
+  if (model_->is_update_lazy())
+    model_->get_action_heap().remove(this);
   XBT_OUT();
 }
 
 void Action::cancel()
 {
   set_state(Action::State::FAILED);
-  if (get_model()->get_update_algorithm() == Model::UpdateAlgo::LAZY) {
+  if (model_->is_update_lazy()) {
     if (modified_set_hook_.is_linked())
-      xbt::intrusive_erase(*get_model()->get_modified_set(), *this);
-    get_model()->get_action_heap().remove(this);
+      xbt::intrusive_erase(*model_->get_modified_set(), *this);
+    model_->get_action_heap().remove(this);
   }
 }
 
@@ -156,10 +156,10 @@ void Action::suspend()
 {
   XBT_IN("(%p)", this);
   if (suspended_ != SuspendStates::SLEEPING) {
-    get_model()->get_maxmin_system()->update_variable_penalty(get_variable(), 0.0);
-    if (get_model()->get_update_algorithm() == Model::UpdateAlgo::LAZY) {
-      get_model()->get_action_heap().remove(this);
-      if (state_set_ == get_model()->get_started_action_set() && sharing_penalty_ > 0) {
+    model_->get_maxmin_system()->update_variable_penalty(get_variable(), 0.0);
+    if (model_->is_update_lazy()) {
+      model_->get_action_heap().remove(this);
+      if (state_set_ == model_->get_started_action_set() && sharing_penalty_ > 0) {
         // If we have a lazy model, we need to update the remaining value accordingly
         update_remains_lazy(surf_get_clock());
       }
@@ -173,10 +173,10 @@ void Action::resume()
 {
   XBT_IN("(%p)", this);
   if (suspended_ != SuspendStates::SLEEPING) {
-    get_model()->get_maxmin_system()->update_variable_penalty(get_variable(), get_sharing_penalty());
+    model_->get_maxmin_system()->update_variable_penalty(get_variable(), get_sharing_penalty());
     suspended_ = SuspendStates::RUNNING;
-    if (get_model()->get_update_algorithm() == Model::UpdateAlgo::LAZY)
-      get_model()->get_action_heap().remove(this);
+    if (model_->is_update_lazy())
+      model_->get_action_heap().remove(this);
   }
   XBT_OUT();
 }
@@ -185,7 +185,7 @@ double Action::get_remains()
 {
   XBT_IN("(%p)", this);
   /* update remains before returning it */
-  if (get_model()->get_update_algorithm() == Model::UpdateAlgo::LAZY) /* update remains before return it */
+  if (model_->is_update_lazy()) /* update remains before return it */
     update_remains_lazy(surf_get_clock());
   XBT_OUT();
   return remains_;
index f54d8f7..640df1e 100644 (file)
@@ -46,7 +46,7 @@ double Model::next_occurring_event_lazy(double now)
   while (not maxmin_system_->modified_set_->empty()) {
     Action* action = &(maxmin_system_->modified_set_->front());
     maxmin_system_->modified_set_->pop_front();
-    bool max_duration_flag = false;
+    ActionHeap::Type action_type = ActionHeap::Type::normal;
 
     if (action->get_state_set() != &started_action_set_)
       continue;
@@ -74,7 +74,7 @@ double Model::next_occurring_event_lazy(double now)
         (min <= -1 || action->get_start_time() + action->get_max_duration() < min)) {
       // when the task will complete anyway because of the deadline if any
       min          = action->get_start_time() + action->get_max_duration();
-      max_duration_flag = true;
+      action_type  = ActionHeap::Type::max_duration;
     }
 
     XBT_DEBUG("Action(%p) corresponds to variable %d", action, action->get_variable()->rank_);
@@ -83,7 +83,7 @@ double Model::next_occurring_event_lazy(double now)
               action->get_start_time(), min, share, action->get_max_duration());
 
     if (min > -1) {
-      action_heap_.update(action, min, max_duration_flag ? ActionHeap::Type::max_duration : ActionHeap::Type::normal);
+      action_heap_.update(action, min, action_type);
       XBT_DEBUG("Insert at heap action(%p) min %f now %f", action, min, now);
     } else
       DIE_IMPOSSIBLE;
index ee5ffa4..a526b56 100644 (file)
@@ -64,7 +64,7 @@ CpuCas01Model::CpuCas01Model(Model::UpdateAlgo algo) : CpuModel(algo)
 
   bool select = config::get_value<bool>("cpu/maxmin-selective-update");
 
-  if (algo == Model::UpdateAlgo::LAZY) {
+  if (is_update_lazy()) {
     xbt_assert(select || config::is_default("cpu/maxmin-selective-update"),
                "You cannot disable cpu selective update when using the lazy update mechanism");
     select = true;
@@ -188,7 +188,7 @@ CpuAction* CpuCas01::sleep(double duration)
     action->set_state(Action::State::IGNORED);
 
   get_model()->get_maxmin_system()->update_variable_penalty(action->get_variable(), 0.0);
-  if (get_model()->get_update_algorithm() == Model::UpdateAlgo::LAZY) { // remove action from the heap
+  if (get_model()->is_update_lazy()) { // remove action from the heap
     get_model()->get_action_heap().remove(action);
     // this is necessary for a variable with weight 0 since such variables are ignored in lmm and we need to set its
     // max_duration correctly at the next call to share_resources
@@ -208,7 +208,7 @@ CpuCas01Action::CpuCas01Action(Model* model, double cost, bool failed, double sp
                 model->get_maxmin_system()->variable_new(this, 1.0 / requested_core, requested_core * speed, 1))
     , requested_core_(requested_core)
 {
-  if (model->get_update_algorithm() == Model::UpdateAlgo::LAZY)
+  if (model->is_update_lazy())
     set_last_update();
   model->get_maxmin_system()->expand(constraint, get_variable(), 1.0);
 }
index 94a7a5a..25b0ba3 100644 (file)
@@ -189,7 +189,7 @@ Action* NetworkCm02Model::communicate(s4u::Host* src, s4u::Host* dst, double siz
   action->latency_ = latency;
   action->rate_ = rate;
 
-  if (get_update_algorithm() == Model::UpdateAlgo::LAZY) {
+  if (is_update_lazy()) {
     action->set_last_update();
   }
 
@@ -214,7 +214,7 @@ Action* NetworkCm02Model::communicate(s4u::Host* src, s4u::Host* dst, double siz
 
   if (action->latency_ > 0) {
     action->set_variable(get_maxmin_system()->variable_new(action, 0.0, -1.0, constraints_per_variable));
-    if (get_update_algorithm() == Model::UpdateAlgo::LAZY) {
+    if (is_update_lazy()) {
       // add to the heap the event when the latency is payed
       double date = action->latency_ + action->get_last_update();