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 | 48 | NesterovATestTaskSTL::NesterovATestTaskSTL(const InType &in) { | |
14 | SetTypeOfTask(GetStaticTypeOfTask()); | ||
15 | 48 | GetInput() = in; | |
16 | GetOutput() = 0; | ||
17 | 48 | } | |
18 | |||
19 | 48 | bool NesterovATestTaskSTL::ValidationImpl() { | |
20 |
2/4✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 48 times.
|
48 | return (GetInput() > 0) && (GetOutput() == 0); |
21 | } | ||
22 | |||
23 | 48 | bool NesterovATestTaskSTL::PreProcessingImpl() { | |
24 | 48 | GetOutput() = 2 * GetInput(); | |
25 | 48 | return GetOutput() > 0; | |
26 | } | ||
27 | |||
28 | 48 | bool NesterovATestTaskSTL::RunImpl() { | |
29 |
2/2✓ Branch 0 taken 144 times.
✓ Branch 1 taken 48 times.
|
192 | for (InType i = 0; i < GetInput(); i++) { |
30 |
2/2✓ Branch 0 taken 432 times.
✓ Branch 1 taken 144 times.
|
576 | for (InType j = 0; j < GetInput(); j++) { |
31 |
2/2✓ Branch 0 taken 1296 times.
✓ Branch 1 taken 432 times.
|
1728 | for (InType k = 0; k < GetInput(); k++) { |
32 | 1296 | std::vector<InType> tmp(i + j + k, 1); | |
33 | 1296 | GetOutput() += std::accumulate(tmp.begin(), tmp.end(), 0); | |
34 |
2/2✓ Branch 0 taken 1248 times.
✓ Branch 1 taken 48 times.
|
1296 | GetOutput() -= i + j + k; |
35 | } | ||
36 | } | ||
37 | } | ||
38 | |||
39 | 48 | const int num_threads = ppc::util::GetNumThreads(); | |
40 | 48 | std::vector<std::thread> threads(num_threads); | |
41 | 48 | GetOutput() *= num_threads; | |
42 | |||
43 | 48 | std::atomic<int> counter(0); | |
44 |
2/2✓ Branch 0 taken 120 times.
✓ Branch 1 taken 48 times.
|
168 | for (int i = 0; i < num_threads; i++) { |
45 |
2/4✓ Branch 1 taken 120 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 120 times.
|
120 | threads[i] = std::thread([&]() { counter++; }); |
46 |
1/2✓ Branch 1 taken 120 times.
✗ Branch 2 not taken.
|
120 | threads[i].join(); |
47 | } | ||
48 | |||
49 | 48 | GetOutput() /= counter; | |
50 | 48 | return GetOutput() > 0; | |
51 | 48 | } | |
52 | |||
53 | 48 | bool NesterovATestTaskSTL::PostProcessingImpl() { | |
54 | 48 | GetOutput() -= GetInput(); | |
55 | 48 | return GetOutput() > 0; | |
56 | } | ||
57 | |||
58 | } // namespace nesterov_a_test_task_threads | ||
59 |