X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/f89671e0bd7450461d70d5ced6079123e73c2a63..bf14756466400d3bf9ba7c47d52d3f510cd2ac98:/src/kernel/lmm/maxmin.hpp diff --git a/src/kernel/lmm/maxmin.hpp b/src/kernel/lmm/maxmin.hpp index cc4ed51dbb..3cc65d62b0 100644 --- a/src/kernel/lmm/maxmin.hpp +++ b/src/kernel/lmm/maxmin.hpp @@ -1,4 +1,4 @@ -/* Copyright (c) 2004-2019. The SimGrid Team. All rights reserved. */ +/* Copyright (c) 2004-2021. The SimGrid Team. All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ @@ -8,12 +8,15 @@ #include "simgrid/kernel/resource/Action.hpp" #include "simgrid/s4u/Link.hpp" +#include "src/surf/surf_interface.hpp" #include "xbt/asserts.h" +#include "xbt/ex.h" #include "xbt/mallocator.h" #include #include #include +#include #include namespace simgrid { @@ -140,6 +143,12 @@ namespace lmm { */ class XBT_PUBLIC Element { public: + // Use rule-of-three, and implicitely disable the move constructor which should be 'noexcept' according to C++ Core + // Guidelines. + Element() = default; + Element(const Element&) = default; + ~Element() = default; + int get_concurrency() const; void decrease_concurrency(); void increase_concurrency(); @@ -184,6 +193,8 @@ public: /** @brief Unshare a constraint. */ void unshare() { sharing_policy_ = s4u::Link::SharingPolicy::FATPIPE; } + /** @brief Set how a constraint is shared */ + void set_sharing_policy(s4u::Link::SharingPolicy policy) { sharing_policy_ = policy; } /** @brief Check how a constraint is shared */ s4u::Link::SharingPolicy get_sharing_policy() const { return sharing_policy_; } @@ -238,7 +249,7 @@ public: * @param numelem parameter representing the number of elements to go * @return A variable associated to a constraint */ - Variable* get_variable_safe(const Element** elem, const Element** nextelem, int* numelem) const; + Variable* get_variable_safe(const Element** elem, const Element** nextelem, size_t* numelem) const; /** * @brief Get the data associated to a constraint @@ -260,24 +271,24 @@ public: boost::intrusive::list, &Element::active_element_set_hook>> active_element_set_; - double remaining_; - double usage_; + double remaining_ = 0.0; + double usage_ = 0.0; double bound_; // TODO MARTIN Check maximum value across resources at the end of simulation and give a warning is more than e.g. 500 - int concurrency_current_; /* The current concurrency */ - int concurrency_maximum_; /* The maximum number of (enabled and disabled) variables associated to the constraint at - * any given time (essentially for tracing)*/ + int concurrency_current_ = 0; /* The current concurrency */ + int concurrency_maximum_ = 0; /* The maximum number of (enabled and disabled) variables associated to the constraint + * at any given time (essentially for tracing)*/ - s4u::Link::SharingPolicy sharing_policy_; + s4u::Link::SharingPolicy sharing_policy_ = s4u::Link::SharingPolicy::SHARED; int rank_; // Only used in debug messages to identify the constraint - double lambda_; - double new_lambda_; - ConstraintLight* cnst_light_; + double lambda_ = 0.0; + double new_lambda_ = 0.0; + ConstraintLight* cnst_light_ = nullptr; private: static int next_rank_; // To give a separate rank_ to each constraint - int concurrency_limit_; /* The maximum number of variables that may be enabled at any time (stage variables if - * necessary) */ + int concurrency_limit_ = sg_concurrency_limit; /* The maximum number of variables that may be enabled at any time + * (stage variables if necessary) */ resource::Resource* id_; }; @@ -289,7 +300,7 @@ private: */ class XBT_PUBLIC Variable { public: - void initialize(resource::Action* id_value, double sharing_penalty, double bound_value, int number_of_constraints, + void initialize(resource::Action* id_value, double sharing_penalty, double bound_value, size_t number_of_constraints, unsigned visited_value); /** @brief Get the value of the variable after the last lmm solve */ @@ -312,7 +323,7 @@ public: Constraint* get_constraint(unsigned num) const { return num < cnsts_.size() ? cnsts_[num].constraint : nullptr; } /** - * @brief Get the weigth of the numth constraint associated to the variable + * @brief Get the weight of the numth constraint associated to the variable * @param num The rank of constraint we want to get * @return The numth constraint */ @@ -336,7 +347,7 @@ public: /** @brief Check if a variable can be enabled * Make sure to set staged_penalty before, if your intent is only to check concurrency */ - int can_enable() const { return staged_penalty_ > 0 && get_min_concurrency_slack() >= concurrency_share_; } + bool can_enable() const { return staged_penalty_ > 0 && get_min_concurrency_slack() >= concurrency_share_; } /* hookup to system */ boost::intrusive::list_member_hook<> variable_set_hook_; @@ -371,7 +382,7 @@ inline void Element::make_active() inline void Element::make_inactive() { if (active_element_set_hook.is_linked()) - simgrid::xbt::intrusive_erase(constraint->active_element_set_, *this); + xbt::intrusive_erase(constraint->active_element_set_, *this); } /** @@ -438,7 +449,7 @@ public: /** @brief Update a constraint bound */ void update_constraint_bound(Constraint * cnst, double bound); - int constraint_used(Constraint* cnst) { return cnst->active_constraint_set_hook_.is_linked(); } + int constraint_used(const Constraint* cnst) const { return cnst->active_constraint_set_hook_.is_linked(); } /** @brief Print the lmm system */ void print() const; @@ -475,9 +486,9 @@ private: void remove_variable(Variable * var) { if (var->variable_set_hook_.is_linked()) - simgrid::xbt::intrusive_erase(variable_set, *var); + xbt::intrusive_erase(variable_set, *var); if (var->saturated_variable_set_hook_.is_linked()) - simgrid::xbt::intrusive_erase(saturated_variable_set, *var); + xbt::intrusive_erase(saturated_variable_set, *var); } void make_constraint_active(Constraint * cnst) { @@ -487,9 +498,9 @@ private: void make_constraint_inactive(Constraint * cnst) { if (cnst->active_constraint_set_hook_.is_linked()) - simgrid::xbt::intrusive_erase(active_constraint_set, *cnst); + xbt::intrusive_erase(active_constraint_set, *cnst); if (cnst->modified_constraint_set_hook_.is_linked()) - simgrid::xbt::intrusive_erase(modified_constraint_set, *cnst); + xbt::intrusive_erase(modified_constraint_set, *cnst); } void enable_var(Variable * var); @@ -504,8 +515,8 @@ private: */ void update(Constraint * cnst, Variable * var, double value); - void update_modified_set(Constraint * cnst); - void update_modified_set_rec(Constraint * cnst); + void update_modified_set(Constraint* cnst); + void update_modified_set_rec(const Constraint* cnst); /** @brief Remove all constraints of the modified_constraint_set. */ void remove_all_modified_set(); @@ -528,9 +539,15 @@ public: &Constraint::saturated_constraint_set_hook_>> saturated_constraint_set; - resource::Action::ModifiedSet* modified_set_ = nullptr; + std::unique_ptr modified_set_ = nullptr; private: + using dyn_light_t = std::vector; + + //Data used in lmm::solve + std::vector cnst_light_vec; + dyn_light_t saturated_constraints; + bool selective_update_active; /* flag to update partially the system only selecting changed portions */ unsigned visited_counter_ = 1; /* used by System::update_modified_set() and System::remove_all_modified_set() to * cleverly (un-)flag the constraints (more details in these functions) */ @@ -546,19 +563,16 @@ private: class XBT_PUBLIC FairBottleneck : public System { public: - explicit FairBottleneck(bool selective_update) : System(selective_update) {} + using System::System; void solve() final { bottleneck_solve(); } private: void bottleneck_solve(); }; -XBT_PUBLIC System* make_new_maxmin_system(bool selective_update); -XBT_PUBLIC System* make_new_fair_bottleneck_system(bool selective_update); - /** @} */ -} -} -} +} // namespace lmm +} // namespace kernel +} // namespace simgrid #endif