Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of scm.gforge.inria.fr:/gitroot/simgrid/simgrid
authorMartin Quinson <martin.quinson@loria.fr>
Tue, 27 Mar 2018 19:50:05 +0000 (21:50 +0200)
committerMartin Quinson <martin.quinson@loria.fr>
Tue, 27 Mar 2018 20:58:01 +0000 (22:58 +0200)
1  2 
include/simgrid/kernel/resource/Model.hpp
src/kernel/resource/Model.cpp
src/surf/cpu_cas01.cpp
src/surf/network_cm02.cpp

@@@ -8,6 -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 {
   */
  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();
  
    /** @brief Get the maxmin system of the current Model */
    lmm::System* get_maxmin_system() const { return maxmin_system_; }
  
+   /** @brief Set the maxmin system of the current Model */
+   void set_maxmin_system(lmm::System* system) { maxmin_system_ = system; }
    /**
     * @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_; }
     */
    virtual bool nextOccuringEventIsIdempotent() { return true; }
  
- protected:
-   lmm::System* maxmin_system_ = nullptr;
  private:
 -  e_UM_t update_mechanism_        = UM_UNDEFINED;
+   lmm::System* maxmin_system_           = nullptr;
 +  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 */
@@@ -39,9 -39,9 +39,9 @@@ Action::ModifiedSet* Model::get_modifie
  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!");
@@@ -50,7 -50,7 +50,7 @@@
  double Model::next_occuring_event_lazy(double now)
  {
    XBT_DEBUG("Before share resources, the size of modified actions set is %zu", maxmin_system_->modified_set_->size());
-   lmm_solve(maxmin_system_);
+   maxmin_system_->lmm_solve();
    XBT_DEBUG("After share resources, The size of modified actions set is %zu", maxmin_system_->modified_set_->size());
  
    while (not maxmin_system_->modified_set_->empty()) {
  
  double Model::next_occuring_event_full(double /*now*/)
  {
-   maxmin_system_->solve_fun(maxmin_system_);
+   maxmin_system_->solve();
  
    double min = -1;
  
  
  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!");
diff --combined src/surf/cpu_cas01.cpp
@@@ -41,20 -41,20 +41,20 @@@ CpuCas01Model::CpuCas01Model() : simgri
    bool select = xbt_cfg_get_boolean("cpu/maxmin-selective-update");
  
    if (optim == "Full") {
 -    setUpdateMechanism(UM_FULL);
 +    setUpdateMechanism(Model::UpdateAlgo::Full);
    } else if (optim == "Lazy") {
+     xbt_assert(select || xbt_cfg_is_default_value("cpu/maxmin-selective-update"),
+                "You cannot disable cpu selective update when using the lazy update mechanism");
 +    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!");
 -    setUpdateMechanism(UM_LAZY);
    } else {
      xbt_die("Unsupported optimization (%s) for this model", optim.c_str());
    }
  
-   maxmin_system_ = new simgrid::kernel::lmm::System(select);
+   set_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();
+     get_maxmin_system()->modified_set_ = new kernel::resource::Action::ModifiedSet();
  }
  
  CpuCas01Model::~CpuCas01Model()
@@@ -181,7 -181,7 +181,7 @@@ CpuAction *CpuCas01::sleep(double durat
    }
  
    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 +201,7 @@@ CpuCas01Action::CpuCas01Action(kernel::
                  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);
    }
@@@ -94,7 -94,7 +94,7 @@@ void surf_network_model_init_Reno(
    xbt_cfg_setdefault_double("network/bandwidth-factor", 0.97);
    xbt_cfg_setdefault_double("network/weight-S", 20537);
  
-   surf_network_model = new simgrid::surf::NetworkCm02Model(&simgrid::kernel::lmm::lagrange_solve);
+   surf_network_model = new simgrid::surf::NetworkCm02Model(&simgrid::kernel::lmm::make_new_lagrange_system);
    all_existing_models->push_back(surf_network_model);
  }
  
@@@ -111,7 -111,7 +111,7 @@@ void surf_network_model_init_Reno2(
    xbt_cfg_setdefault_double("network/bandwidth-factor", 0.97);
    xbt_cfg_setdefault_double("network/weight-S", 20537);
  
-   surf_network_model = new simgrid::surf::NetworkCm02Model(&simgrid::kernel::lmm::lagrange_solve);
+   surf_network_model = new simgrid::surf::NetworkCm02Model(&simgrid::kernel::lmm::make_new_lagrange_system);
    all_existing_models->push_back(surf_network_model);
  }
  
@@@ -127,46 -127,40 +127,40 @@@ void surf_network_model_init_Vegas(
    xbt_cfg_setdefault_double("network/bandwidth-factor", 0.97);
    xbt_cfg_setdefault_double("network/weight-S", 20537);
  
-   surf_network_model = new simgrid::surf::NetworkCm02Model(&simgrid::kernel::lmm::lagrange_solve);
+   surf_network_model = new simgrid::surf::NetworkCm02Model(&simgrid::kernel::lmm::make_new_lagrange_system);
    all_existing_models->push_back(surf_network_model);
  }
  
  namespace simgrid {
  namespace surf {
  
- NetworkCm02Model::NetworkCm02Model()
-   :NetworkModel()
+ NetworkCm02Model::NetworkCm02Model(kernel::lmm::System* (*make_new_lmm_system)(bool)) : NetworkModel()
  {
    std::string optim = xbt_cfg_get_string("network/optim");
    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") {
+     xbt_assert(select || xbt_cfg_is_default_value("network/maxmin-selective-update"),
+                "You cannot disable network selective update when using the lazy update mechanism");
      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 {
      xbt_die("Unsupported optimization (%s) for this model. Accepted: Full, Lazy.", optim.c_str());
    }
  
-   maxmin_system_ = new simgrid::kernel::lmm::System(select);
+   set_maxmin_system(make_new_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();
- }
- NetworkCm02Model::NetworkCm02Model(void (*specificSolveFun)(kernel::lmm::System* self)) : NetworkCm02Model()
- {
-   maxmin_system_->solve_fun = specificSolveFun;
+     get_maxmin_system()->modified_set_ = new kernel::resource::Action::ModifiedSet();
  }
  
  LinkImpl* NetworkCm02Model::createLink(const std::string& name, double bandwidth, double latency,
                                         e_surf_link_sharing_policy_t policy)
  {
-   return new NetworkCm02Link(this, name, bandwidth, latency, policy, maxmin_system_);
+   return new NetworkCm02Link(this, name, bandwidth, latency, policy, get_maxmin_system());
  }
  
  void NetworkCm02Model::update_actions_state_lazy(double now, double /*delta*/)
      // if I am wearing a latency hat
      if (action->get_type() == kernel::resource::Action::Type::LATENCY) {
        XBT_DEBUG("Latency paid for action %p. Activating", action);
-       maxmin_system_->update_variable_weight(action->get_variable(), action->weight_);
+       get_maxmin_system()->update_variable_weight(action->get_variable(), action->weight_);
        action->heapRemove();
        action->set_last_update();
  
@@@ -222,7 -216,7 +216,7 @@@ void NetworkCm02Model::update_actions_s
          action.latency_ = 0.0;
        }
        if (action.latency_ <= 0.0 && not action.is_suspended())
-         maxmin_system_->update_variable_weight(action.get_variable(), action.weight_);
+         get_maxmin_system()->update_variable_weight(action.get_variable(), action.weight_);
      }
      if (TRACE_is_enabled()) {
        int n = action.get_variable()->get_number_of_constraint();
@@@ -282,7 -276,7 +276,7 @@@ kernel::resource::Action* NetworkCm02Mo
    action->weight_ = latency;
    action->latency_ = latency;
    action->rate_ = rate;
 -  if (getUpdateMechanism() == UM_LAZY) {
 +  if (getUpdateMechanism() == kernel::resource::Model::UpdateAlgo::Lazy) {
      action->set_last_update();
    }
  
    constraints_per_variable += back_route.size();
  
    if (action->latency_ > 0) {
-     action->set_variable(maxmin_system_->variable_new(action, 0.0, -1.0, constraints_per_variable));
+     action->set_variable(get_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()
                                                                             : kernel::resource::Action::Type::LATENCY);
      }
    } else
-     action->set_variable(maxmin_system_->variable_new(action, 1.0, -1.0, constraints_per_variable));
+     action->set_variable(get_maxmin_system()->variable_new(action, 1.0, -1.0, constraints_per_variable));
  
    if (action->rate_ < 0) {
-     maxmin_system_->update_variable_bound(
+     get_maxmin_system()->update_variable_bound(
          action->get_variable(), (action->latCurrent_ > 0) ? sg_tcp_gamma / (2.0 * action->latCurrent_) : -1.0);
    } else {
-     maxmin_system_->update_variable_bound(action->get_variable(),
-                                           (action->latCurrent_ > 0)
-                                               ? std::min(action->rate_, sg_tcp_gamma / (2.0 * action->latCurrent_))
-                                               : action->rate_);
+     get_maxmin_system()->update_variable_bound(action->get_variable(),
+                                                (action->latCurrent_ > 0)
+                                                    ? std::min(action->rate_, sg_tcp_gamma / (2.0 * action->latCurrent_))
+                                                    : action->rate_);
    }
  
    for (auto const& link : route)
-     maxmin_system_->expand(link->constraint(), action->get_variable(), 1.0);
+     get_maxmin_system()->expand(link->constraint(), action->get_variable(), 1.0);
  
    if (not back_route.empty()) { //  sg_network_crosstraffic was activated
      XBT_DEBUG("Crosstraffic active adding backward flow using 5%%");
      for (auto const& link : back_route)
-       maxmin_system_->expand(link->constraint(), action->get_variable(), .05);
+       get_maxmin_system()->expand(link->constraint(), action->get_variable(), .05);
  
      // Change concurrency_share here, if you want that cross-traffic is included in the SURF concurrency
      // (You would also have to change simgrid::kernel::lmm::Element::get_concurrency())