Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
1e1bebba44deeaf80d4263b662384249da0fd188
[simgrid.git] / include / simgrid / kernel / resource / Model.hpp
1 /* Copyright (c) 2004-2018. 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     UM_UNDEFINED /**< Mechanism not defined */
29   };
30
31   Model();
32   virtual ~Model();
33
34   /** @brief Get the set of [actions](@ref Action) in *ready* state */
35   Action::StateSet* get_ready_action_set() const { return ready_action_set_; }
36
37   /** @brief Get the set of [actions](@ref Action) in *running* state */
38   Action::StateSet* get_running_action_set() const { return running_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 *done* state */
44   Action::StateSet* get_done_action_set() const { return done_action_set_; }
45
46   /** @brief Get the set of modified [actions](@ref Action) */
47   Action::ModifiedSet* get_modified_set() const;
48
49   /** @brief Get the maxmin system of the current Model */
50   lmm::System* get_maxmin_system() const { return maxmin_system_; }
51
52   /** @brief Set the maxmin system of the current Model */
53   void set_maxmin_system(lmm::System* system) { maxmin_system_ = system; }
54
55   /**
56    * @brief Get the update mechanism of the current Model
57    * @see e_UM_t
58    */
59   UpdateAlgo getUpdateMechanism() const { return update_mechanism_; }
60   void setUpdateMechanism(UpdateAlgo mechanism) { update_mechanism_ = mechanism; }
61
62   /** @brief Get Action heap */
63   heap_type& getActionHeap() { return action_heap_; }
64
65   double actionHeapTopDate() const { return action_heap_.top().first; }
66   Action* actionHeapPop();
67   bool actionHeapIsEmpty() const { return action_heap_.empty(); }
68
69   /**
70    * @brief Share the resources between the actions
71    *
72    * @param now The current time of the simulation
73    * @return The delta of time till the next action will finish
74    */
75   virtual double next_occuring_event(double now);
76   virtual double next_occuring_event_lazy(double now);
77   virtual double next_occuring_event_full(double now);
78
79   /**
80    * @brief Update action to the current time
81    *
82    * @param now The current time of the simulation
83    * @param delta The delta of time since the last update
84    */
85   virtual void update_actions_state(double now, double delta);
86   virtual void update_actions_state_lazy(double now, double delta);
87   virtual void update_actions_state_full(double now, double delta);
88
89   /** @brief Returns whether this model have an idempotent shareResource()
90    *
91    * The only model that is not is NS3: computing the next timestamp moves the model up to that point,
92    * so we need to call it only when the next timestamp of other sources is computed.
93    */
94   virtual bool nextOccuringEventIsIdempotent() { return true; }
95
96 private:
97   lmm::System* maxmin_system_           = nullptr;
98   UpdateAlgo update_mechanism_          = UpdateAlgo::UM_UNDEFINED;
99   Action::StateSet* ready_action_set_   = new Action::StateSet(); /**< Actions in state SURF_ACTION_READY */
100   Action::StateSet* running_action_set_ = new Action::StateSet(); /**< Actions in state SURF_ACTION_RUNNING */
101   Action::StateSet* failed_action_set_  = new Action::StateSet(); /**< Actions in state SURF_ACTION_FAILED */
102   Action::StateSet* done_action_set_    = new Action::StateSet(); /**< Actions in state SURF_ACTION_DONE */
103   heap_type action_heap_;
104 };
105
106 } // namespace resource
107 } // namespace kernel
108 } // namespace simgrid
109 #endif