Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
enum class for Model::UpdateAlgo
authorMartin Quinson <martin.quinson@loria.fr>
Tue, 27 Mar 2018 11:54:46 +0000 (13:54 +0200)
committerMartin Quinson <martin.quinson@loria.fr>
Tue, 27 Mar 2018 11:54:46 +0000 (13:54 +0200)
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 dc228ad..8e744df 100644 (file)
@@ -8,19 +8,6 @@
 
 #include <simgrid/kernel/resource/Action.hpp>
 
-extern "C" {
-
-/** @brief Possible update mechanisms */
-enum e_UM_t {
-  UM_FULL,     /**< Full update mechanism: the remaining time of every action is recomputed at each step */
-  UM_LAZY,     /**< Lazy update mechanism: only the modified actions get recomputed.
-                    It may be slower than full if your system is tightly coupled to the point where every action
-                    gets recomputed anyway. In that case, you'd better not try to be cleaver with lazy and go for
-                    a simple full update.  */
-  UM_UNDEFINED /**< Mechanism not defined */
-};
-}
-
 namespace simgrid {
 namespace kernel {
 namespace resource {
@@ -31,6 +18,16 @@ namespace resource {
  */
 class XBT_PUBLIC Model {
 public:
+  /** @brief Possible update mechanisms */
+  enum class UpdateAlgo {
+    Full,        /**< Full update mechanism: the remaining time of every action is recomputed at each step */
+    Lazy,        /**< Lazy update mechanism: only the modified actions get recomputed.
+                         It may be slower than full if your system is tightly coupled to the point where every action
+                         gets recomputed anyway. In that case, you'd better not try to be cleaver with lazy and go for
+                         a simple full update.  */
+    UM_UNDEFINED /**< Mechanism not defined */
+  };
+
   Model();
   virtual ~Model();
 
@@ -56,8 +53,8 @@ public:
    * @brief Get the update mechanism of the current Model
    * @see e_UM_t
    */
-  e_UM_t getUpdateMechanism() const { return update_mechanism_; }
-  void setUpdateMechanism(e_UM_t mechanism) { update_mechanism_ = mechanism; }
+  UpdateAlgo getUpdateMechanism() const { return update_mechanism_; }
+  void setUpdateMechanism(UpdateAlgo mechanism) { update_mechanism_ = mechanism; }
 
   /** @brief Get Action heap */
   heap_type& getActionHeap() { return action_heap_; }
@@ -97,7 +94,7 @@ protected:
   lmm::System* maxmin_system_ = nullptr;
 
 private:
-  e_UM_t update_mechanism_        = UM_UNDEFINED;
+  UpdateAlgo update_mechanism_          = UpdateAlgo::UM_UNDEFINED;
   Action::StateSet* ready_action_set_   = new Action::StateSet(); /**< Actions in state SURF_ACTION_READY */
   Action::StateSet* running_action_set_ = new Action::StateSet(); /**< Actions in state SURF_ACTION_RUNNING */
   Action::StateSet* failed_action_set_  = new Action::StateSet(); /**< Actions in state SURF_ACTION_FAILED */
index 9de1225..9e64d25 100644 (file)
@@ -36,7 +36,7 @@ Action::~Action()
     simgrid::xbt::intrusive_erase(*state_set_, *this);
   if (get_variable())
     get_model()->get_maxmin_system()->variable_free(get_variable());
-  if (get_model()->getUpdateMechanism() == UM_LAZY) {
+  if (get_model()->getUpdateMechanism() == Model::UpdateAlgo::Lazy) {
     /* remove from heap */
     heapRemove();
     if (modified_set_hook_.is_linked())
@@ -101,7 +101,7 @@ void Action::set_bound(double bound)
   if (variable_)
     get_model()->get_maxmin_system()->update_variable_bound(variable_, bound);
 
-  if (get_model()->getUpdateMechanism() == UM_LAZY && get_last_update() != surf_get_clock())
+  if (get_model()->getUpdateMechanism() == Model::UpdateAlgo::Lazy && get_last_update() != surf_get_clock())
     heapRemove();
   XBT_OUT();
 }
@@ -119,7 +119,7 @@ void Action::ref()
 void Action::set_max_duration(double duration)
 {
   max_duration_ = duration;
-  if (get_model()->getUpdateMechanism() == UM_LAZY) // remove action from the heap
+  if (get_model()->getUpdateMechanism() == Model::UpdateAlgo::Lazy) // remove action from the heap
     heapRemove();
 }
 
@@ -129,7 +129,7 @@ void Action::set_priority(double weight)
   sharing_priority_ = weight;
   get_model()->get_maxmin_system()->update_variable_weight(get_variable(), weight);
 
-  if (get_model()->getUpdateMechanism() == UM_LAZY)
+  if (get_model()->getUpdateMechanism() == Model::UpdateAlgo::Lazy)
     heapRemove();
   XBT_OUT();
 }
@@ -137,7 +137,7 @@ void Action::set_priority(double weight)
 void Action::cancel()
 {
   set_state(Action::State::failed);
-  if (get_model()->getUpdateMechanism() == UM_LAZY) {
+  if (get_model()->getUpdateMechanism() == Model::UpdateAlgo::Lazy) {
     if (modified_set_hook_.is_linked())
       simgrid::xbt::intrusive_erase(*get_model()->get_modified_set(), *this);
     heapRemove();
@@ -159,7 +159,7 @@ void Action::suspend()
   XBT_IN("(%p)", this);
   if (suspended_ != SuspendStates::sleeping) {
     get_model()->get_maxmin_system()->update_variable_weight(get_variable(), 0.0);
-    if (get_model()->getUpdateMechanism() == UM_LAZY) {
+    if (get_model()->getUpdateMechanism() == Model::UpdateAlgo::Lazy) {
       heapRemove();
       if (state_set_ == get_model()->get_running_action_set() && sharing_priority_ > 0) {
         // If we have a lazy model, we need to update the remaining value accordingly
@@ -177,7 +177,7 @@ void Action::resume()
   if (suspended_ != SuspendStates::sleeping) {
     get_model()->get_maxmin_system()->update_variable_weight(get_variable(), get_priority());
     suspended_ = SuspendStates::not_suspended;
-    if (get_model()->getUpdateMechanism() == UM_LAZY)
+    if (get_model()->getUpdateMechanism() == Model::UpdateAlgo::Lazy)
       heapRemove();
   }
   XBT_OUT();
@@ -223,7 +223,7 @@ double Action::get_remains()
 {
   XBT_IN("(%p)", this);
   /* update remains before return it */
-  if (get_model()->getUpdateMechanism() == UM_LAZY) /* update remains before return it */
+  if (get_model()->getUpdateMechanism() == Model::UpdateAlgo::Lazy) /* update remains before return it */
     update_remains_lazy(surf_get_clock());
   XBT_OUT();
   return remains_;
index 25a3ee6..ca29b99 100644 (file)
@@ -39,9 +39,9 @@ Action::ModifiedSet* Model::get_modified_set() const
 double Model::next_occuring_event(double now)
 {
   // FIXME: set the good function once and for all
-  if (update_mechanism_ == UM_LAZY)
+  if (update_mechanism_ == Model::UpdateAlgo::Lazy)
     return next_occuring_event_lazy(now);
-  else if (update_mechanism_ == UM_FULL)
+  else if (update_mechanism_ == Model::UpdateAlgo::Full)
     return next_occuring_event_full(now);
   else
     xbt_die("Invalid cpu update mechanism!");
@@ -140,9 +140,9 @@ double Model::next_occuring_event_full(double /*now*/)
 
 void Model::update_actions_state(double now, double delta)
 {
-  if (update_mechanism_ == UM_FULL)
+  if (update_mechanism_ == Model::UpdateAlgo::Full)
     update_actions_state_full(now, delta);
-  else if (update_mechanism_ == UM_LAZY)
+  else if (update_mechanism_ == Model::UpdateAlgo::Lazy)
     update_actions_state_lazy(now, delta);
   else
     xbt_die("Invalid cpu update mechanism!");
index 52d7f2c..78c279d 100644 (file)
@@ -41,9 +41,9 @@ CpuCas01Model::CpuCas01Model() : simgrid::surf::CpuModel()
   bool select = xbt_cfg_get_boolean("cpu/maxmin-selective-update");
 
   if (optim == "Full") {
-    setUpdateMechanism(UM_FULL);
+    setUpdateMechanism(Model::UpdateAlgo::Full);
   } else if (optim == "Lazy") {
-    setUpdateMechanism(UM_LAZY);
+    setUpdateMechanism(Model::UpdateAlgo::Lazy);
     select = true;
     xbt_assert(select || (xbt_cfg_is_default_value("cpu/maxmin-selective-update")),
                "Disabling selective update while using the lazy update mechanism is dumb!");
@@ -53,7 +53,7 @@ CpuCas01Model::CpuCas01Model() : simgrid::surf::CpuModel()
 
   maxmin_system_ = new simgrid::kernel::lmm::System(select);
 
-  if (getUpdateMechanism() == UM_LAZY)
+  if (getUpdateMechanism() == Model::UpdateAlgo::Lazy)
     maxmin_system_->modified_set_ = new kernel::resource::Action::ModifiedSet();
 }
 
@@ -181,7 +181,7 @@ CpuAction *CpuCas01::sleep(double duration)
   }
 
   model()->get_maxmin_system()->update_variable_weight(action->get_variable(), 0.0);
-  if (model()->getUpdateMechanism() == UM_LAZY) { // remove action from the heap
+  if (model()->getUpdateMechanism() == kernel::resource::Model::UpdateAlgo::Lazy) { // remove action from the heap
     action->heapRemove();
     // 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
@@ -201,7 +201,7 @@ CpuCas01Action::CpuCas01Action(kernel::resource::Model* model, double cost, bool
                 model->get_maxmin_system()->variable_new(this, 1.0 / requestedCore, requestedCore * speed, 1))
     , requestedCore_(requestedCore)
 {
-  if (model->getUpdateMechanism() == UM_LAZY) {
+  if (model->getUpdateMechanism() == kernel::resource::Model::UpdateAlgo::Lazy) {
     set_last_update();
     set_last_value(0.0);
   }
index e0c2bd9..521a176 100644 (file)
@@ -141,10 +141,10 @@ NetworkCm02Model::NetworkCm02Model()
   bool select = xbt_cfg_get_boolean("network/maxmin-selective-update");
 
   if (optim == "Full") {
-    setUpdateMechanism(UM_FULL);
+    setUpdateMechanism(kernel::resource::Model::UpdateAlgo::Full);
   } else if (optim == "Lazy") {
     select = true;
-    setUpdateMechanism(UM_LAZY);
+    setUpdateMechanism(kernel::resource::Model::UpdateAlgo::Lazy);
     xbt_assert(select || (xbt_cfg_is_default_value("network/maxmin-selective-update")),
                "You cannot disable selective update when using the lazy update mechanism");
   } else {
@@ -154,7 +154,7 @@ NetworkCm02Model::NetworkCm02Model()
   maxmin_system_ = new simgrid::kernel::lmm::System(select);
   loopback_     = NetworkCm02Model::createLink("__loopback__", 498000000, 0.000015, SURF_LINK_FATPIPE);
 
-  if (getUpdateMechanism() == UM_LAZY)
+  if (getUpdateMechanism() == kernel::resource::Model::UpdateAlgo::Lazy)
     maxmin_system_->modified_set_ = new kernel::resource::Action::ModifiedSet();
 }
 
@@ -282,7 +282,7 @@ kernel::resource::Action* NetworkCm02Model::communicate(s4u::Host* src, s4u::Hos
   action->weight_ = latency;
   action->latency_ = latency;
   action->rate_ = rate;
-  if (getUpdateMechanism() == UM_LAZY) {
+  if (getUpdateMechanism() == kernel::resource::Model::UpdateAlgo::Lazy) {
     action->set_last_update();
   }
 
@@ -305,7 +305,7 @@ kernel::resource::Action* NetworkCm02Model::communicate(s4u::Host* src, s4u::Hos
 
   if (action->latency_ > 0) {
     action->set_variable(maxmin_system_->variable_new(action, 0.0, -1.0, constraints_per_variable));
-    if (getUpdateMechanism() == UM_LAZY) {
+    if (getUpdateMechanism() == kernel::resource::Model::UpdateAlgo::Lazy) {
       // add to the heap the event when the latency is payed
       XBT_DEBUG("Added action (%p) one latency event at date %f", action, action->latency_ + action->get_last_update());
       action->heapInsert(action->latency_ + action->get_last_update(), route.empty()