GCC Code Coverage Report


Directory: ./
File: tasks/example_threads/all/src/ops_all.cpp
Date: 2025-06-27 00:53:24
Exec Total Coverage
Lines: 40 41 97.6%
Functions: 5 5 100.0%
Branches: 16 22 72.7%

Line Branch Exec Source
1 #include "example_threads/all/include/ops_all.hpp"
2
3 #include <mpi.h>
4
5 #include <atomic>
6 #include <numeric>
7 #include <thread>
8 #include <vector>
9
10 #include "core/util/include/util.hpp"
11 #include "example_threads/common/include/common.hpp"
12 #include "oneapi/tbb/parallel_for.h"
13
14 namespace nesterov_a_test_task_threads {
15
16 60 NesterovATestTaskALL::NesterovATestTaskALL(const InType &in) {
17 SetTypeOfTask(GetStaticTypeOfTask());
18 60 GetInput() = in;
19 60 GetOutput() = 0;
20 60 }
21
22
2/4
✓ Branch 0 taken 60 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 60 times.
60 bool NesterovATestTaskALL::ValidationImpl() { return (GetInput() > 0) && (GetOutput() == 0); }
23
24 60 bool NesterovATestTaskALL::PreProcessingImpl() {
25 60 GetOutput() = 2 * GetInput();
26 60 return GetOutput() > 0;
27 }
28
29 60 bool NesterovATestTaskALL::RunImpl() {
30
2/2
✓ Branch 0 taken 180 times.
✓ Branch 1 taken 60 times.
240 for (InType i = 0; i < GetInput(); i++) {
31
2/2
✓ Branch 0 taken 540 times.
✓ Branch 1 taken 180 times.
720 for (InType j = 0; j < GetInput(); j++) {
32
2/2
✓ Branch 0 taken 1620 times.
✓ Branch 1 taken 540 times.
2160 for (InType k = 0; k < GetInput(); k++) {
33 1620 std::vector<InType> tmp(i + j + k, 1);
34 1620 GetOutput() += std::accumulate(tmp.begin(), tmp.end(), 0);
35
2/2
✓ Branch 0 taken 1560 times.
✓ Branch 1 taken 60 times.
1620 GetOutput() -= i + j + k;
36 }
37 }
38 }
39
40 60 const int num_threads = ppc::util::GetNumThreads();
41 {
42 60 GetOutput() *= num_threads;
43
44 60 int rank = -1;
45 60 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
46
1/2
✓ Branch 0 taken 60 times.
✗ Branch 1 not taken.
60 if (rank == 0) {
47 60 std::atomic<int> counter(0);
48 60 #pragma omp parallel default(none) shared(counter) num_threads(ppc::util::GetNumThreads())
49 counter++;
50
51 60 GetOutput() /= counter;
52 } else {
53 GetOutput() /= num_threads;
54 }
55 }
56
57 {
58 60 GetOutput() *= num_threads;
59 60 std::vector<std::thread> threads(num_threads);
60 60 std::atomic<int> counter(0);
61
2/2
✓ Branch 0 taken 120 times.
✓ Branch 1 taken 60 times.
180 for (int i = 0; i < num_threads; i++) {
62
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++; });
63
1/2
✓ Branch 1 taken 120 times.
✗ Branch 2 not taken.
120 threads[i].join();
64 }
65 60 GetOutput() /= counter;
66 60 }
67
68 {
69 60 GetOutput() *= num_threads;
70 60 std::atomic<int> counter(0);
71 240 tbb::parallel_for(0, ppc::util::GetNumThreads(), [&](int /*i*/) { counter++; });
72 60 GetOutput() /= counter;
73 }
74 60 MPI_Barrier(MPI_COMM_WORLD);
75 60 return GetOutput() > 0;
76 }
77
78 60 bool NesterovATestTaskALL::PostProcessingImpl() {
79 60 GetOutput() -= GetInput();
80 60 return GetOutput() > 0;
81 }
82
83 } // namespace nesterov_a_test_task_threads
84