in benchmarks/summing_for_benchmark.cpp [134:157]
void BM_tbb(benchmark::State& state) {
const int num_threads = state.range(0);
const int num_elements = state.range(1);
int64_t sum = 0;
int foo = 0;
auto& input = getInputs(num_elements);
for (auto UNUSED_VAR : state) {
tbb::task_scheduler_init initsched(num_threads);
++foo;
sum = tbb::parallel_reduce(
tbb::blocked_range<const int*>(&input[0], &input[0] + num_elements),
int64_t{0},
[foo](const tbb::blocked_range<const int*>& r, int64_t init) -> int64_t {
for (const int* a = r.begin(); a != r.end(); ++a)
init += *a * *a - 3 * foo * *a;
return init;
},
[](int64_t x, int64_t y) -> int64_t { return x + y; });
}
checkResults(input, sum, foo);
}