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