GCC Code Coverage Report


Directory: ./
File: tasks/redkina_a_integral_simpson/tbb/src/ops_tbb.cpp
Date: 2026-04-02 17:12:27
Exec Total Coverage
Lines: 57 57 100.0%
Functions: 7 7 100.0%
Branches: 44 70 62.9%

Line Branch Exec Source
1 #include "redkina_a_integral_simpson/tbb/include/ops_tbb.hpp"
2
3 #include <oneapi/tbb.h>
4
5 #include <cmath>
6 #include <cstddef>
7 #include <functional>
8 #include <vector>
9
10 #include "redkina_a_integral_simpson/common/include/common.hpp"
11
12 namespace redkina_a_integral_simpson {
13
14 namespace {
15 925136 double ComputeNodeContribution(size_t linear_idx, const std::vector<double> &a, const std::vector<double> &h,
16 const std::vector<int> &n, const std::vector<size_t> &strides,
17 const std::function<double(const std::vector<double> &)> &func) {
18 size_t dim = a.size();
19 925136 std::vector<double> point(dim);
20 size_t remainder = linear_idx;
21
1/4
✓ Branch 1 taken 925136 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
925136 std::vector<int> indices(dim);
22
23
2/2
✓ Branch 0 taken 2123928 times.
✓ Branch 1 taken 925136 times.
3049064 for (size_t i = 0; i < dim; ++i) {
24 2123928 indices[i] = static_cast<int>(remainder / strides[i]);
25 2123928 remainder %= strides[i];
26 }
27
28 double w_prod = 1.0;
29
2/2
✓ Branch 0 taken 2123928 times.
✓ Branch 1 taken 925136 times.
3049064 for (size_t i = 0; i < dim; ++i) {
30
2/2
✓ Branch 0 taken 2096768 times.
✓ Branch 1 taken 27160 times.
2123928 int idx = indices[i];
31 2123928 point[i] = a[i] + (static_cast<double>(idx) * h[i]);
32
33 int w = 0;
34
4/4
✓ Branch 0 taken 2096768 times.
✓ Branch 1 taken 27160 times.
✓ Branch 2 taken 2069608 times.
✓ Branch 3 taken 27160 times.
2123928 if (idx == 0 || idx == n[i]) {
35 w = 1;
36
2/2
✓ Branch 0 taken 1021224 times.
✓ Branch 1 taken 1048384 times.
2069608 } else if (idx % 2 == 1) {
37 w = 4;
38 } else {
39 w = 2;
40 }
41 2123928 w_prod *= static_cast<double>(w);
42 }
43
1/2
✓ Branch 0 taken 925136 times.
✗ Branch 1 not taken.
1850272 return w_prod * func(point);
44 }
45 } // namespace
46
47
1/2
✓ Branch 1 taken 80 times.
✗ Branch 2 not taken.
80 RedkinaAIntegralSimpsonTBB::RedkinaAIntegralSimpsonTBB(const InType &in) {
48 SetTypeOfTask(GetStaticTypeOfTask());
49
1/2
✓ Branch 1 taken 80 times.
✗ Branch 2 not taken.
80 GetInput() = in;
50 80 }
51
52
1/2
✓ Branch 0 taken 80 times.
✗ Branch 1 not taken.
80 bool RedkinaAIntegralSimpsonTBB::ValidationImpl() {
53 const auto &in = GetInput();
54 size_t dim = in.a.size();
55
56
3/6
✓ Branch 0 taken 80 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 80 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 80 times.
80 if (dim == 0 || in.b.size() != dim || in.n.size() != dim) {
57 return false;
58 }
59
60
2/2
✓ Branch 0 taken 152 times.
✓ Branch 1 taken 80 times.
232 for (size_t i = 0; i < dim; ++i) {
61
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 152 times.
152 if (in.a[i] >= in.b[i]) {
62 return false;
63 }
64
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 152 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 152 times.
152 if (in.n[i] <= 0 || in.n[i] % 2 != 0) {
65 return false;
66 }
67 }
68
69 80 return static_cast<bool>(in.func);
70 }
71
72 80 bool RedkinaAIntegralSimpsonTBB::PreProcessingImpl() {
73 const auto &in = GetInput();
74 80 func_ = in.func;
75 80 a_ = in.a;
76 80 b_ = in.b;
77 80 n_ = in.n;
78 80 result_ = 0.0;
79 80 return true;
80 }
81
82
1/2
✓ Branch 0 taken 80 times.
✗ Branch 1 not taken.
80 bool RedkinaAIntegralSimpsonTBB::RunImpl() {
83
1/2
✓ Branch 0 taken 80 times.
✗ Branch 1 not taken.
80 if (!func_) {
84 return false;
85 }
86 size_t dim = a_.size();
87
1/2
✓ Branch 0 taken 80 times.
✗ Branch 1 not taken.
80 if (dim == 0) {
88 return false;
89 }
90
91 80 std::vector<double> h(dim);
92
2/2
✓ Branch 0 taken 152 times.
✓ Branch 1 taken 80 times.
232 for (size_t i = 0; i < dim; ++i) {
93 152 h[i] = (b_[i] - a_[i]) / static_cast<double>(n_[i]);
94 }
95
96 double h_prod = 1.0;
97
2/2
✓ Branch 0 taken 152 times.
✓ Branch 1 taken 80 times.
232 for (size_t i = 0; i < dim; ++i) {
98 152 h_prod *= h[i];
99 }
100
101
1/4
✓ Branch 1 taken 80 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
80 std::vector<int> dim_sizes(dim);
102 size_t total_points = 1;
103
2/2
✓ Branch 0 taken 152 times.
✓ Branch 1 taken 80 times.
232 for (size_t i = 0; i < dim; ++i) {
104 152 dim_sizes[i] = n_[i] + 1;
105 152 total_points *= static_cast<size_t>(dim_sizes[i]);
106 }
107
108
1/4
✓ Branch 1 taken 80 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
80 std::vector<size_t> strides(dim);
109 80 strides[dim - 1] = 1;
110
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 80 times.
152 for (size_t i = dim - 1; i > 0; --i) {
111 72 strides[i - 1] = strides[i] * static_cast<size_t>(dim_sizes[i]);
112 }
113
114 160 double sum = tbb::parallel_reduce(tbb::blocked_range<size_t>(0, total_points), 0.0,
115
1/2
✓ Branch 1 taken 80 times.
✗ Branch 2 not taken.
10215 [&](const tbb::blocked_range<size_t> &r, double local_sum) {
116
2/2
✓ Branch 0 taken 925136 times.
✓ Branch 1 taken 10135 times.
935271 for (size_t linear_idx = r.begin(); linear_idx != r.end(); ++linear_idx) {
117 925136 local_sum += ComputeNodeContribution(linear_idx, a_, h, n_, strides, func_);
118 }
119 10135 return local_sum;
120
0/2
✗ Branch 0 not taken.
✗ Branch 1 not taken.
299 }, [](double x, double y) -> double { return x + y; });
121
122 double denominator = 1.0;
123
2/2
✓ Branch 0 taken 152 times.
✓ Branch 1 taken 80 times.
232 for (size_t i = 0; i < dim; ++i) {
124 152 denominator *= 3.0;
125 }
126
127
1/2
✓ Branch 0 taken 80 times.
✗ Branch 1 not taken.
80 result_ = (h_prod / denominator) * sum;
128 return true;
129 }
130
131 80 bool RedkinaAIntegralSimpsonTBB::PostProcessingImpl() {
132 80 GetOutput() = result_;
133 80 return true;
134 }
135
136 } // namespace redkina_a_integral_simpson
137