| 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 <numeric> | ||
| 7 | #include <util/include/util.hpp> | ||
| 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 | 12 | NesterovATestTaskTBB::NesterovATestTaskTBB(const InType &in) { | |
| 16 | SetTypeOfTask(GetStaticTypeOfTask()); | ||
| 17 | 12 | GetInput() = in; | |
| 18 | GetOutput() = 0; | ||
| 19 | 12 | } | |
| 20 | |||
| 21 | 12 | bool NesterovATestTaskTBB::ValidationImpl() { | |
| 22 |
2/4✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 12 times.
|
12 | return (GetInput() > 0) && (GetOutput() == 0); |
| 23 | } | ||
| 24 | |||
| 25 | 12 | bool NesterovATestTaskTBB::PreProcessingImpl() { | |
| 26 | 12 | GetOutput() = 2 * GetInput(); | |
| 27 | 12 | return GetOutput() > 0; | |
| 28 | } | ||
| 29 | |||
| 30 | 12 | bool NesterovATestTaskTBB::RunImpl() { | |
| 31 |
2/2✓ Branch 0 taken 36 times.
✓ Branch 1 taken 12 times.
|
48 | for (InType i = 0; i < GetInput(); i++) { |
| 32 |
2/2✓ Branch 0 taken 108 times.
✓ Branch 1 taken 36 times.
|
144 | for (InType j = 0; j < GetInput(); j++) { |
| 33 |
2/2✓ Branch 0 taken 324 times.
✓ Branch 1 taken 108 times.
|
432 | for (InType k = 0; k < GetInput(); k++) { |
| 34 | 324 | std::vector<InType> tmp(i + j + k, 1); | |
| 35 | 324 | GetOutput() += std::accumulate(tmp.begin(), tmp.end(), 0); | |
| 36 |
2/2✓ Branch 0 taken 312 times.
✓ Branch 1 taken 12 times.
|
324 | GetOutput() -= i + j + k; |
| 37 | } | ||
| 38 | } | ||
| 39 | } | ||
| 40 | |||
| 41 | 12 | const int num_threads = ppc::util::GetNumThreads(); | |
| 42 | 12 | GetOutput() *= num_threads; | |
| 43 | |||
| 44 | 12 | std::atomic<int> counter(0); | |
| 45 | 42 | tbb::parallel_for(0, ppc::util::GetNumThreads(), [&](int /*i*/) { counter++; }); | |
| 46 | |||
| 47 | 12 | GetOutput() /= counter; | |
| 48 | 12 | return GetOutput() > 0; | |
| 49 | } | ||
| 50 | |||
| 51 | 12 | bool NesterovATestTaskTBB::PostProcessingImpl() { | |
| 52 | 12 | GetOutput() -= GetInput(); | |
| 53 | 12 | return GetOutput() > 0; | |
| 54 | } | ||
| 55 | |||
| 56 | } // namespace nesterov_a_test_task_threads | ||
| 57 |