-
Notifications
You must be signed in to change notification settings - Fork 0
/
try.cpp
136 lines (113 loc) · 2.49 KB
/
try.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#include <bits/stdc++.h>
#include <fstream>
using namespace std;
#include "executor.hpp"
#include <unistd.h>
#define Sleep(X) usleep(X * 1000)
#include <chrono>
using namespace std::chrono;
//dot -Tpng myflow_graph.dot > output.png && eog output.png
void fun1(){
cout<<"Function 1 start!\n";
Sleep(500);
cout<<"Function 1 finish!\n";
}
void fun2(){
cout<<"Function 2 start!\n";
Sleep(500);
cout<<"Function 2 finish!\n";
}
void fun3(){
cout<<"Function 3 start!\n";
Sleep(1000);
cout<<"Function 3 finish!\n";
}
void fun4(){
cout<<"Function 4 start!\n";
Sleep(1000);
cout<<"Function 4 finish!\n";
}
void fun5(){
cout<<"Function 5 start!\n";
Sleep(1000);
cout<<"Function 5 finish!\n";
}
void fun6(){
cout<<"Function 6 start!\n";
Sleep(1000);
cout<<"Function 6 finish!\n";
}
void fun7(){
cout<<"Function 7 start!\n";
Sleep(3000);
cout<<"Function 7 finish!\n";
}
void subflow_fun(){
cout<<"subflow fun start\n";
cout<<"subflow fun end\n";
}
int main(){
auto start = high_resolution_clock::now();
Taskflow myflow = Taskflow("myflow");
auto A = myflow.add({
fun1,
fun2,
fun3,
fun4,
fun5,
fun6,
fun7
});
A[1]->precede({A[0]});
A[2]->precede({A[0]});
A[3]->precede({A[0]});
A[4]->precede({A[3], A[1]});
A[5]->precede({A[3],A[1]});
A[6]->precede({A[4],A[2]});
Subflow sub1("sub1");
// auto sub_tasks = sub1.add({
// fun1,
// subflow_fun
// });
// A[6]->attach(&sub1);
// Subflow sub2("sub_of_sub");
// sub2.add({fun1, fun2});
// sub_tasks[0]->attach(&sub2);
// A[6]->detach();
Taskflow myflow2 = Taskflow("myflow2");
auto B = myflow2.add({
fun1,
fun2,
fun3,
fun4,
fun5,
fun6,
fun7
});
B[1]->precede({B[0]});
B[0]->precede({B[1]});
B[3]->precede({B[0]});
// Linear Execution in comments
// for(auto test: myflow.taskflow[0]->successor){
// test->execute_task();
// }
// A[1].execute_task();
ofstream myfile;
myfile.open(myflow.name+"_graph.dot");
myflow.dump(myfile);
// string cmd = "dot -Tpng "+myflow.name+"_graph.dot > output.png && eog output.png";
// const char * command = cmd.c_str();
// cout << "compiling";
// system(command);
Executor exe;
exe.run({myflow, myflow2});
auto stop = high_resolution_clock::now();
auto duration = duration_cast<microseconds>(stop - start);
cout <<"Total time taken for mini-taskflow:"<< duration.count()/1e6 << endl;
return 0;
// vector<Task> your = myflow.taskflow[0]->successor;
//Serial execution
// for(auto task: exe.topological_sort_list){
// task->execute_task();
// }
}