1 /* Copyright (c) 2004-2021. The SimGrid Team. All rights reserved. */
3 /* This program is free software; you can redistribute it and/or modify it
4 * under the terms of the license (GNU LGPL) which comes with this package. */
6 #ifndef SIMGRID_KERNEL_RESOURCE_MODEL_HPP
7 #define SIMGRID_KERNEL_RESOURCE_MODEL_HPP
10 #include <simgrid/kernel/resource/Action.hpp>
11 #include <unordered_map>
17 /** @ingroup SURF_interface
18 * @brief SURF model interface class
19 * @details A model is an object which handle the interactions between its Resources and its Actions
21 class XBT_PUBLIC Model {
23 /** @brief Possible model types */
25 HOST, /**< Host models: see surf_host_model_description for more details */
26 NETWORK, /**< Network models: see surf_network_model_description for more details */
27 CPU, /**< CPU models: see surf_cpu_model_description for more details */
28 DISK, /**< Disk models: see surf_disk_model_description for more details */
32 /** @brief Possible update mechanisms */
33 enum class UpdateAlgo {
34 FULL, /**< Full update mechanism: the remaining time of every action is recomputed at each step */
35 LAZY /**< Lazy update mechanism: only the modified actions get recomputed.
36 It may be slower than full if your system is tightly coupled to the point where every action
37 gets recomputed anyway. In that case, you'd better not try to be cleaver with lazy and go for
38 a simple full update. */
41 explicit Model(Model::UpdateAlgo algo);
42 Model(const Model&) = delete;
43 Model& operator=(const Model&) = delete;
47 bool is_update_lazy() const { return update_algorithm_ == UpdateAlgo::LAZY; }
49 /** @brief Get the set of [actions](@ref Action) in *inited* state */
50 Action::StateSet* get_inited_action_set() { return &inited_action_set_; }
52 /** @brief Get the set of [actions](@ref Action) in *started* state */
53 Action::StateSet* get_started_action_set() { return &started_action_set_; }
55 /** @brief Get the set of [actions](@ref Action) in *failed* state */
56 Action::StateSet* get_failed_action_set() { return &failed_action_set_; }
58 /** @brief Get the set of [actions](@ref Action) in *finished* state */
59 Action::StateSet* get_finished_action_set() { return &finished_action_set_; }
61 /** @brief Get the set of [actions](@ref Action) in *ignored* state */
62 Action::StateSet* get_ignored_action_set() { return &ignored_action_set_; }
64 /** @brief Get the set of modified [actions](@ref Action) */
65 Action::ModifiedSet* get_modified_set() const;
67 /** @brief Get the maxmin system of the current Model */
68 lmm::System* get_maxmin_system() const { return maxmin_system_.get(); }
70 /** @brief Set the maxmin system of the current Model */
71 void set_maxmin_system(lmm::System* system);
73 /** @brief Get the update algorithm of the current Model */
74 XBT_ATTRIB_DEPRECATED_v329("Please use is_update_lazy()") UpdateAlgo get_update_algorithm() const
76 return update_algorithm_;
79 /** @brief Get Action heap */
80 ActionHeap& get_action_heap() { return action_heap_; }
83 * @brief Share the resources between the actions
85 * @param now The current time of the simulation
86 * @return The delta of time till the next action will finish
88 virtual double next_occurring_event(double now);
89 virtual double next_occurring_event_lazy(double now);
90 virtual double next_occurring_event_full(double now);
92 XBT_ATTRIB_DEPRECATED_v329("Please use next_occurring_event()") virtual double next_occuring_event(double now) final
94 return next_occurring_event(now);
96 XBT_ATTRIB_DEPRECATED_v329("Please use next_occurring_event_lazy()") virtual double next_occuring_event_lazy(
99 return next_occurring_event_lazy(now);
101 XBT_ATTRIB_DEPRECATED_v329("Please use next_occurring_event_full()") virtual double next_occuring_event_full(
104 return next_occurring_event_full(now);
108 Action* extract_action(Action::StateSet* list);
111 Action* extract_done_action();
112 Action* extract_failed_action();
115 * @brief Update action to the current time
117 * @param now The current time of the simulation
118 * @param delta The delta of time since the last update
120 virtual void update_actions_state(double now, double delta);
121 virtual void update_actions_state_lazy(double now, double delta);
122 virtual void update_actions_state_full(double now, double delta);
124 /** @brief Returns whether this model have an idempotent share_resource()
126 * The only model that is not is ns-3: computing the next timestamp moves the model up to that point,
127 * so we need to call it only when the next timestamp of other sources is computed.
129 virtual bool next_occurring_event_is_idempotent() { return true; }
131 XBT_ATTRIB_DEPRECATED_v329(
132 "Please use next_occurring_event_is_idempotent()") virtual bool next_occuring_event_is_idempotent() final
134 return next_occurring_event_is_idempotent();
138 std::unique_ptr<lmm::System> maxmin_system_;
139 const UpdateAlgo update_algorithm_;
140 Action::StateSet inited_action_set_; /**< Created not started */
141 Action::StateSet started_action_set_; /**< Started not done */
142 Action::StateSet failed_action_set_; /**< Done with failure */
143 Action::StateSet finished_action_set_; /**< Done successful */
144 Action::StateSet ignored_action_set_; /**< not considered (failure detectors?) */
146 ActionHeap action_heap_;
149 } // namespace resource
150 } // namespace kernel
151 } // namespace simgrid
153 /** @ingroup SURF_models
154 * @brief List of initialized models
156 XBT_PUBLIC_DATA std::vector<simgrid::kernel::resource::Model*> all_existing_models;
157 /** @ingroup SURF_models
158 * @brief Map of initialized models by category
161 std::unordered_map<simgrid::kernel::resource::Model::Type, std::vector<simgrid::kernel::resource::Model*>>