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