GCC Code Coverage Report


Directory: ./
File: tasks/redkina_a_integral_simpson/omp/src/ops_omp.cpp
Date: 2026-04-02 17:12:27
Exec Total Coverage
Lines: 38 38 100.0%
Functions: 5 5 100.0%
Branches: 23 42 54.8%

Line Branch Exec Source
1 #include "redkina_a_integral_simpson/omp/include/ops_omp.hpp"
2
3 #include <omp.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
1/2
✓ Branch 1 taken 80 times.
✗ Branch 2 not taken.
80 RedkinaAIntegralSimpsonOMP::RedkinaAIntegralSimpsonOMP(const InType &in) {
15 SetTypeOfTask(GetStaticTypeOfTask());
16
1/2
✓ Branch 1 taken 80 times.
✗ Branch 2 not taken.
80 GetInput() = in;
17 80 }
18
19
1/2
✓ Branch 0 taken 80 times.
✗ Branch 1 not taken.
80 bool RedkinaAIntegralSimpsonOMP::ValidationImpl() {
20 const auto &in = GetInput();
21 size_t dim = in.a.size();
22
23
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) {
24 return false;
25 }
26
27
2/2
✓ Branch 0 taken 152 times.
✓ Branch 1 taken 80 times.
232 for (size_t i = 0; i < dim; ++i) {
28
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 152 times.
152 if (in.a[i] >= in.b[i]) {
29 return false;
30 }
31
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) {
32 return false;
33 }
34 }
35
36 80 return static_cast<bool>(in.func);
37 }
38
39 80 bool RedkinaAIntegralSimpsonOMP::PreProcessingImpl() {
40 const auto &in = GetInput();
41 80 func_ = in.func;
42 80 a_ = in.a;
43 80 b_ = in.b;
44 80 n_ = in.n;
45 80 result_ = 0.0;
46 80 return true;
47 }
48
49 80 bool RedkinaAIntegralSimpsonOMP::RunImpl() {
50 size_t dim = a_.size();
51
52 80 const std::vector<double> a_local = a_;
53
1/2
✓ Branch 1 taken 80 times.
✗ Branch 2 not taken.
80 const std::vector<double> b_local = b_;
54
1/2
✓ Branch 1 taken 80 times.
✗ Branch 2 not taken.
80 const std::vector<int> n_local = n_;
55
1/2
✓ Branch 1 taken 80 times.
✗ Branch 2 not taken.
80 const auto func_local = func_;
56
57
1/4
✓ Branch 1 taken 80 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
80 std::vector<double> h(dim);
58 double h_prod = 1.0;
59
2/2
✓ Branch 0 taken 152 times.
✓ Branch 1 taken 80 times.
232 for (size_t i = 0; i < dim; ++i) {
60 152 h[i] = (b_local[i] - a_local[i]) / static_cast<double>(n_local[i]);
61 152 h_prod *= h[i];
62 }
63
64
1/4
✓ Branch 1 taken 80 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
80 std::vector<int> strides(dim);
65 80 strides[dim - 1] = 1;
66
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 80 times.
152 for (int i = static_cast<int>(dim) - 2; i >= 0; --i) {
67 72 strides[i] = strides[i + 1] * (n_local[i + 1] + 1);
68 }
69 80 int total_nodes = strides[0] * (n_local[0] + 1);
70
71 double total_sum = 0.0;
72
73 80 #pragma omp parallel default(none) shared(total_nodes, h, strides, a_local, n_local, func_local, dim) \
74 reduction(+ : total_sum)
75 {
76 std::vector<int> indices(dim);
77 std::vector<double> point(dim);
78
79 #pragma omp for schedule(static)
80 for (int idx = 0; idx < total_nodes; ++idx) {
81 int remainder = idx;
82 for (size_t dim_idx = 0; dim_idx < dim; ++dim_idx) {
83 indices[dim_idx] = remainder / strides[dim_idx];
84 remainder %= strides[dim_idx];
85 }
86
87 double w_prod = 1.0;
88 for (size_t dim_idx = 0; dim_idx < dim; ++dim_idx) {
89 int i_idx = indices[dim_idx];
90 point[dim_idx] = a_local[dim_idx] + (i_idx * h[dim_idx]);
91
92 int w = 0;
93 if (i_idx == 0 || i_idx == n_local[dim_idx]) {
94 w = 1;
95 } else if (i_idx % 2 == 1) {
96 w = 4;
97 } else {
98 w = 2;
99 }
100 w_prod *= static_cast<double>(w);
101 }
102
103 total_sum += w_prod * func_local(point);
104 }
105 }
106
107 double denominator = 1.0;
108
2/2
✓ Branch 0 taken 152 times.
✓ Branch 1 taken 80 times.
232 for (size_t i = 0; i < dim; ++i) {
109 152 denominator *= 3.0;
110 }
111
112
1/2
✓ Branch 0 taken 80 times.
✗ Branch 1 not taken.
80 result_ = (h_prod / denominator) * total_sum;
113 80 return true;
114 }
115
116 80 bool RedkinaAIntegralSimpsonOMP::PostProcessingImpl() {
117 80 GetOutput() = result_;
118 80 return true;
119 }
120
121 } // namespace redkina_a_integral_simpson
122