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
36 lines (27 loc) · 984 Bytes
/
Copy pathtaskflow.cpp
File metadata and controls
36 lines (27 loc) · 984 Bytes
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
#include "reduce_sum.hpp"
#include <taskflow/taskflow.hpp>
#include <taskflow/algorithm/reduce.hpp>
void reduce_sum_taskflow(unsigned num_threads) {
static tf::Executor executor(num_threads);
tf::Taskflow taskflow;
double result = 0.0;
taskflow.reduce_by_index(
tf::IndexRange<size_t>(0, vec.size(), 1),
result,
[&](tf::IndexRange<size_t> range, std::optional<double> running_total) {
double partial_sum = running_total ? *running_total : 0.0;
for(size_t i=range.begin(); i<range.end(); i+=range.step_size()) {
partial_sum += vec[i];
}
return partial_sum;
},
std::plus<double>()
);
executor.run(taskflow).get();
}
std::chrono::microseconds measure_time_taskflow(unsigned num_threads) {
auto beg = std::chrono::high_resolution_clock::now();
reduce_sum_taskflow(num_threads);
auto end = std::chrono::high_resolution_clock::now();
return std::chrono::duration_cast<std::chrono::microseconds>(end - beg);
}