Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
dc228ad6142706ed8d39fe795d797ff900df150a
[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 extern "C" {
12
13 /** @brief Possible update mechanisms */
14 enum e_UM_t {
15   UM_FULL,     /**< Full update mechanism: the remaining time of every action is recomputed at each step */
16   UM_LAZY,     /**< Lazy update mechanism: only the modified actions get recomputed.
17                     It may be slower than full if your system is tightly coupled to the point where every action
18                     gets recomputed anyway. In that case, you'd better not try to be cleaver with lazy and go for
19                     a simple full update.  */
20   UM_UNDEFINED /**< Mechanism not defined */
21 };
22 }
23
24 namespace simgrid {
25 namespace kernel {
26 namespace resource {
27
28 /** @ingroup SURF_interface
29  * @brief SURF model interface class
30  * @details A model is an object which handle the interactions between its Resources and its Actions
31  */
32 class XBT_PUBLIC Model {
33 public:
34   Model();
35   virtual ~Model();
36
37   /** @brief Get the set of [actions](@ref Action) in *ready* state */
38   Action::StateSet* get_ready_action_set() const { return ready_action_set_; }
39
40   /** @brief Get the set of [actions](@ref Action) in *running* state */
41   Action::StateSet* get_running_action_set() const { return running_action_set_; }
42
43   /** @brief Get the set of [actions](@ref Action) in *failed* state */
44   Action::StateSet* get_failed_action_set() const { return failed_action_set_; }
45
46   /** @brief Get the set of [actions](@ref Action) in *done* state */
47   Action::StateSet* get_done_action_set() const { return done_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   /**
56    * @brief Get the update mechanism of the current Model
57    * @see e_UM_t
58    */
59   e_UM_t getUpdateMechanism() const { return update_mechanism_; }
60   void setUpdateMechanism(e_UM_t 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 protected:
97   lmm::System* maxmin_system_ = nullptr;
98
99 private:
100   e_UM_t update_mechanism_        = UM_UNDEFINED;
101   Action::StateSet* ready_action_set_   = new Action::StateSet(); /**< Actions in state SURF_ACTION_READY */
102   Action::StateSet* running_action_set_ = new Action::StateSet(); /**< Actions in state SURF_ACTION_RUNNING */
103   Action::StateSet* failed_action_set_  = new Action::StateSet(); /**< Actions in state SURF_ACTION_FAILED */
104   Action::StateSet* done_action_set_    = new Action::StateSet(); /**< Actions in state SURF_ACTION_DONE */
105   heap_type action_heap_;
106 };
107
108 } // namespace resource
109 } // namespace kernel
110 } // namespace simgrid
111 #endif