GCC Code Coverage Report


Directory: ./
File: tasks/kiselev_i_trapezoidal_method_for_multidimensional_integrals/tbb/src/ops_tbb.cpp
Date: 2026-05-11 08:26:31
Exec Total Coverage
Lines: 55 56 98.2%
Functions: 8 8 100.0%
Branches: 38 45 84.4%

Line Branch Exec Source
1 #include "kiselev_i_trapezoidal_method_for_multidimensional_integrals/tbb/include/ops_tbb.hpp"
2
3 #include <tbb/blocked_range2d.h>
4 #include <tbb/parallel_reduce.h>
5
6 #include <cmath>
7 #include <functional>
8 #include <vector>
9
10 #include "kiselev_i_trapezoidal_method_for_multidimensional_integrals/common/include/common.hpp"
11
12 namespace kiselev_i_trapezoidal_method_for_multidimensional_integrals {
13
14
1/2
✓ Branch 1 taken 72 times.
✗ Branch 2 not taken.
72 KiselevITestTaskTBB::KiselevITestTaskTBB(const InType &in) {
15 SetTypeOfTask(GetStaticTypeOfTask());
16
1/2
✓ Branch 1 taken 72 times.
✗ Branch 2 not taken.
72 GetInput() = in;
17 72 GetOutput() = 0;
18 72 }
19
20 72 bool KiselevITestTaskTBB::ValidationImpl() {
21 72 return true;
22 }
23
24 72 bool KiselevITestTaskTBB::PreProcessingImpl() {
25 72 GetOutput() = 0.0;
26 72 return true;
27 }
28
29 9071156 double KiselevITestTaskTBB::FunctionTypeChoose(int type_x, double x, double y) {
30
5/5
✓ Branch 0 taken 3321640 times.
✓ Branch 1 taken 804808 times.
✓ Branch 2 taken 1167212 times.
✓ Branch 3 taken 1611864 times.
✓ Branch 4 taken 2165632 times.
9071156 switch (type_x) {
31 3321640 case 0:
32 3321640 return (x * x) + (y * y);
33 804808 case 1:
34 804808 return std::sin(x) * std::cos(y);
35 1167212 case 2:
36 1167212 return std::sin(x) + std::cos(y);
37 1611864 case 3:
38 1611864 return std::exp(x + y);
39 2165632 default:
40 2165632 return x + y;
41 }
42 }
43
44 116 double KiselevITestTaskTBB::ComputeIntegral(const std::vector<int> &steps) {
45 const auto &in = GetInput();
46
47 116 double hx = (in.right_bounds[0] - in.left_bounds[0]) / steps[0];
48 116 double hy = (in.right_bounds[1] - in.left_bounds[1]) / steps[1];
49 using Range2d = tbb::blocked_range2d<int, int>;
50
51 232 double result = tbb::parallel_reduce(Range2d(0, steps[0] + 1, 32, 0, steps[1] + 1, 32), 0.0,
52 17788 [&](const Range2d &r, double local_sum) {
53
2/2
✓ Branch 0 taken 396640 times.
✓ Branch 1 taken 17672 times.
414312 for (int i = r.rows().begin(); i < r.rows().end(); ++i) {
54
2/2
✓ Branch 0 taken 395320 times.
✓ Branch 1 taken 1320 times.
396640 double x = in.left_bounds[0] + (i * hx);
55
4/4
✓ Branch 0 taken 395320 times.
✓ Branch 1 taken 1320 times.
✓ Branch 2 taken 1320 times.
✓ Branch 3 taken 394000 times.
396640 double wx = (i == 0 || i == steps[0]) ? 0.5 : 1.0;
56
57
2/2
✓ Branch 0 taken 9071156 times.
✓ Branch 1 taken 396640 times.
9467796 for (int j = r.cols().begin(); j < r.cols().end(); ++j) {
58 9071156 double y = in.left_bounds[1] + (j * hy);
59
4/4
✓ Branch 0 taken 9041520 times.
✓ Branch 1 taken 29636 times.
✓ Branch 2 taken 29636 times.
✓ Branch 3 taken 9011884 times.
9071156 double wy = (j == 0 || j == steps[1]) ? 0.5 : 1.0;
60
61 9071156 local_sum += wx * wy * FunctionTypeChoose(in.type_function, x, y);
62 }
63 }
64 17672 return local_sum;
65 116 }, std::plus<>());
66
67 116 return result * hx * hy;
68 }
69
70 72 bool KiselevITestTaskTBB::RunImpl() {
71 72 std::vector<int> steps = GetInput().step_n_size;
72
2/2
✓ Branch 0 taken 68 times.
✓ Branch 1 taken 4 times.
72 double epsilon = GetInput().epsilon;
73
74 const auto &in = GetInput();
75
6/6
✓ Branch 0 taken 68 times.
✓ Branch 1 taken 4 times.
✓ Branch 2 taken 64 times.
✓ Branch 3 taken 4 times.
✓ Branch 4 taken 4 times.
✓ Branch 5 taken 60 times.
72 if (in.left_bounds.size() != 2 || in.right_bounds.size() != 2 || in.step_n_size.size() != 2) {
76 12 GetOutput() = 0.0;
77 12 return true;
78 }
79
80
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 56 times.
60 if (epsilon <= 0.0) {
81
1/2
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
4 GetOutput() = ComputeIntegral(steps);
82 4 return true;
83 }
84
85
1/2
✓ Branch 1 taken 56 times.
✗ Branch 2 not taken.
56 double prev = ComputeIntegral(steps);
86 double current = prev;
87
88 int iter = 0;
89 const int max_iter = 10;
90
91
1/2
✓ Branch 0 taken 56 times.
✗ Branch 1 not taken.
56 while (iter < max_iter) {
92
2/2
✓ Branch 0 taken 112 times.
✓ Branch 1 taken 56 times.
168 for (auto &s : steps) {
93 112 s *= 2;
94 }
95
96
1/2
✓ Branch 1 taken 56 times.
✗ Branch 2 not taken.
56 current = ComputeIntegral(steps);
97
98
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 56 times.
56 if (std::abs(current - prev) < epsilon) {
99 break;
100 }
101
102 prev = current;
103 iter++;
104 }
105
106 56 GetOutput() = current;
107 56 return true;
108 }
109
110 72 bool KiselevITestTaskTBB::PostProcessingImpl() {
111 72 return true;
112 }
113
114 } // namespace kiselev_i_trapezoidal_method_for_multidimensional_integrals
115