Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fix misspelling of "occurring".
[simgrid.git] / include / simgrid / kernel / resource / Model.hpp
1 /* Copyright (c) 2004-2019. The SimGrid Team. All rights reserved.          */
2
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. */
5
6 #ifndef SIMGRID_KERNEL_RESOURCE_MODEL_HPP
7 #define SIMGRID_KERNEL_RESOURCE_MODEL_HPP
8
9 #include <memory>
10 #include <simgrid/kernel/resource/Action.hpp>
11
12 namespace simgrid {
13 namespace kernel {
14 namespace resource {
15
16 /** @ingroup SURF_interface
17  * @brief SURF model interface class
18  * @details A model is an object which handle the interactions between its Resources and its Actions
19  */
20 class XBT_PUBLIC Model {
21 public:
22   /** @brief Possible update mechanisms */
23   enum class UpdateAlgo {
24     FULL, /**< Full update mechanism: the remaining time of every action is recomputed at each step */
25     LAZY  /**< Lazy update mechanism: only the modified actions get recomputed.
26                    It may be slower than full if your system is tightly coupled to the point where every action
27                    gets recomputed anyway. In that case, you'd better not try to be cleaver with lazy and go for
28                    a simple full update.  */
29   };
30
31   explicit Model(Model::UpdateAlgo algo);
32   Model(const Model&) = delete;
33   Model& operator=(const Model&) = delete;
34
35   virtual ~Model();
36
37   /** @brief Get the set of [actions](@ref Action) in *inited* state */
38   Action::StateSet* get_inited_action_set() { return &inited_action_set_; }
39
40   /** @brief Get the set of [actions](@ref Action) in *started* state */
41   Action::StateSet* get_started_action_set() { return &started_action_set_; }
42
43   /** @brief Get the set of [actions](@ref Action) in *failed* state */
44   Action::StateSet* get_failed_action_set() { return &failed_action_set_; }
45
46   /** @brief Get the set of [actions](@ref Action) in *finished* state */
47   Action::StateSet* get_finished_action_set() { return &finished_action_set_; }
48
49   /** @brief Get the set of [actions](@ref Action) in *ignored* state */
50   Action::StateSet* get_ignored_action_set() { return &ignored_action_set_; }
51
52   /** @brief Get the set of modified [actions](@ref Action) */
53   Action::ModifiedSet* get_modified_set() const;
54
55   /** @brief Get the maxmin system of the current Model */
56   lmm::System* get_maxmin_system() const { return maxmin_system_.get(); }
57
58   /** @brief Set the maxmin system of the current Model */
59   void set_maxmin_system(lmm::System* system);
60
61   /** @brief Get the update algorithm of the current Model */
62   UpdateAlgo get_update_algorithm() const { return update_algorithm_; }
63
64   /** @brief Get Action heap */
65   ActionHeap& get_action_heap() { return action_heap_; }
66
67   /**
68    * @brief Share the resources between the actions
69    *
70    * @param now The current time of the simulation
71    * @return The delta of time till the next action will finish
72    */
73   virtual double next_occurring_event(double now);
74   virtual double next_occurring_event_lazy(double now);
75   virtual double next_occurring_event_full(double now);
76
77   XBT_ATTRIB_DEPRECATED_v329("Please use next_occurring_event()") double next_occuring_event(double now)
78   {
79     return next_occurring_event(now);
80   }
81   XBT_ATTRIB_DEPRECATED_v329("Please use next_occurring_event_lazy()") double next_occuring_event_lazy(double now)
82   {
83     return next_occurring_event_lazy(now);
84   }
85   XBT_ATTRIB_DEPRECATED_v329("Please use next_occurring_event_full()") double next_occuring_event_full(double now)
86   {
87     return next_occurring_event_full(now);
88   }
89
90 private:
91   Action* extract_action(Action::StateSet* list);
92
93 public:
94   Action* extract_done_action();
95   Action* extract_failed_action();
96
97   /**
98    * @brief Update action to the current time
99    *
100    * @param now The current time of the simulation
101    * @param delta The delta of time since the last update
102    */
103   virtual void update_actions_state(double now, double delta);
104   virtual void update_actions_state_lazy(double now, double delta);
105   virtual void update_actions_state_full(double now, double delta);
106
107   /** @brief Returns whether this model have an idempotent share_resource()
108    *
109    * The only model that is not is ns-3: computing the next timestamp moves the model up to that point,
110    * so we need to call it only when the next timestamp of other sources is computed.
111    */
112   virtual bool next_occurring_event_is_idempotent() { return true; }
113
114   XBT_ATTRIB_DEPRECATED_v329("Please use next_occurring_event_is_idempotent()") bool next_occuring_event_is_idempotent()
115   {
116     return next_occurring_event_is_idempotent();
117   }
118
119 private:
120   std::unique_ptr<lmm::System> maxmin_system_;
121   const UpdateAlgo update_algorithm_;
122   Action::StateSet inited_action_set_;   /**< Created not started */
123   Action::StateSet started_action_set_;  /**< Started not done */
124   Action::StateSet failed_action_set_;   /**< Done with failure */
125   Action::StateSet finished_action_set_; /**< Done successful */
126   Action::StateSet ignored_action_set_;  /**< not considered (failure detectors?) */
127
128   ActionHeap action_heap_;
129 };
130
131 } // namespace resource
132 } // namespace kernel
133 } // namespace simgrid
134
135 /** @ingroup SURF_models
136  *  @brief List of initialized models
137  */
138 XBT_PUBLIC_DATA std::vector<simgrid::kernel::resource::Model*> all_existing_models;
139
140 #endif