GCC Code Coverage Report


Directory: ./
File: tasks/kutergin_a_multidim_trapezoid/omp/src/ops_omp.cpp
Date: 2026-06-04 20:25:32
Exec Total Coverage
Lines: 29 29 100.0%
Functions: 5 5 100.0%
Branches: 21 38 55.3%

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