GCC Code Coverage Report


Directory: ./
File: tasks/dergynov_s_integrals_multistep_rectangle/omp/src/ops_omp.cpp
Date: 2026-06-04 20:25:32
Exec Total Coverage
Lines: 32 32 100.0%
Functions: 5 5 100.0%
Branches: 16 28 57.1%

Line Branch Exec Source
1 #include "dergynov_s_integrals_multistep_rectangle/omp/include/ops_omp.hpp"
2
3 #include <omp.h>
4
5 #include <algorithm>
6 #include <cmath>
7 #include <cstddef>
8 #include <utility>
9 #include <vector>
10
11 #include "dergynov_s_integrals_multistep_rectangle/common/include/common.hpp"
12
13 namespace dergynov_s_integrals_multistep_rectangle {
14 namespace {
15
16 bool ValidateBorders(const std::vector<std::pair<double, double>> &borders) {
17 return std::ranges::all_of(borders, [](const auto &p) {
18 const auto &[left, right] = p;
19
3/6
✓ Branch 0 taken 132 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 132 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 132 times.
✗ Branch 5 not taken.
132 return std::isfinite(left) && std::isfinite(right) && left < right;
20 });
21 }
22
23 } // namespace
24
25
1/2
✓ Branch 1 taken 76 times.
✗ Branch 2 not taken.
76 DergynovSIntegralsMultistepRectangleOMP::DergynovSIntegralsMultistepRectangleOMP(const InType &in) {
26 SetTypeOfTask(GetStaticTypeOfTask());
27 GetInput() = in;
28 76 GetOutput() = 0.0;
29 76 }
30
31
1/2
✓ Branch 0 taken 76 times.
✗ Branch 1 not taken.
76 bool DergynovSIntegralsMultistepRectangleOMP::ValidationImpl() {
32 const auto &[func, borders, n] = GetInput();
33
34
1/2
✓ Branch 0 taken 76 times.
✗ Branch 1 not taken.
76 if (!func) {
35 return false;
36 }
37
1/2
✓ Branch 0 taken 76 times.
✗ Branch 1 not taken.
76 if (n <= 0) {
38 return false;
39 }
40
1/2
✓ Branch 0 taken 76 times.
✗ Branch 1 not taken.
76 if (borders.empty()) {
41 return false;
42 }
43
44 return ValidateBorders(borders);
45 }
46
47 76 bool DergynovSIntegralsMultistepRectangleOMP::PreProcessingImpl() {
48 76 GetOutput() = 0.0;
49 76 return true;
50 }
51
52 76 bool DergynovSIntegralsMultistepRectangleOMP::RunImpl() {
53 const auto &input = GetInput();
54 const auto &func = std::get<0>(input);
55 const auto &borders = std::get<1>(input);
56 76 int n = std::get<2>(input);
57
58 76 const int dim = static_cast<int>(borders.size());
59
60 76 std::vector<double> h(dim);
61 double cell_volume = 1.0;
62
63
2/2
✓ Branch 0 taken 132 times.
✓ Branch 1 taken 76 times.
208 for (int i = 0; i < dim; ++i) {
64 132 const double left = borders[i].first;
65 132 const double right = borders[i].second;
66 132 h[i] = (right - left) / n;
67 132 cell_volume *= h[i];
68 }
69
70 size_t total_points = 1;
71
2/2
✓ Branch 0 taken 132 times.
✓ Branch 1 taken 76 times.
208 for (int i = 0; i < dim; ++i) {
72 132 total_points *= n;
73 }
74
75
1/4
✓ Branch 2 taken 76 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
76 std::vector<double> local_sums(omp_get_max_threads(), 0.0);
76
77 76 int error_flag = 0;
78
79 76 #pragma omp parallel default(none) shared(func, borders, h, dim, n, total_points, local_sums, error_flag, cell_volume)
80 {
81 int thread_id = omp_get_thread_num();
82 double local_sum = 0.0;
83
84 #pragma omp for schedule(static)
85 for (size_t linear_idx = 0; linear_idx < total_points; ++linear_idx) {
86 if (error_flag != 0) {
87 continue;
88 }
89
90 size_t tmp = linear_idx;
91 std::vector<double> point(dim);
92
93 for (int dimension = dim - 1; dimension >= 0; --dimension) {
94 int idx_val = static_cast<int>(tmp % static_cast<size_t>(n));
95 tmp /= static_cast<size_t>(n);
96
97 point[dimension] = borders[dimension].first + ((static_cast<double>(idx_val) + 0.5) * h[dimension]);
98 }
99
100 double f_val = func(point);
101 if (!std::isfinite(f_val)) {
102 #pragma omp atomic write
103 error_flag = 1;
104 continue;
105 }
106 local_sum += f_val;
107 }
108
109 local_sums[thread_id] = local_sum;
110 }
111
112
1/2
✓ Branch 0 taken 76 times.
✗ Branch 1 not taken.
76 if (error_flag != 0) {
113 return false;
114 }
115
116 double total_sum = 0.0;
117
2/2
✓ Branch 0 taken 190 times.
✓ Branch 1 taken 76 times.
266 for (double s : local_sums) {
118 190 total_sum += s;
119 }
120
121 76 GetOutput() = total_sum * cell_volume;
122 76 return std::isfinite(GetOutput());
123 }
124
125 76 bool DergynovSIntegralsMultistepRectangleOMP::PostProcessingImpl() {
126 76 return std::isfinite(GetOutput());
127 }
128
129 } // namespace dergynov_s_integrals_multistep_rectangle
130