GCC Code Coverage Report


Directory: ./
File: tasks/nazyrov_a_multidim_integral_rectangle/omp/src/ops_omp.cpp
Date: 2026-06-04 20:25:32
Exec Total Coverage
Lines: 25 25 100.0%
Functions: 5 5 100.0%
Branches: 13 22 59.1%

Line Branch Exec Source
1 #include "nazyrov_a_multidim_integral_rectangle/omp/include/ops_omp.hpp"
2
3 #include <algorithm>
4 #include <cmath>
5 #include <cstddef>
6 #include <cstdint>
7 #include <vector>
8
9 #include "nazyrov_a_multidim_integral_rectangle/common/include/common.hpp"
10
11 namespace nazyrov_a_multidim_integral_rectangle {
12
13
1/2
✓ Branch 1 taken 40 times.
✗ Branch 2 not taken.
40 NazyrovAMultidimIntegralRectangleOmp::NazyrovAMultidimIntegralRectangleOmp(const InType &in) {
14 SetTypeOfTask(GetStaticTypeOfTask());
15 GetInput() = in;
16 40 GetOutput() = 0.0;
17 40 }
18
19 40 bool NazyrovAMultidimIntegralRectangleOmp::ValidationImpl() {
20 const auto &func = std::get<0>(GetInput());
21 const auto &bounds = std::get<1>(GetInput());
22
1/2
✓ Branch 0 taken 40 times.
✗ Branch 1 not taken.
40 const int n = std::get<2>(GetInput());
23
3/6
✓ Branch 0 taken 40 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 40 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 40 times.
✗ Branch 5 not taken.
40 return func && n > 0 && !bounds.empty() && std::ranges::all_of(bounds, [](const auto &bd) {
24
3/6
✓ Branch 0 taken 84 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 84 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 84 times.
✗ Branch 5 not taken.
84 return std::isfinite(bd.first) && std::isfinite(bd.second) && bd.first < bd.second;
25 40 });
26 }
27
28 40 bool NazyrovAMultidimIntegralRectangleOmp::PreProcessingImpl() {
29 40 return true;
30 }
31
32 40 bool NazyrovAMultidimIntegralRectangleOmp::RunImpl() {
33 const auto &func = std::get<0>(GetInput());
34 const auto &bounds = std::get<1>(GetInput());
35 40 const int n = std::get<2>(GetInput());
36
37 40 const int dim = static_cast<int>(bounds.size());
38
39 40 std::vector<double> h(static_cast<std::size_t>(dim));
40 double cell_vol = 1.0;
41
2/2
✓ Branch 0 taken 84 times.
✓ Branch 1 taken 40 times.
124 for (int i = 0; i < dim; ++i) {
42 84 h[i] = (bounds[i].second - bounds[i].first) / n;
43 84 cell_vol *= h[i];
44 }
45
46 std::int64_t total = 1;
47
2/2
✓ Branch 0 taken 84 times.
✓ Branch 1 taken 40 times.
124 for (int i = 0; i < dim; ++i) {
48 84 total *= n;
49 }
50
51 40 double sum = 0.0;
52
53 40 #pragma omp parallel default(none) shared(func, bounds, h, n, dim, total, sum)
54 {
55 std::vector<double> point(static_cast<std::size_t>(dim));
56 double thread_sum = 0.0;
57
58 #pragma omp for schedule(static)
59 for (std::int64_t cell = 0; cell < total; ++cell) {
60 std::int64_t tmp = cell;
61 for (int i = dim - 1; i >= 0; --i) {
62 const int ki = static_cast<int>(tmp % n);
63 tmp /= n;
64 const double coordinate = bounds[i].first + ((ki + 0.5) * h[i]);
65 point[i] = coordinate;
66 }
67 thread_sum += func(point);
68 }
69
70 #pragma omp atomic
71 sum += thread_sum;
72 }
73
74
1/2
✓ Branch 0 taken 40 times.
✗ Branch 1 not taken.
40 GetOutput() = sum * cell_vol;
75 40 return true;
76 }
77
78 40 bool NazyrovAMultidimIntegralRectangleOmp::PostProcessingImpl() {
79 40 return true;
80 }
81
82 } // namespace nazyrov_a_multidim_integral_rectangle
83