From 8372ae97612f27b84e8d75aeeed9de0ba6d2ba6a Mon Sep 17 00:00:00 2001 From: Martin Quinson Date: Sat, 31 Mar 2018 22:48:24 +0200 Subject: [PATCH 1/1] make Model::update_algo a constant field, set at initialization only --- include/simgrid/kernel/resource/Model.hpp | 19 ++++++++----------- src/kernel/resource/Model.cpp | 11 +++++------ src/surf/HostImpl.hpp | 2 +- src/surf/StorageImpl.cpp | 2 +- src/surf/cpu_cas01.hpp | 2 +- src/surf/cpu_interface.hpp | 3 +-- src/surf/cpu_ti.hpp | 2 +- src/surf/network_cm02.cpp | 11 ++++------- src/surf/network_constant.hpp | 1 + src/surf/network_interface.hpp | 2 +- src/surf/network_ns3.cpp | 3 ++- src/surf/ptask_L07.cpp | 6 ++++-- 12 files changed, 30 insertions(+), 34 deletions(-) diff --git a/include/simgrid/kernel/resource/Model.hpp b/include/simgrid/kernel/resource/Model.hpp index b803d87a14..83076bebf1 100644 --- a/include/simgrid/kernel/resource/Model.hpp +++ b/include/simgrid/kernel/resource/Model.hpp @@ -20,16 +20,14 @@ 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. */ - Undefined /**< Mechanism not defined */ + 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. */ }; - Model(); - Model(Model::UpdateAlgo algo); + explicit Model(Model::UpdateAlgo algo); virtual ~Model(); @@ -55,8 +53,7 @@ public: void set_maxmin_system(lmm::System* system) { maxmin_system_ = system; } /** @brief Get the update mechanism of the current Model */ - UpdateAlgo getUpdateMechanism() const { return update_mechanism_; } - void setUpdateMechanism(UpdateAlgo mechanism) { update_mechanism_ = mechanism; } + UpdateAlgo getUpdateMechanism() const { return update_algorithm_; } /** @brief Get Action heap */ heap_type& getActionHeap() { return action_heap_; } @@ -94,7 +91,7 @@ public: private: lmm::System* maxmin_system_ = nullptr; - UpdateAlgo update_mechanism_ = UpdateAlgo::Undefined; + const UpdateAlgo update_algorithm_; 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 */ diff --git a/src/kernel/resource/Model.cpp b/src/kernel/resource/Model.cpp index e463d997be..ee43169796 100644 --- a/src/kernel/resource/Model.cpp +++ b/src/kernel/resource/Model.cpp @@ -12,8 +12,7 @@ namespace simgrid { namespace kernel { namespace resource { -Model::Model() = default; -Model::Model(Model::UpdateAlgo algo) : update_mechanism_(algo) {} +Model::Model(Model::UpdateAlgo algo) : update_algorithm_(algo) {} Model::~Model() { @@ -40,9 +39,9 @@ Action::ModifiedSet* Model::get_modified_set() const double Model::next_occuring_event(double now) { // FIXME: set the good function once and for all - if (update_mechanism_ == Model::UpdateAlgo::Lazy) + if (update_algorithm_ == Model::UpdateAlgo::Lazy) return next_occuring_event_lazy(now); - else if (update_mechanism_ == Model::UpdateAlgo::Full) + else if (update_algorithm_ == Model::UpdateAlgo::Full) return next_occuring_event_full(now); else xbt_die("Invalid cpu update mechanism!"); @@ -141,9 +140,9 @@ double Model::next_occuring_event_full(double /*now*/) void Model::update_actions_state(double now, double delta) { - if (update_mechanism_ == Model::UpdateAlgo::Full) + if (update_algorithm_ == Model::UpdateAlgo::Full) update_actions_state_full(now, delta); - else if (update_mechanism_ == Model::UpdateAlgo::Lazy) + else if (update_algorithm_ == Model::UpdateAlgo::Lazy) update_actions_state_lazy(now, delta); else xbt_die("Invalid cpu update mechanism!"); diff --git a/src/surf/HostImpl.hpp b/src/surf/HostImpl.hpp index 85db47a253..02b40c493e 100644 --- a/src/surf/HostImpl.hpp +++ b/src/surf/HostImpl.hpp @@ -33,7 +33,7 @@ namespace surf { */ class XBT_PRIVATE HostModel : public kernel::resource::Model { public: - HostModel() : Model() {} + HostModel() : Model(Model::UpdateAlgo::Full) {} virtual void ignore_empty_vm_in_pm_LMM(); virtual kernel::resource::Action* execute_parallel(int host_nb, sg_host_t* host_list, double* flops_amount, diff --git a/src/surf/StorageImpl.cpp b/src/surf/StorageImpl.cpp index 4d4d01afe9..2916346406 100644 --- a/src/surf/StorageImpl.cpp +++ b/src/surf/StorageImpl.cpp @@ -30,7 +30,7 @@ simgrid::xbt::signal *speedPerPstate, int core) override; diff --git a/src/surf/cpu_interface.hpp b/src/surf/cpu_interface.hpp index 00d095cb6b..81a9cb77bc 100644 --- a/src/surf/cpu_interface.hpp +++ b/src/surf/cpu_interface.hpp @@ -26,8 +26,7 @@ namespace surf { */ class XBT_PUBLIC CpuModel : public kernel::resource::Model { public: - CpuModel(kernel::resource::Model::UpdateAlgo algo) : Model(algo) {} - CpuModel() : Model() {} + explicit CpuModel(kernel::resource::Model::UpdateAlgo algo) : Model(algo) {} /** * @brief Create a Cpu diff --git a/src/surf/cpu_ti.hpp b/src/surf/cpu_ti.hpp index 982727d261..df6c050613 100644 --- a/src/surf/cpu_ti.hpp +++ b/src/surf/cpu_ti.hpp @@ -139,7 +139,7 @@ typedef boost::intrusive::list CpuTiList; *********/ class CpuTiModel : public CpuModel { public: - CpuTiModel() = default; + CpuTiModel() : CpuModel(Model::UpdateAlgo::Full){}; ~CpuTiModel() override; Cpu* createCpu(simgrid::s4u::Host* host, std::vector* speed_per_pstate, int core) override; double next_occuring_event(double now) override; diff --git a/src/surf/network_cm02.cpp b/src/surf/network_cm02.cpp index 41a9f4b266..aa9df6d85e 100644 --- a/src/surf/network_cm02.cpp +++ b/src/surf/network_cm02.cpp @@ -134,20 +134,17 @@ void surf_network_model_init_Vegas() namespace simgrid { namespace surf { -NetworkCm02Model::NetworkCm02Model(kernel::lmm::System* (*make_new_lmm_system)(bool)) : NetworkModel() +NetworkCm02Model::NetworkCm02Model(kernel::lmm::System* (*make_new_lmm_system)(bool)) + : NetworkModel(xbt_cfg_get_string("network/optim") == "Full" ? kernel::resource::Model::UpdateAlgo::Full + : kernel::resource::Model::UpdateAlgo::Lazy) { std::string optim = xbt_cfg_get_string("network/optim"); bool select = xbt_cfg_get_boolean("network/maxmin-selective-update"); - if (optim == "Full") { - setUpdateMechanism(kernel::resource::Model::UpdateAlgo::Full); - } else if (optim == "Lazy") { + 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(kernel::resource::Model::UpdateAlgo::Lazy); - } else { - xbt_die("Unsupported optimization (%s) for this model. Accepted: Full, Lazy.", optim.c_str()); } set_maxmin_system(make_new_lmm_system(select)); diff --git a/src/surf/network_constant.hpp b/src/surf/network_constant.hpp index 23c37acd40..151b2d072a 100644 --- a/src/surf/network_constant.hpp +++ b/src/surf/network_constant.hpp @@ -25,6 +25,7 @@ namespace simgrid { *********/ class NetworkConstantModel : public NetworkModel { public: + NetworkConstantModel() : NetworkModel(Model::UpdateAlgo::Full) {} kernel::resource::Action* communicate(simgrid::s4u::Host* src, simgrid::s4u::Host* dst, double size, double rate) override; double next_occuring_event(double now) override; diff --git a/src/surf/network_interface.hpp b/src/surf/network_interface.hpp index c26d753636..a04496ecf8 100644 --- a/src/surf/network_interface.hpp +++ b/src/surf/network_interface.hpp @@ -34,7 +34,7 @@ namespace surf { class NetworkModel : public kernel::resource::Model { public: /** @brief Constructor */ - NetworkModel() : Model() {} + explicit NetworkModel(kernel::resource::Model::UpdateAlgo algo) : Model(algo) {} /** @brief Destructor */ ~NetworkModel() override; diff --git a/src/surf/network_ns3.cpp b/src/surf/network_ns3.cpp index f1ddedfe91..f13305591c 100644 --- a/src/surf/network_ns3.cpp +++ b/src/surf/network_ns3.cpp @@ -147,7 +147,8 @@ static simgrid::config::Flag namespace simgrid { namespace surf { -NetworkNS3Model::NetworkNS3Model() : NetworkModel() { +NetworkNS3Model::NetworkNS3Model() : NetworkModel(Model::UpdateAlgo::Full) +{ xbt_assert(not sg_link_energy_is_inited(), "LinkEnergy plugin and NS3 network models are not compatible. Are you looking for Ecofen, maybe?"); diff --git a/src/surf/ptask_L07.cpp b/src/surf/ptask_L07.cpp index 2a348a9429..d0c47f5f20 100644 --- a/src/surf/ptask_L07.cpp +++ b/src/surf/ptask_L07.cpp @@ -46,7 +46,8 @@ HostL07Model::~HostL07Model() delete surf_cpu_model_pm; } -CpuL07Model::CpuL07Model(HostL07Model* hmodel, kernel::lmm::System* sys) : CpuModel(), hostModel_(hmodel) +CpuL07Model::CpuL07Model(HostL07Model* hmodel, kernel::lmm::System* sys) + : CpuModel(Model::UpdateAlgo::Full), hostModel_(hmodel) { set_maxmin_system(sys); } @@ -56,7 +57,8 @@ CpuL07Model::~CpuL07Model() set_maxmin_system(nullptr); } -NetworkL07Model::NetworkL07Model(HostL07Model* hmodel, kernel::lmm::System* sys) : NetworkModel(), hostModel_(hmodel) +NetworkL07Model::NetworkL07Model(HostL07Model* hmodel, kernel::lmm::System* sys) + : NetworkModel(Model::UpdateAlgo::Full), hostModel_(hmodel) { set_maxmin_system(sys); loopback_ = NetworkL07Model::createLink("__loopback__", 498000000, 0.000015, SURF_LINK_FATPIPE); -- 2.20.1