Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Remove superfluous "virtual" declarations.
[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   ActionList* getReadyActionSet() const { return readyActionSet_; }
39
40   /** @brief Get the set of [actions](@ref Action) in *running* state */
41   ActionList* getRunningActionSet() const { return runningActionSet_; }
42
43   /** @brief Get the set of [actions](@ref Action) in *failed* state */
44   ActionList* getFailedActionSet() const { return failedActionSet_; }
45
46   /** @brief Get the set of [actions](@ref Action) in *done* state */
47   ActionList* getDoneActionSet() const { return doneActionSet_; }
48
49   /** @brief Get the set of modified [actions](@ref Action) */
50   ActionLmmListPtr getModifiedSet() const { return modifiedSet_; }
51
52   /** @brief Get the maxmin system of the current Model */
53   lmm_system_t getMaxminSystem() const { return maxminSystem_; }
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 updateMechanism_; }
60   void setUpdateMechanism(e_UM_t mechanism) { updateMechanism_ = mechanism; }
61
62   /** @brief Get Action heap */
63   heap_type& getActionHeap() { return actionHeap_; }
64
65   double actionHeapTopDate() const { return actionHeap_.top().first; }
66   Action* actionHeapPop();
67   bool actionHeapIsEmpty() const { return actionHeap_.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 nextOccuringEvent(double now);
76   virtual double nextOccuringEventLazy(double now);
77   virtual double nextOccuringEventFull(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 updateActionsState(double now, double delta);
86   virtual void updateActionsStateLazy(double now, double delta);
87   virtual void updateActionsStateFull(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   ActionLmmListPtr modifiedSet_;
98   lmm_system_t maxminSystem_ = nullptr;
99   bool selectiveUpdate_;
100
101 private:
102   e_UM_t updateMechanism_ = UM_UNDEFINED;
103   ActionList* readyActionSet_;   /**< Actions in state SURF_ACTION_READY */
104   ActionList* runningActionSet_; /**< Actions in state SURF_ACTION_RUNNING */
105   ActionList* failedActionSet_;  /**< Actions in state SURF_ACTION_FAILED */
106   ActionList* doneActionSet_;    /**< Actions in state SURF_ACTION_DONE */
107   heap_type actionHeap_;
108 };
109
110 } // namespace resource
111 } // namespace kernel
112 } // namespace simgrid
113 #endif