GCC Code Coverage Report


Directory: ./
File: tasks/example_threads/stl/src/ops_stl.cpp
Date: 2025-06-27 00:53:24
Exec Total Coverage
Lines: 28 28 100.0%
Functions: 5 5 100.0%
Branches: 15 20 75.0%

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