Line | Branch | Exec | Source |
---|---|---|---|
1 | #include "example_threads/tbb/include/ops_tbb.hpp" | ||
2 | |||
3 | #include <tbb/tbb.h> | ||
4 | |||
5 | #include <atomic> | ||
6 | #include <core/util/include/util.hpp> | ||
7 | #include <numeric> | ||
8 | #include <vector> | ||
9 | |||
10 | #include "example_threads/common/include/common.hpp" | ||
11 | #include "oneapi/tbb/parallel_for.h" | ||
12 | |||
13 | namespace nesterov_a_test_task_threads { | ||
14 | |||
15 | 36 | NesterovATestTaskTBB::NesterovATestTaskTBB(const InType &in) { | |
16 | SetTypeOfTask(GetStaticTypeOfTask()); | ||
17 | 36 | GetInput() = in; | |
18 | 36 | GetOutput() = 0; | |
19 | 36 | } | |
20 | |||
21 |
2/4✓ Branch 0 taken 36 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 36 times.
|
36 | bool NesterovATestTaskTBB::ValidationImpl() { return (GetInput() > 0) && (GetOutput() == 0); } |
22 | |||
23 | 36 | bool NesterovATestTaskTBB::PreProcessingImpl() { | |
24 | 36 | GetOutput() = 2 * GetInput(); | |
25 | 36 | return GetOutput() > 0; | |
26 | } | ||
27 | |||
28 | 36 | bool NesterovATestTaskTBB::RunImpl() { | |
29 |
2/2✓ Branch 0 taken 108 times.
✓ Branch 1 taken 36 times.
|
144 | for (InType i = 0; i < GetInput(); i++) { |
30 |
2/2✓ Branch 0 taken 324 times.
✓ Branch 1 taken 108 times.
|
432 | for (InType j = 0; j < GetInput(); j++) { |
31 |
2/2✓ Branch 0 taken 972 times.
✓ Branch 1 taken 324 times.
|
1296 | for (InType k = 0; k < GetInput(); k++) { |
32 | 972 | std::vector<InType> tmp(i + j + k, 1); | |
33 | 972 | GetOutput() += std::accumulate(tmp.begin(), tmp.end(), 0); | |
34 |
2/2✓ Branch 0 taken 936 times.
✓ Branch 1 taken 36 times.
|
972 | GetOutput() -= i + j + k; |
35 | } | ||
36 | } | ||
37 | } | ||
38 | |||
39 | 36 | const int num_threads = ppc::util::GetNumThreads(); | |
40 | 36 | GetOutput() *= num_threads; | |
41 | |||
42 | 36 | std::atomic<int> counter(0); | |
43 | 126 | tbb::parallel_for(0, ppc::util::GetNumThreads(), [&](int /*i*/) { counter++; }); | |
44 | |||
45 | 36 | GetOutput() /= counter; | |
46 | 36 | return GetOutput() > 0; | |
47 | } | ||
48 | |||
49 | 36 | bool NesterovATestTaskTBB::PostProcessingImpl() { | |
50 | 36 | GetOutput() -= GetInput(); | |
51 | 36 | return GetOutput() > 0; | |
52 | } | ||
53 | |||
54 | } // namespace nesterov_a_test_task_threads | ||
55 |