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