forked from taskflow/taskflow
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtaskflow.cpp
More file actions
53 lines (41 loc) · 1.38 KB
/
Copy pathtaskflow.cpp
File metadata and controls
53 lines (41 loc) · 1.38 KB
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
#include <iostream>
#include <chrono>
#include <taskflow/taskflow.hpp>
#include "levelgraph.hpp"
struct TF {
TF(LevelGraph& graph, unsigned num_threads) : executor(num_threads) {
tasks.resize(graph.level());
for(size_t i=0; i<tasks.size(); ++i) {
tasks[i].resize(graph.length());
}
for(size_t i=0; i<graph.length(); i++){
Node& n = graph.node_at(graph.level()-1, i);
tasks[graph.level()-1][i] = taskflow.emplace([&](){ n.mark(); });
}
for(int l=graph.level()-2; l>=0 ; l--){
for(size_t i=0; i<graph.length(); i++){
Node& n = graph.node_at(l, i);
tasks[l][i] = taskflow.emplace([&](){ n.mark();});
for(size_t k=0; k<n._out_edges.size(); k++){
tasks[l][i].precede(tasks[l+1][n._out_edges[k]]);
}
}
}
}
void run() {
executor.run(taskflow).get();
}
tf::Executor executor;
tf::Taskflow taskflow;
std::vector<std::vector<tf::Task>> tasks;
};
void traverse_level_graph_taskflow(LevelGraph& graph, unsigned num_threads){
TF tf(graph, num_threads);
tf.run();
}
std::chrono::microseconds measure_time_taskflow(LevelGraph& graph, unsigned num_threads){
auto beg = std::chrono::high_resolution_clock::now();
traverse_level_graph_taskflow(graph, num_threads);
auto end = std::chrono::high_resolution_clock::now();
return std::chrono::duration_cast<std::chrono::microseconds>(end - beg);
}