WRENCH  1.11
Cyberinfrastructure Simulation Workbench
Overview Installation Getting Started WRENCH 101 WRENCH 102
Action.h
1 
10 #ifndef WRENCH_ACTION_H
11 #define WRENCH_ACTION_H
12 
13 #include <memory>
14 #include <string>
15 #include <set>
16 #include <stack>
17 #include <iostream>
18 
19 namespace wrench {
20 
21  class CompoundJob;
22  class FailureCause;
23  class ActionExecutor;
24 
28  class Action : public std::enable_shared_from_this<Action> {
29 
30  public:
31 
33  enum State {
46  };
47 
48  const std::string &getName() const;
49  std::shared_ptr<CompoundJob> getJob() const;
50  Action::State getState() const;
51  std::string getStateAsString() const;
52  static std::string stateToString(Action::State state);
53 
54  double getStartDate() const;
55  double getEndDate() const;
56  std::shared_ptr<FailureCause> getFailureCause() const;
57 
58  std::set<std::shared_ptr<Action>> getChildren();
59 
60  std::set<std::shared_ptr<Action>> getParents();
61 
62  virtual unsigned long getMinNumCores() const;
63  virtual unsigned long getMaxNumCores() const;
64  virtual double getMinRAMFootprint() const;
65 
66  virtual bool usesScratch() const;
67 
68  void setPriority(double priority);
69  double getPriority() const;
70 
72  void setThreadCreationOverhead(double overhead_in_seconds);
73 
74  static std::string getActionTypeAsString(const std::shared_ptr<Action>& action);
75 
79  struct ActionExecution {
81  double start_date = -1.0;
83  double end_date = -1.0;
87  std::string execution_host;
91  unsigned long num_cores_allocated = 0;
93  double ram_allocated = 0;
95  std::shared_ptr<FailureCause> failure_cause;
96  };
97 
98  std::stack<Action::ActionExecution> &getExecutionHistory();
99 
104  std::shared_ptr<Action> getSharedPtr() { return this->shared_from_this(); }
105 
106  protected:
107 
108  friend class CompoundJob;
109  friend class ActionExecutor;
110  friend class ActionExecutionService;
111  friend class BareMetalComputeService; // this is a bit unfortunate (to call setFailureCause - perhaps go through CompoundJob?)
112  friend class BatchComputeService; // this is a bit unfortunate (to call setFailureCause - perhaps go through CompoundJob?)
113 
114  void newExecution(Action::State state);
115 
116  void setStartDate(double date);
117  void setEndDate(double date);
118  void setState(Action::State new_state);
119  void setExecutionHost(std::string host);
120  void setNumCoresAllocated(unsigned long num_cores);
121  void setRAMAllocated(double ram);
122  void setFailureCause(std::shared_ptr<FailureCause> failure_cause);
123 
124  virtual ~Action() = default;
125 
126  Action(const std::string& name, const std::string& prefix, std::shared_ptr<CompoundJob> job);
127 
132  virtual void execute(std::shared_ptr<ActionExecutor> action_executor) = 0;
137  virtual void terminate(std::shared_ptr<ActionExecutor> action_executor) = 0;
138 
139  void updateState();
140 
145 
146  private:
147 
148  std::set<Action*> parents;
149  std::set<Action*> children;
150 
151  double priority;
152 
153  std::string name;
154  std::weak_ptr<CompoundJob> job;
155 
156  std::map<std::string, std::string> service_specific_arguments;
157 
158  static unsigned long getNewUniqueNumber();
159 
160  std::stack<ActionExecution> execution_history;
161 
162  };
163 }
164 
165 #endif //WRENCH_ACTION_H
wrench::Action::getChildren
std::set< std::shared_ptr< Action > > getChildren()
Get the action's children.
Definition: Action.cpp:300
wrench::Action::setStartDate
void setStartDate(double date)
Sets the action's start date.
Definition: Action.cpp:139
wrench::Action::simulate_computation_as_sleep
bool simulate_computation_as_sleep
Whether to simulate the computation as sleep.
Definition: Action.h:144
wrench::Action::setRAMAllocated
void setRAMAllocated(double ram)
Sets the action's allocated RAM.
Definition: Action.cpp:204
wrench::Action::terminate
virtual void terminate(std::shared_ptr< ActionExecutor > action_executor)=0
Method called when the task terminates.
wrench::Action::FAILED
@ FAILED
Failed (has failed)
Definition: Action.h:45
wrench::Action::getEndDate
double getEndDate() const
Returns this action's end date (-1.0 if not ended)
Definition: Action.cpp:163
wrench::Action::getFailureCause
std::shared_ptr< FailureCause > getFailureCause() const
Returns the action's failure cause.
Definition: Action.cpp:131
wrench::Action::getExecutionHistory
std::stack< Action::ActionExecution > & getExecutionHistory()
Retrieve the execution history.
Definition: Action.cpp:291
wrench::ActionExecutionService
An action execution service that:
Definition: ActionExecutionService.h:38
wrench::Action::getMinRAMFootprint
virtual double getMinRAMFootprint() const
Get the minimum required amount of RAM to execute the action.
Definition: Action.cpp:283
wrench::Action::setThreadCreationOverhead
void setThreadCreationOverhead(double overhead_in_seconds)
Set the thread creation overhead (default = zero)
Definition: Action.cpp:236
wrench::Action::execute
virtual void execute(std::shared_ptr< ActionExecutor > action_executor)=0
Method to execute the task.
wrench::Action::getSharedPtr
std::shared_ptr< Action > getSharedPtr()
Get the shared pointer for this object.
Definition: Action.h:104
wrench::Action::ActionExecution
A data structure that keeps track of an action's execution(s)
Definition: Action.h:79
wrench::Action::STARTED
@ STARTED
Started (is being executed)
Definition: Action.h:39
wrench::Action::COMPLETED
@ COMPLETED
Completed (successfully completed)
Definition: Action.h:41
wrench::Action::getState
Action::State getState() const
Returns the action's state.
Definition: Action.cpp:71
wrench::Action::NOT_READY
@ NOT_READY
Not ready (not ready, because depends on other actions)
Definition: Action.h:35
wrench::Action::ActionExecution::state
Action::State state
final state
Definition: Action.h:85
wrench::BareMetalComputeService
A compute service that manages a set of multi-core compute hosts and provides access to their resourc...
Definition: BareMetalComputeService.h:45
wrench::BatchComputeService
A batch_standard_and_pilot_jobs-scheduled compute service that manages a set of compute hosts and con...
Definition: BatchComputeService.h:49
wrench
Definition: Action.cpp:28
wrench::Action::usesScratch
virtual bool usesScratch() const
Determine whether the action uses scratch.
Definition: Action.cpp:369
wrench::Action::getMinNumCores
virtual unsigned long getMinNumCores() const
Get the minimum number of cores required to execute the action.
Definition: Action.cpp:267
wrench::Action::setEndDate
void setEndDate(double date)
Sets the action's end date.
Definition: Action.cpp:147
wrench::Action::ActionExecution::execution_host
std::string execution_host
execution host (could be a virtual host)
Definition: Action.h:87
wrench::Action::ActionExecution::num_cores_allocated
unsigned long num_cores_allocated
Number of allocated cores.
Definition: Action.h:91
wrench::Action::getActionTypeAsString
static std::string getActionTypeAsString(const std::shared_ptr< Action > &action)
Returns an action's type as a human-readable string.
Definition: Action.cpp:341
wrench::Action::getParents
std::set< std::shared_ptr< Action > > getParents()
Get the action's parents.
Definition: Action.cpp:312
wrench::Action::getPriority
double getPriority() const
Get the action's priority.
Definition: Action.cpp:332
wrench::Action::ActionExecution::failure_cause
std::shared_ptr< FailureCause > failure_cause
Failure cause (if applicable)
Definition: Action.h:95
wrench::Action::ActionExecution::end_date
double end_date
end date
Definition: Action.h:83
wrench::Action::updateState
void updateState()
Update the action's state.
Definition: Action.cpp:243
wrench::Action::getJob
std::shared_ptr< CompoundJob > getJob() const
Returns the job this action belongs to.
Definition: Action.cpp:112
wrench::Action::setFailureCause
void setFailureCause(std::shared_ptr< FailureCause > failure_cause)
Sets the action's failure cause.
Definition: Action.cpp:171
wrench::Action::ActionExecution::start_date
double start_date
start date
Definition: Action.h:81
wrench::Action::setNumCoresAllocated
void setNumCoresAllocated(unsigned long num_cores)
Sets the action's allocated number of cores.
Definition: Action.cpp:196
wrench::Action::ActionExecution::physical_execution_host
std::string physical_execution_host
physical execution host
Definition: Action.h:89
wrench::Action::setPriority
void setPriority(double priority)
Set the action's priority.
Definition: Action.cpp:324
wrench::Action::setState
void setState(Action::State new_state)
Sets the action's state to a new value.
Definition: Action.cpp:120
wrench::Action::setSimulateComputationAsSleep
void setSimulateComputationAsSleep(bool simulate_computation_as_sleep)
Set whether simulation should be simulated as sleep (default = false)
Definition: Action.cpp:212
wrench::Action::newExecution
void newExecution(Action::State state)
Create a new execution data structure (e.g., after a restart)
Definition: Action.cpp:220
wrench::Action::getMaxNumCores
virtual unsigned long getMaxNumCores() const
Get the maximum number of cores that can be used to execute the action.
Definition: Action.cpp:275
wrench::Action::Action
Action(const std::string &name, const std::string &prefix, std::shared_ptr< CompoundJob > job)
Constructor.
Definition: Action.cpp:36
wrench::Action::getStartDate
double getStartDate() const
Returns ths action's started date (-1.0 if not started)
Definition: Action.cpp:155
wrench::Action::ActionExecution::ram_allocated
double ram_allocated
RAM allocated cores.
Definition: Action.h:93
wrench::Action::getStateAsString
std::string getStateAsString() const
Returns the action's state as a human-readable string.
Definition: Action.cpp:104
wrench::Action
An abstract class that implements the concept of an action.
Definition: Action.h:28
wrench::Action::setExecutionHost
void setExecutionHost(std::string host)
Sets the action's execution hosts (and the action's physical execution host)
Definition: Action.cpp:179
wrench::Action::KILLED
@ KILLED
Killed (due to user actions, service being terminated, etc.)
Definition: Action.h:43
wrench::Action::thread_creation_overhead
double thread_creation_overhead
The thread creation overhead in seconds.
Definition: Action.h:142
wrench::Action::READY
@ READY
Ready (ready to execute)
Definition: Action.h:37
wrench::Action::getName
const std::string & getName() const
Returns the action's name.
Definition: Action.cpp:63
wrench::Action::stateToString
static std::string stateToString(Action::State state)
Convert an action state to a human-readable string.
Definition: Action.cpp:80
wrench::Action::State
State
Action states.
Definition: Action.h:33