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
52 lines (40 loc) · 1.29 KB
/
Copy pathtaskflow.cpp
File metadata and controls
52 lines (40 loc) · 1.29 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
#include "matrix_multiplication.hpp"
#include <taskflow/taskflow.hpp>
// matrix_multiplication_taskflow
void matrix_multiplication_taskflow(unsigned num_threads) {
tf::Executor executor(num_threads);
tf::Taskflow taskflow;
auto pa = taskflow.parallel_for(0, N, 1, [&] (int i) {
for(int j=0; j<N; ++j) {
a[i][j] = i + j;
}
}, num_threads);
auto pb = taskflow.parallel_for(0, N, 1, [&] (int i) {
for(int j=0; j<N; ++j) {
b[i][j] = i * j;
}
}, num_threads);
auto pc = taskflow.parallel_for(0, N, 1, [&] (int i) {
for(int j=0; j<N; ++j) {
c[i][j] = 0;;
}
}, num_threads);
auto pr = taskflow.parallel_for(0, N, 1, [&] (int i) {
for(int j=0; j<N; ++j) {
for(int k=0; k<N; k++) {
c[i][j] += a[i][k] * b[k][j];
}
}
}, num_threads);
pa.second.precede(pr.first);
pb.second.precede(pr.first);
pc.second.precede(pr.first);
executor.run(taskflow).get();
//std::cout << reduce_sum() << std::endl;
}
std::chrono::microseconds measure_time_taskflow(unsigned num_threads) {
auto beg = std::chrono::high_resolution_clock::now();
matrix_multiplication_taskflow(num_threads);
auto end = std::chrono::high_resolution_clock::now();
return std::chrono::duration_cast<std::chrono::microseconds>(end - beg);
}