GCC Code Coverage Report


Directory: ./
File: tasks/zyuzin_n_multi_integrals_simpson/omp/src/ops_omp.cpp
Date: 2026-04-02 17:12:27
Exec Total Coverage
Lines: 30 34 88.2%
Functions: 6 7 85.7%
Branches: 18 32 56.2%

Line Branch Exec Source
1 #include "zyuzin_n_multi_integrals_simpson/omp/include/ops_omp.hpp"
2
3 #include <cstddef>
4 #include <vector>
5
6 #include "zyuzin_n_multi_integrals_simpson/common/include/common.hpp"
7
8 namespace zyuzin_n_multi_integrals_simpson {
9
10
1/2
✓ Branch 1 taken 48 times.
✗ Branch 2 not taken.
48 ZyuzinNSimpsonOMP::ZyuzinNSimpsonOMP(const InType &in) {
11 SetTypeOfTask(GetStaticTypeOfTask());
12
1/2
✓ Branch 1 taken 48 times.
✗ Branch 2 not taken.
48 GetInput() = in;
13 48 GetOutput() = 0.0;
14 48 }
15
16
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 bool ZyuzinNSimpsonOMP::ValidationImpl() {
17 const auto &input = GetInput();
18
2/4
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 48 times.
48 if (input.lower_bounds.size() != input.upper_bounds.size() || input.lower_bounds.size() != input.n_steps.size()) {
19 return false;
20 }
21
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 48 times.
48 if (input.lower_bounds.empty()) {
22 return false;
23 }
24
2/2
✓ Branch 0 taken 96 times.
✓ Branch 1 taken 48 times.
144 for (size_t i = 0; i < input.lower_bounds.size(); ++i) {
25
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 96 times.
96 if (input.lower_bounds[i] > input.upper_bounds[i]) {
26 return false;
27 }
28
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 96 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 96 times.
96 if (input.n_steps[i] <= 0 || input.n_steps[i] % 2 != 0) {
29 return false;
30 }
31 }
32 48 return static_cast<bool>(input.func);
33 }
34
35 48 bool ZyuzinNSimpsonOMP::PreProcessingImpl() {
36 48 result_ = 0.0;
37 48 return true;
38 }
39
40 double ZyuzinNSimpsonOMP::GetSimpsonWeight(int index, int n) {
41 if (index == 0 || index == n) {
42 return 1.0;
43 }
44 if (index % 2 == 1) {
45 return 4.0;
46 }
47 return 2.0;
48 }
49
50 48 double ZyuzinNSimpsonOMP::ComputeSimpsonMultiDim() {
51 const auto &input = GetInput();
52 const size_t num_dims = input.lower_bounds.size();
53
54 48 std::vector<double> h(num_dims);
55
2/2
✓ Branch 0 taken 96 times.
✓ Branch 1 taken 48 times.
144 for (size_t dim = 0; dim < num_dims; ++dim) {
56 96 h[dim] = (input.upper_bounds[dim] - input.lower_bounds[dim]) / input.n_steps[dim];
57 }
58
59 size_t total_points = 1;
60
2/2
✓ Branch 0 taken 96 times.
✓ Branch 1 taken 48 times.
144 for (size_t dim = 0; dim < num_dims; ++dim) {
61 96 total_points *= static_cast<size_t>(input.n_steps[dim] + 1);
62 }
63
64 double sum = 0.0;
65
66 48 #pragma omp parallel for default(none) shared(input, total_points, num_dims, h) reduction(+ : sum)
67 for (size_t point_idx = 0; point_idx < total_points; ++point_idx) {
68 std::vector<int> indices(num_dims);
69 auto temp = point_idx;
70 for (size_t dim = 0; dim < num_dims; ++dim) {
71 indices[dim] = static_cast<int>(temp % static_cast<size_t>(input.n_steps[dim] + 1));
72 temp /= static_cast<size_t>(input.n_steps[dim] + 1);
73 }
74
75 std::vector<double> point(num_dims);
76 for (size_t dim = 0; dim < num_dims; ++dim) {
77 point[dim] = input.lower_bounds[dim] + (indices[dim] * h[dim]);
78 }
79
80 double weight = 1.0;
81 for (size_t dim = 0; dim < num_dims; ++dim) {
82 weight *= GetSimpsonWeight(indices[dim], input.n_steps[dim]);
83 }
84
85 sum += weight * input.func(point);
86 }
87
88 double factor = 1.0;
89
2/2
✓ Branch 0 taken 96 times.
✓ Branch 1 taken 48 times.
144 for (size_t dim = 0; dim < num_dims; ++dim) {
90 96 factor *= h[dim] / 3.0;
91 }
92
93
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 return sum * factor;
94 }
95
96 48 bool ZyuzinNSimpsonOMP::RunImpl() {
97 48 result_ = ComputeSimpsonMultiDim();
98 48 return true;
99 }
100
101 48 bool ZyuzinNSimpsonOMP::PostProcessingImpl() {
102 48 GetOutput() = result_;
103 48 return true;
104 }
105
106 } // namespace zyuzin_n_multi_integrals_simpson
107