| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "example_threads/stl/include/ops_stl.hpp" | ||
| 2 | |||
| 3 | #include <atomic> | ||
| 4 | #include <numeric> | ||
| 5 | #include <thread> | ||
| 6 | #include <vector> | ||
| 7 | |||
| 8 | #include "example_threads/common/include/common.hpp" | ||
| 9 | #include "util/include/util.hpp" | ||
| 10 | |||
| 11 | namespace nesterov_a_test_task_threads { | ||
| 12 | |||
| 13 | 24 | NesterovATestTaskSTL::NesterovATestTaskSTL(const InType &in) { | |
| 14 | SetTypeOfTask(GetStaticTypeOfTask()); | ||
| 15 | 24 | GetInput() = in; | |
| 16 | GetOutput() = 0; | ||
| 17 | 24 | } | |
| 18 | |||
| 19 | 24 | bool NesterovATestTaskSTL::ValidationImpl() { | |
| 20 |
2/4✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 24 times.
|
24 | return (GetInput() > 0) && (GetOutput() == 0); |
| 21 | } | ||
| 22 | |||
| 23 | 24 | bool NesterovATestTaskSTL::PreProcessingImpl() { | |
| 24 | 24 | GetOutput() = 2 * GetInput(); | |
| 25 | 24 | return GetOutput() > 0; | |
| 26 | } | ||
| 27 | |||
| 28 | 24 | bool NesterovATestTaskSTL::RunImpl() { | |
| 29 |
2/2✓ Branch 0 taken 72 times.
✓ Branch 1 taken 24 times.
|
96 | for (InType i = 0; i < GetInput(); i++) { |
| 30 |
2/2✓ Branch 0 taken 216 times.
✓ Branch 1 taken 72 times.
|
288 | for (InType j = 0; j < GetInput(); j++) { |
| 31 |
2/2✓ Branch 0 taken 648 times.
✓ Branch 1 taken 216 times.
|
864 | for (InType k = 0; k < GetInput(); k++) { |
| 32 | 648 | std::vector<InType> tmp(i + j + k, 1); | |
| 33 | 648 | GetOutput() += std::accumulate(tmp.begin(), tmp.end(), 0); | |
| 34 |
2/2✓ Branch 0 taken 624 times.
✓ Branch 1 taken 24 times.
|
648 | GetOutput() -= i + j + k; |
| 35 | } | ||
| 36 | } | ||
| 37 | } | ||
| 38 | |||
| 39 | 24 | const int num_threads = ppc::util::GetNumThreads(); | |
| 40 | 24 | std::vector<std::thread> threads(num_threads); | |
| 41 | 24 | GetOutput() *= num_threads; | |
| 42 | |||
| 43 | 24 | std::atomic<int> counter(0); | |
| 44 |
2/2✓ Branch 0 taken 60 times.
✓ Branch 1 taken 24 times.
|
84 | for (int i = 0; i < num_threads; i++) { |
| 45 |
2/4✓ Branch 1 taken 60 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 60 times.
|
60 | threads[i] = std::thread([&]() { counter++; }); |
| 46 |
1/2✓ Branch 1 taken 60 times.
✗ Branch 2 not taken.
|
60 | threads[i].join(); |
| 47 | } | ||
| 48 | |||
| 49 | 24 | GetOutput() /= counter; | |
| 50 | 24 | return GetOutput() > 0; | |
| 51 | 24 | } | |
| 52 | |||
| 53 | 24 | bool NesterovATestTaskSTL::PostProcessingImpl() { | |
| 54 | 24 | GetOutput() -= GetInput(); | |
| 55 | 24 | return GetOutput() > 0; | |
| 56 | } | ||
| 57 | |||
| 58 | } // namespace nesterov_a_test_task_threads | ||
| 59 |