Logo AND Algorithmique Numérique Distribuée

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