forked from Kolkir/cpptask
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparallel_reduce_test.cpp
More file actions
44 lines (33 loc) · 955 Bytes
/
Copy pathparallel_reduce_test.cpp
File metadata and controls
44 lines (33 loc) · 955 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
35
36
37
38
39
40
41
42
43
44
#include "cpptasktest.h"
#include <cpptask/cpptask.h>
#include <algorithm>
namespace
{
double process_func(const cpptask::range<CppTaskTestData::ArrayType::iterator>& range)
{
double res = 0;
std::for_each(range.start, range.end,
[&res](double x)
{
CppTaskTestData::DoubleSqrt()(x);
res += x;
});
return res;
}
double join_func(double a, double b)
{
return a + b;
}
}
TEST_F(CppTaskTest, Reduce_Serial)
{
cpptask::initialzer init(0);
double sum = cpptask::reduce<double>(testArray.begin(), testArray.end(), process_func, join_func);
ASSERT_EQ(CppTaskTestData::instance().getSum(), sum);
}
TEST_F(CppTaskTest, Reduce_Parallel)
{
cpptask::initialzer init(4);
double sum = cpptask::reduce<double>(testArray.begin(), testArray.end(), process_func, join_func);
ASSERT_EQ(CppTaskTestData::instance().getSum(), sum);
}