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