GCC Code Coverage Report


Directory: ./
File: tasks/vlasova_a_simpson_method/tbb/src/ops_tbb.cpp
Date: 2026-06-04 20:25:32
Exec Total Coverage
Lines: 58 58 100.0%
Functions: 8 8 100.0%
Branches: 30 40 75.0%

Line Branch Exec Source
1 #include "vlasova_a_simpson_method/tbb/include/ops_tbb.hpp"
2
3 #include <tbb/blocked_range.h>
4 #include <tbb/parallel_reduce.h>
5 #include <tbb/partitioner.h>
6
7 #include <cmath>
8 #include <cstddef>
9 #include <utility>
10 #include <vector>
11
12 #include "vlasova_a_simpson_method/common/include/common.hpp"
13
14 namespace vlasova_a_simpson_method {
15
16 88 VlasovaASimpsonMethodTBB::VlasovaASimpsonMethodTBB(InType in) : task_data_(std::move(in)) {
17 SetTypeOfTask(GetStaticTypeOfTask());
18 88 GetOutput() = 0.0;
19 88 }
20
21
1/2
✓ Branch 0 taken 88 times.
✗ Branch 1 not taken.
88 bool VlasovaASimpsonMethodTBB::ValidationImpl() {
22 size_t dim = task_data_.a.size();
23
24
3/6
✓ Branch 0 taken 88 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 88 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 88 times.
88 if (dim == 0 || dim != task_data_.b.size() || dim != task_data_.n.size()) {
25 return false;
26 }
27
28
2/2
✓ Branch 0 taken 168 times.
✓ Branch 1 taken 88 times.
256 for (size_t i = 0; i < dim; ++i) {
29
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 168 times.
168 if (task_data_.a[i] >= task_data_.b[i]) {
30 return false;
31 }
32
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 168 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 168 times.
168 if (task_data_.n[i] <= 0 || task_data_.n[i] % 2 != 0) {
33 return false;
34 }
35 }
36
37
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 88 times.
88 if (!task_data_.func) {
38 return false;
39 }
40
41 88 return GetOutput() == 0.0;
42 }
43
44 88 bool VlasovaASimpsonMethodTBB::PreProcessingImpl() {
45 88 result_ = 0.0;
46 88 GetOutput() = 0.0;
47
48 size_t dim = task_data_.a.size();
49 88 h_.resize(dim);
50 88 dimensions_.resize(dim);
51
52
2/2
✓ Branch 0 taken 168 times.
✓ Branch 1 taken 88 times.
256 for (size_t i = 0; i < dim; ++i) {
53 168 h_[i] = (task_data_.b[i] - task_data_.a[i]) / task_data_.n[i];
54 168 dimensions_[i] = task_data_.n[i] + 1;
55 }
56
57 88 return true;
58 }
59
60 620984 void VlasovaASimpsonMethodTBB::ComputeWeight(const std::vector<int> &index, double &weight) const {
61 620984 weight = 1.0;
62 size_t dim = index.size();
63
64
2/2
✓ Branch 0 taken 1857080 times.
✓ Branch 1 taken 620984 times.
2478064 for (size_t i = 0; i < dim; ++i) {
65 1857080 int idx = index[i];
66 1857080 int steps = task_data_.n[i];
67
68
2/2
✓ Branch 0 taken 1765192 times.
✓ Branch 1 taken 91888 times.
1857080 if (idx == 0 || idx == steps) {
69 weight *= 1.0;
70
2/2
✓ Branch 0 taken 859624 times.
✓ Branch 1 taken 905568 times.
1765192 } else if (idx % 2 == 0) {
71 859624 weight *= 2.0;
72 } else {
73 905568 weight *= 4.0;
74 }
75 }
76 620984 }
77
78 620984 void VlasovaASimpsonMethodTBB::ComputePoint(const std::vector<int> &index, std::vector<double> &point) const {
79 size_t dim = index.size();
80 620984 point.resize(dim);
81
82
2/2
✓ Branch 0 taken 1857080 times.
✓ Branch 1 taken 620984 times.
2478064 for (size_t i = 0; i < dim; ++i) {
83 1857080 point[i] = task_data_.a[i] + (index[i] * h_[i]);
84 }
85 620984 }
86
87 88 bool VlasovaASimpsonMethodTBB::RunImpl() {
88 size_t dim = task_data_.a.size();
89
90 size_t total_points = 1;
91
2/2
✓ Branch 0 taken 168 times.
✓ Branch 1 taken 88 times.
256 for (size_t i = 0; i < dim; ++i) {
92 168 total_points *= static_cast<size_t>(dimensions_[i]);
93 }
94
95 176 double sum = tbb::parallel_reduce(tbb::blocked_range<size_t>(0, total_points), 0.0,
96 88 [this, dim](const tbb::blocked_range<size_t> &range, double local_sum) {
97 11707 std::vector<int> cur_index(dim, 0);
98 11707 std::vector<double> cur_point;
99 11707 double local_weight = 0.0;
100
101
2/2
✓ Branch 0 taken 620984 times.
✓ Branch 1 taken 11707 times.
632691 for (size_t idx = range.begin(); idx != range.end(); ++idx) {
102 size_t temp_idx = idx;
103
2/2
✓ Branch 0 taken 1857080 times.
✓ Branch 1 taken 620984 times.
2478064 for (size_t i = 0; i < dim; ++i) {
104 1857080 cur_index[i] = static_cast<int>(temp_idx % static_cast<int>(dimensions_[i]));
105 1857080 temp_idx /= static_cast<int>(dimensions_[i]);
106 }
107
108 620984 ComputeWeight(cur_index, local_weight);
109
1/2
✓ Branch 1 taken 620984 times.
✗ Branch 2 not taken.
620984 ComputePoint(cur_index, cur_point);
110
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 620984 times.
1241968 local_sum += local_weight * task_data_.func(cur_point);
111 }
112 11707 return local_sum;
113 313 }, [](double x, double y) { return x + y; });
114
115 double factor = 1.0;
116
2/2
✓ Branch 0 taken 168 times.
✓ Branch 1 taken 88 times.
256 for (size_t i = 0; i < dim; ++i) {
117 168 factor *= h_[i] / 3.0;
118 }
119
120 88 result_ = sum * factor;
121 88 GetOutput() = result_;
122
123 88 return true;
124 }
125
126 88 bool VlasovaASimpsonMethodTBB::PostProcessingImpl() {
127 88 return std::isfinite(GetOutput());
128 }
129
130 } // namespace vlasova_a_simpson_method
131