#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 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_; }
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 */
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())
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();
}
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();
}
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();
}
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();
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
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();
{
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_;
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!");
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!");
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!");
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();
}
}
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
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);
}
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 {
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();
}
action->weight_ = latency;
action->latency_ = latency;
action->rate_ = rate;
- if (getUpdateMechanism() == UM_LAZY) {
+ if (getUpdateMechanism() == kernel::resource::Model::UpdateAlgo::Lazy) {
action->set_last_update();
}
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()