GCC Code Coverage Report


Directory: ./
File: tasks/shkrebko_m_calc_of_integral_rect/omp/src/ops_omp.cpp
Date: 2026-04-02 17:12:27
Exec Total Coverage
Lines: 32 32 100.0%
Functions: 5 5 100.0%
Branches: 12 22 54.5%

Line Branch Exec Source
1 #include "shkrebko_m_calc_of_integral_rect/omp/include/ops_omp.hpp"
2
3 #include <omp.h>
4
5 #include <algorithm>
6 #include <cmath>
7 #include <cstddef>
8 #include <cstdint>
9 #include <vector>
10
11 #include "shkrebko_m_calc_of_integral_rect/common/include/common.hpp"
12 #include "util/include/util.hpp"
13
14 namespace shkrebko_m_calc_of_integral_rect {
15
16
1/2
✓ Branch 1 taken 40 times.
✗ Branch 2 not taken.
40 ShkrebkoMCalcOfIntegralRectOMP::ShkrebkoMCalcOfIntegralRectOMP(const InType &in) {
17 SetTypeOfTask(GetStaticTypeOfTask());
18
1/2
✓ Branch 1 taken 40 times.
✗ Branch 2 not taken.
40 GetInput() = in;
19 40 GetOutput() = 0.0;
20 40 }
21
22
1/2
✓ Branch 0 taken 40 times.
✗ Branch 1 not taken.
40 bool ShkrebkoMCalcOfIntegralRectOMP::ValidationImpl() {
23 const auto &input = GetInput();
24
25
1/2
✓ Branch 0 taken 40 times.
✗ Branch 1 not taken.
40 if (!input.func) {
26 return false;
27 }
28
2/4
✓ Branch 0 taken 40 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 40 times.
✗ Branch 3 not taken.
40 if (input.limits.size() != input.n_steps.size() || input.limits.empty()) {
29 return false;
30 }
31
1/2
✓ Branch 0 taken 40 times.
✗ Branch 1 not taken.
40 if (!std::ranges::all_of(input.n_steps, [](int n) { return n > 0; })) {
32 return false;
33 }
34
1/2
✓ Branch 0 taken 60 times.
✗ Branch 1 not taken.
60 if (!std::ranges::all_of(input.limits, [](const auto &lim) { return lim.first < lim.second; })) {
35 return false;
36 }
37
38 return true;
39 }
40
41 40 bool ShkrebkoMCalcOfIntegralRectOMP::PreProcessingImpl() {
42 40 local_input_ = GetInput();
43 40 res_ = 0.0;
44 40 return true;
45 }
46
47 40 bool ShkrebkoMCalcOfIntegralRectOMP::RunImpl() {
48 const std::size_t dims = local_input_.limits.size();
49 40 const auto &limits = local_input_.limits;
50 40 const auto &n_steps = local_input_.n_steps;
51 40 const auto &func = local_input_.func;
52
53 std::int64_t total_points = 1;
54 40 std::vector<double> h(dims);
55 double cell_volume = 1.0;
56
57
2/2
✓ Branch 0 taken 60 times.
✓ Branch 1 taken 40 times.
100 for (std::size_t i = 0; i < dims; ++i) {
58 60 const double left = limits[i].first;
59 60 const double right = limits[i].second;
60 60 const int steps = n_steps[i];
61
62 60 total_points *= static_cast<std::int64_t>(steps);
63 60 h[i] = (right - left) / static_cast<double>(steps);
64 60 cell_volume *= h[i];
65 }
66
67 double total_sum = 0.0;
68
69
1/2
✓ Branch 1 taken 40 times.
✗ Branch 2 not taken.
40 omp_set_num_threads(ppc::util::GetNumThreads());
70
71 40 #pragma omp parallel default(none) shared(total_points, h, limits, n_steps, func, dims) reduction(+ : total_sum)
72 {
73 std::vector<double> point(dims);
74
75 #pragma omp for
76 for (std::int64_t idx = 0; idx < total_points; ++idx) {
77 std::int64_t tmp = idx;
78
79 for (int dim = static_cast<int>(dims) - 1; dim >= 0; --dim) {
80 const int coord_index = static_cast<int>(tmp % n_steps[dim]);
81 tmp /= n_steps[dim];
82
83 point[dim] = limits[dim].first + ((static_cast<double>(coord_index) + 0.5) * h[dim]);
84 }
85
86 total_sum += func(point);
87 }
88 }
89
90
1/2
✓ Branch 0 taken 40 times.
✗ Branch 1 not taken.
40 res_ = total_sum * cell_volume;
91 40 return true;
92 }
93 40 bool ShkrebkoMCalcOfIntegralRectOMP::PostProcessingImpl() {
94 40 GetOutput() = res_;
95 40 return true;
96 }
97
98 } // namespace shkrebko_m_calc_of_integral_rect
99