GCC Code Coverage Report


Directory: ./
File: tasks/tsibareva_e_integral_calculate_trapezoid_method/tbb/src/ops_tbb.cpp
Date: 2026-05-11 08:26:31
Exec Total Coverage
Lines: 39 40 97.5%
Functions: 6 6 100.0%
Branches: 22 30 73.3%

Line Branch Exec Source
1 // ops_tbb.cpp
2 #include "tsibareva_e_integral_calculate_trapezoid_method/tbb/include/ops_tbb.hpp"
3
4 #include <tbb/blocked_range.h>
5 #include <tbb/parallel_reduce.h>
6
7 #include <cmath>
8 #include <functional>
9 #include <vector>
10
11 #include "tsibareva_e_integral_calculate_trapezoid_method/common/include/common.hpp"
12
13 namespace tsibareva_e_integral_calculate_trapezoid_method {
14
15 24 TsibarevaEIntegralCalculateTrapezoidMethodTBB::TsibarevaEIntegralCalculateTrapezoidMethodTBB(const InType &in)
16
1/2
✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
24 : BaseTask() {
17 SetTypeOfTask(GetStaticTypeOfTask());
18
1/2
✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
24 GetInput() = in;
19 24 GetOutput() = 0.0;
20 24 }
21
22 24 bool TsibarevaEIntegralCalculateTrapezoidMethodTBB::ValidationImpl() {
23 24 return true;
24 }
25
26 24 bool TsibarevaEIntegralCalculateTrapezoidMethodTBB::PreProcessingImpl() {
27 24 GetOutput() = 0.0;
28 24 return true;
29 }
30
31 24 bool TsibarevaEIntegralCalculateTrapezoidMethodTBB::RunImpl() {
32 const Integral &input_i = GetInput();
33 24 int dim = input_i.dim;
34
35 24 std::vector<double> h(dim);
36
1/4
✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
24 std::vector<int> sizes(dim);
37 int total_nodes = 1;
38
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 24 times.
72 for (int i = 0; i < dim; ++i) {
39 48 h[i] = (input_i.hi[i] - input_i.lo[i]) / input_i.steps[i];
40 48 sizes[i] = input_i.steps[i] + 1;
41 48 total_nodes *= sizes[i];
42 }
43
44 48 double res_sum = tbb::parallel_reduce(tbb::blocked_range<int>(0, total_nodes), 0.0,
45
1/2
✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
24 [&](const tbb::blocked_range<int> &r, double local_sum) {
46 5932 return local_sum + ComputeSumNode(r, 0.0, input_i, h, sizes);
47 }, std::plus<>());
48
49 double res_h = 1.0;
50
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 24 times.
72 for (int i = 0; i < dim; ++i) {
51 48 res_h *= h[i];
52 }
53
2/2
✓ Branch 0 taken 20 times.
✓ Branch 1 taken 4 times.
24 GetOutput() = res_sum * res_h;
54 24 return true;
55 }
56
57 24 bool TsibarevaEIntegralCalculateTrapezoidMethodTBB::PostProcessingImpl() {
58 24 return true;
59 }
60
61 5932 double TsibarevaEIntegralCalculateTrapezoidMethodTBB::ComputeSumNode(const tbb::blocked_range<int> &range, double init,
62 const Integral &input_i,
63 const std::vector<double> &h,
64 const std::vector<int> &sizes) {
65 double sum = init;
66 5932 int dim = input_i.dim;
67
68
2/2
✓ Branch 0 taken 857984 times.
✓ Branch 1 taken 5932 times.
863916 for (int node = range.begin(); node != range.end(); ++node) {
69 int rem = node;
70 double node_w = 1.0;
71 857984 std::vector<double> point(dim);
72
73
2/2
✓ Branch 0 taken 2522248 times.
✓ Branch 1 taken 857984 times.
3380232 for (int i = dim - 1; i >= 0; --i) {
74
2/2
✓ Branch 0 taken 2469560 times.
✓ Branch 1 taken 52688 times.
2522248 int idx = rem % sizes[i];
75 2522248 rem /= sizes[i];
76
77
4/4
✓ Branch 0 taken 2469560 times.
✓ Branch 1 taken 52688 times.
✓ Branch 2 taken 52688 times.
✓ Branch 3 taken 2416872 times.
2522248 if (idx == 0 || idx == input_i.steps[i]) {
78 105376 node_w *= 0.5;
79 }
80
81 2522248 point[i] = input_i.lo[i] + (idx * h[i]);
82 }
83
84
2/2
✓ Branch 0 taken 857980 times.
✓ Branch 1 taken 4 times.
857984 sum += node_w * input_i.f(point);
85 }
86
87 5932 return sum;
88 }
89
90 } // namespace tsibareva_e_integral_calculate_trapezoid_method
91