-/* Copyright (c) 2004-2019. The SimGrid Team. All rights reserved. */
+/* Copyright (c) 2004-2022. 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. */
#define SURF_MAXMIN_HPP
#include "simgrid/kernel/resource/Action.hpp"
+#include "simgrid/kernel/resource/Model.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 <boost/intrusive/list.hpp>
#include <cmath>
#include <limits>
+#include <memory>
#include <vector>
namespace simgrid {
*/
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();
*/
class XBT_PUBLIC Constraint {
public:
+ enum class SharingPolicy { NONLINEAR = 2, SHARED = 1, FATPIPE = 0 };
+
Constraint() = delete;
Constraint(resource::Resource* id_value, double bound_value);
/** @brief Unshare a constraint. */
- void unshare() { sharing_policy_ = s4u::Link::SharingPolicy::FATPIPE; }
+ void unshare() { sharing_policy_ = SharingPolicy::FATPIPE; }
+ /** @brief Set how a constraint is shared */
+ void set_sharing_policy(SharingPolicy policy, const s4u::NonLinearResourceCb& cb);
/** @brief Check how a constraint is shared */
- s4u::Link::SharingPolicy get_sharing_policy() const { return sharing_policy_; }
+ SharingPolicy get_sharing_policy() const { return sharing_policy_; }
/** @brief Get the usage of the constraint after the last lmm solve */
double get_usage() const;
* @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
double remaining_ = 0.0;
double usage_ = 0.0;
double bound_;
+ double dynamic_bound_ = 0.0; //!< dynamic bound for this constraint, defined by user's callback
// 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_ = 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::SHARED;
+ SharingPolicy sharing_policy_ = SharingPolicy::SHARED;
int rank_; // Only used in debug messages to identify the constraint
double lambda_ = 0.0;
double new_lambda_ = 0.0;
ConstraintLight* cnst_light_ = nullptr;
+ s4u::NonLinearResourceCb dyn_constraint_cb_;
private:
static int next_rank_; // To give a separate rank_ to each constraint
*/
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 */
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
*/
/** @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;
*/
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();
&Constraint::saturated_constraint_set_hook_>>
saturated_constraint_set;
- resource::Action::ModifiedSet* modified_set_ = nullptr;
+ std::unique_ptr<resource::Action::ModifiedSet> modified_set_ = nullptr;
private:
- typedef std::vector<int> dyn_light_t;
-
+ using dyn_light_t = std::vector<int>;
+
//Data used in lmm::solve
std::vector<ConstraintLight> cnst_light_vec;
dyn_light_t saturated_constraints;
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