Workflow.h
1 
10 #ifndef WRENCH_WORKFLOW_H
11 #define WRENCH_WORKFLOW_H
12 
13 #include <map>
14 #include <set>
15 
16 #include "wrench/workflow/execution_events/WorkflowExecutionEvent.h"
17 #include "WorkflowFile.h"
18 #include "WorkflowTask.h"
19 #include "DagOfTasks.h"
20 
21 #include <boost/graph/adjacency_list.hpp>
22 #include <wrench/workflow/parallel_model/ParallelModel.h>
23 
24 class WorkflowTask;
25 
26 namespace wrench {
27 
28  class Simulation;
29 
30 
34  class Workflow {
35 
36  public:
37  Workflow();
38 
39  WorkflowTask *addTask(std::string, double flops,
40  unsigned long min_num_cores,
41  unsigned long max_num_cores,
42  double memory_requirement);
43 
44  void removeTask(WorkflowTask *task);
45 
46  void removeFile(WorkflowFile *file);
47 
48  WorkflowTask *getTaskByID(const std::string &id);
49 
50  WorkflowFile *addFile(std::string, double);
51 
52  WorkflowFile *getFileByID(const std::string &id);
53 
54  static double getSumFlops(const std::vector<WorkflowTask *> tasks);
55 
56  void addControlDependency(WorkflowTask *src, WorkflowTask *dest, bool redundant_dependencies = false);
58 
59  unsigned long getNumberOfTasks();
60 
61  unsigned long getNumLevels();
62 
63  double getCompletionDate();
64 
65  void exportToEPS(std::string);
66 
67  std::vector<WorkflowFile *> getFiles() const;
68  std::map<std::string, WorkflowFile *> getFileMap() const;
69  std::vector<WorkflowFile *> getInputFiles() const;
70  std::map<std::string, WorkflowFile *> getInputFileMap() const;
71  std::vector<WorkflowFile *> getOutputFiles() const;
72  std::map<std::string, WorkflowFile *> getOutputFileMap() const;
73 
74  std::vector<WorkflowTask *> getTasks();
75  std::map<std::string, WorkflowTask *> getTaskMap();
76  std::map<std::string, WorkflowTask *> getEntryTaskMap() const;
77  std::vector<WorkflowTask *> getEntryTasks() const;
78  std::map<std::string, WorkflowTask *> getExitTaskMap() const;
79  std::vector<WorkflowTask *> getExitTasks() const;
80 
81  std::vector<WorkflowTask *> getTaskParents(const WorkflowTask *task);
82  long getTaskNumberOfParents(const WorkflowTask *task);
83  std::vector<WorkflowTask *> getTaskChildren(const WorkflowTask *task);
84  long getTaskNumberOfChildren(const WorkflowTask *task);
85 
86  bool pathExists(const WorkflowTask *src, const WorkflowTask *dst);
87 
88 
89  bool isDone();
90 
91  /***********************/
93  /***********************/
94 
95  std::vector<WorkflowTask *> getTasksInTopLevelRange(unsigned long min, unsigned long max);
96 
97  std::vector<WorkflowTask *> getReadyTasks();
98 
99  std::map<std::string, std::vector<WorkflowTask *>> getReadyClusters();
100 
101  /***********************/
103  /***********************/
104 
105 
106  /***********************/
108  /***********************/
109  std::shared_ptr<WorkflowExecutionEvent> waitForNextExecutionEvent();
110  std::shared_ptr<WorkflowExecutionEvent> waitForNextExecutionEvent(double timeout);
111 
112  std::string getCallbackMailbox();
113 
114 // void updateTaskState(WorkflowTask *task, WorkflowTask::State state);
115 
116  /***********************/
118  /***********************/
119 
120  private:
121  friend class WMS;
122 
123  friend class WorkflowTask;
124 
125  struct Vertex{ WorkflowTask *task;};
126  typedef boost::adjacency_list<boost::listS, boost::vecS, boost::directedS, Vertex> DAG;
127  typedef boost::graph_traits<DAG>::vertex_descriptor vertex_t;
128 
129  DagOfTasks dag;
130 
131  std::map<std::string, std::unique_ptr<WorkflowTask>> tasks;
132  std::map<std::string, std::unique_ptr<WorkflowFile>> files;
133 
134 
135  std::string callback_mailbox;
136  ComputeService *parent_compute_service; // The compute service to which the job was submitted, if any
137  Simulation *simulation; // a ptr to the simulation so that the simulation can obtain simulation timestamps for workflow tasks
138  };
139 };
140 
141 #endif //WRENCH_WORKFLOW_H
std::map< std::string, std::vector< WorkflowTask * > > getReadyClusters()
Get a map of clusters composed of ready tasks.
Definition: Workflow.cpp:335
std::map< std::string, WorkflowTask * > getTaskMap()
Get the list of all tasks in the workflow.
Definition: Workflow.cpp:384
An internal class that uses the Boost Graph Library to implement a DAG of WorkflowTask objects.
Definition: DagOfTasks.h:49
void removeControlDependency(WorkflowTask *src, WorkflowTask *dest)
Remove a control dependency between tasks (does nothing if none)
Definition: Workflow.cpp:190
WorkflowFile * addFile(std::string, double)
Add a new file to the workflow.
Definition: Workflow.cpp:234
std::vector< WorkflowFile * > getFiles() const
Get the list of all files in the workflow.
Definition: Workflow.cpp:423
std::map< std::string, WorkflowFile * > getOutputFileMap() const
Retrieve a list of the output files of the workflow (i.e., those files that are output from some task...
Definition: Workflow.cpp:553
void addControlDependency(WorkflowTask *src, WorkflowTask *dest, bool redundant_dependencies=false)
Create a control dependency between two workflow tasks. Will not do anything if there is already a pa...
Definition: Workflow.cpp:165
std::vector< WorkflowTask * > getTaskChildren(const WorkflowTask *task)
Get the list of children for a task.
Definition: Workflow.cpp:438
std::vector< WorkflowTask * > getTasksInTopLevelRange(unsigned long min, unsigned long max)
Returns all tasks with top-levels in a range.
Definition: Workflow.cpp:600
std::shared_ptr< WorkflowExecutionEvent > waitForNextExecutionEvent()
Wait for the next workflow execution event.
Definition: Workflow.cpp:492
std::map< std::string, WorkflowTask * > getEntryTaskMap() const
Get the list of exit tasks of the workflow, i.e., those tasks that don't have parents.
Definition: Workflow.cpp:615
bool pathExists(const WorkflowTask *src, const WorkflowTask *dst)
Determine whether one source is an ancestor of a destination task.
Definition: Workflow.cpp:298
The compute service base class.
Definition: ComputeService.h:35
long getTaskNumberOfParents(const WorkflowTask *task)
Get the number of parents for a task.
Definition: Workflow.cpp:480
std::vector< WorkflowFile * > getInputFiles() const
Retrieve the list of the input files of the workflow (i.e., those files that are input to some tasks ...
Definition: Workflow.cpp:537
WorkflowTask * addTask(std::string, double flops, unsigned long min_num_cores, unsigned long max_num_cores, double memory_requirement)
Create and add a new computational task to the workflow.
Definition: Workflow.cpp:40
std::map< std::string, WorkflowTask * > getExitTaskMap() const
Get the exit tasks of the workflow, i.e., those tasks that don't have children.
Definition: Workflow.cpp:649
void exportToEPS(std::string)
Output the workflow's dependency graph to EPS.
Definition: Workflow.cpp:277
WorkflowFile * getFileByID(const std::string &id)
Find a WorkflowFile based on its ID.
Definition: Workflow.cpp:263
void removeTask(WorkflowTask *task)
Remove a task from the workflow. WARNING: this method de-allocated memory for the task,...
Definition: Workflow.cpp:104
Definition: Alarm.cpp:20
A workflow (to be executed by a WMS)
Definition: Workflow.h:34
std::vector< WorkflowTask * > getTaskParents(const WorkflowTask *task)
Get the list of parents for a task.
Definition: Workflow.cpp:466
std::string getCallbackMailbox()
Get the mailbox name associated to this workflow.
Definition: Workflow.cpp:511
A computational task in a Workflow.
Definition: WorkflowTask.h:31
bool isDone()
Returns whether all tasks are complete.
Definition: Workflow.cpp:369
static double getSumFlops(const std::vector< WorkflowTask * > tasks)
Get the total number of flops for a list of tasks.
Definition: Workflow.cpp:586
double getCompletionDate()
Returns the workflow's completion date.
Definition: Workflow.cpp:701
long getTaskNumberOfChildren(const WorkflowTask *task)
Get the number of children for a task.
Definition: Workflow.cpp:452
unsigned long getNumberOfTasks()
Get the number of tasks in the workflow.
Definition: Workflow.cpp:286
A class that provides basic simulation methods. Once the simulation object has been explicitly or imp...
Definition: Simulation.h:46
void removeFile(WorkflowFile *file)
Remove a file from the workflow. WARNING: this method de-allocated memory for the file,...
Definition: Workflow.cpp:79
std::vector< WorkflowFile * > getOutputFiles() const
Retrieve a list of the output files of the workflow (i.e., those files that are output from some task...
Definition: Workflow.cpp:569
Workflow()
Constructor.
Definition: Workflow.cpp:305
std::vector< WorkflowTask * > getExitTasks() const
Get the exit tasks of the workflow, i.e., those tasks that don't have children.
Definition: Workflow.cpp:666
unsigned long getNumLevels()
Returns the number of levels in the workflow.
Definition: Workflow.cpp:683
std::map< std::string, WorkflowFile * > getFileMap() const
Get the list of all files in the workflow.
Definition: Workflow.cpp:410
WorkflowTask * getTaskByID(const std::string &id)
Find a WorkflowTask based on its ID.
Definition: Workflow.cpp:148
std::vector< WorkflowTask * > getReadyTasks()
Get a vector of ready tasks.
Definition: Workflow.cpp:315
A data file used/produced by a WorkflowTask in a Workflow.
Definition: WorkflowFile.h:26
std::vector< WorkflowTask * > getEntryTasks() const
Get the list of exit tasks of the workflow, i.e., those tasks that don't have parents.
Definition: Workflow.cpp:632
std::vector< WorkflowTask * > getTasks()
Get the list of all tasks in the workflow.
Definition: Workflow.cpp:397
A workflow management system (WMS)
Definition: WMS.h:43
std::map< std::string, WorkflowFile * > getInputFileMap() const
Retrieve the list of the input files of the workflow (i.e., those files that are input to some tasks ...
Definition: Workflow.cpp:521