From 0ebbe45d4b9227f6ac08b04c57eaeb684a1d9201 Mon Sep 17 00:00:00 2001 From: Bruno Donassolo Date: Wed, 16 Mar 2022 12:15:38 +0100 Subject: [PATCH] Move common part for selective_update to System class. And 1 more private variable in System \o/ --- src/kernel/lmm/System.cpp | 19 ++++++++++++++++++- src/kernel/lmm/System.hpp | 7 +++++-- src/kernel/lmm/bmf.cpp | 10 ---------- src/kernel/lmm/maxmin.cpp | 3 --- src/kernel/resource/Model.cpp | 14 ++++++++------ 5 files changed, 31 insertions(+), 22 deletions(-) diff --git a/src/kernel/lmm/System.cpp b/src/kernel/lmm/System.cpp index 3902992b50..66408e415f 100644 --- a/src/kernel/lmm/System.cpp +++ b/src/kernel/lmm/System.cpp @@ -464,6 +464,11 @@ void System::print() const } } +resource::Action::ModifiedSet* System::get_modified_action_set() const +{ + return modified_set_.get(); +} + void System::solve() { if (not modified_) @@ -472,8 +477,20 @@ void System::solve() do_solve(); modified_ = false; - if (selective_update_active) + if (selective_update_active) { + /* update list of modified variables */ + for (const Constraint& cnst : modified_constraint_set) { + for (const Element& elem : cnst.enabled_element_set_) { + if (elem.consumption_weight > 0) { + resource::Action* action = elem.variable->id_; + if (not action->is_within_modified_set()) + modified_set_->push_back(*action); + } + } + } + /* clear list of modified constraint */ remove_all_modified_cnst_set(); + } if (XBT_LOG_ISENABLED(ker_lmm, xbt_log_priority_debug)) { print(); diff --git a/src/kernel/lmm/System.hpp b/src/kernel/lmm/System.hpp index fda28f4fa8..bbdba3a350 100644 --- a/src/kernel/lmm/System.hpp +++ b/src/kernel/lmm/System.hpp @@ -432,6 +432,9 @@ public: Variable* variable_new(resource::Action* id, double sharing_penalty, double bound = -1.0, size_t number_of_constraints = 1); + /** @brief Get the list of modified actions since last solve() */ + resource::Action::ModifiedSet* get_modified_action_set() const; + /** * @brief Free a variable * @param var The variable to free @@ -551,8 +554,6 @@ public: &Constraint::saturated_constraint_set_hook_>> saturated_constraint_set; - std::unique_ptr modified_set_ = nullptr; - protected: bool selective_update_active; /* flag to update partially the system only selecting changed portions */ boost::intrusive::list, @@ -572,6 +573,8 @@ private: constraint_set; xbt_mallocator_t variable_mallocator_ = xbt_mallocator_new(65536, System::variable_mallocator_new_f, System::variable_mallocator_free_f, nullptr); + + std::unique_ptr modified_set_ = nullptr; }; /** @} */ diff --git a/src/kernel/lmm/bmf.cpp b/src/kernel/lmm/bmf.cpp index 824bc5d4c1..7ec03e87b5 100644 --- a/src/kernel/lmm/bmf.cpp +++ b/src/kernel/lmm/bmf.cpp @@ -503,16 +503,6 @@ template void BmfSystem::bmf_solve(const CnstList& cnst_list) for (int i = 0; i < rho.size(); i++) { idx2Var_[i]->value_ = rho[i]; } - /* updating modified_set */ - for (const Constraint& cnst : cnst_list) { - for (const Element& elem : cnst.enabled_element_set_) { - if (elem.consumption_weight > 0) { - resource::Action* action = elem.variable->id_; - if (modified_set_ && not action->is_within_modified_set()) - modified_set_->push_back(*action); - } - } - } } } // namespace lmm diff --git a/src/kernel/lmm/maxmin.cpp b/src/kernel/lmm/maxmin.cpp index c9dbc84f99..c7611fa093 100644 --- a/src/kernel/lmm/maxmin.cpp +++ b/src/kernel/lmm/maxmin.cpp @@ -86,9 +86,6 @@ template void MaxMin::maxmin_solve(CnstList& cnst_list) cnst.usage_ = elem.consumption_weight / elem.variable->sharing_penalty_; elem.make_active(); - resource::Action* action = elem.variable->id_; - if (modified_set_ && not action->is_within_modified_set()) - modified_set_->push_back(*action); } } XBT_DEBUG("Constraint '%d' usage: %f remaining: %f concurrency: %i<=%i<=%i", cnst.rank_, cnst.usage_, diff --git a/src/kernel/resource/Model.cpp b/src/kernel/resource/Model.cpp index 9cb5faf053..1ae513a63c 100644 --- a/src/kernel/resource/Model.cpp +++ b/src/kernel/resource/Model.cpp @@ -27,7 +27,7 @@ Model* Model::set_update_algorithm(Model::UpdateAlgo algo) Action::ModifiedSet* Model::get_modified_set() const { - return maxmin_system_->modified_set_.get(); + return maxmin_system_->get_modified_action_set(); } void Model::set_maxmin_system(lmm::System* system) @@ -49,13 +49,15 @@ double Model::next_occurring_event(double now) double Model::next_occurring_event_lazy(double now) { - XBT_DEBUG("Before share resources, the size of modified actions set is %zu", maxmin_system_->modified_set_->size()); + XBT_DEBUG("Before share resources, the size of modified actions set is %zu", + maxmin_system_->get_modified_action_set()->size()); maxmin_system_->solve(); - XBT_DEBUG("After share resources, The size of modified actions set is %zu", maxmin_system_->modified_set_->size()); + Action::ModifiedSet* modified_action_set = maxmin_system_->get_modified_action_set(); + XBT_DEBUG("After share resources, The size of modified actions set is %zu", modified_action_set->size()); - while (not maxmin_system_->modified_set_->empty()) { - Action* action = &(maxmin_system_->modified_set_->front()); - maxmin_system_->modified_set_->pop_front(); + while (not modified_action_set->empty()) { + Action* action = &(modified_action_set->front()); + modified_action_set->pop_front(); ActionHeap::Type action_type = ActionHeap::Type::normal; if (action->get_state_set() != &started_action_set_) -- 2.20.1