GCC Code Coverage Report


Directory: ./
File: tasks/kiselev_i_trapezoidal_method_for_multidimensional_integrals/omp/src/ops_omp.cpp
Date: 2026-04-02 17:12:27
Exec Total Coverage
Lines: 46 46 100.0%
Functions: 7 7 100.0%
Branches: 21 25 84.0%

Line Branch Exec Source
1 #include "kiselev_i_trapezoidal_method_for_multidimensional_integrals/omp/include/ops_omp.hpp"
2
3 #include <omp.h>
4
5 #include <cmath>
6 #include <vector>
7
8 #include "kiselev_i_trapezoidal_method_for_multidimensional_integrals/common/include/common.hpp"
9
10 namespace kiselev_i_trapezoidal_method_for_multidimensional_integrals {
11
12
1/2
✓ Branch 1 taken 80 times.
✗ Branch 2 not taken.
80 KiselevITestTaskOMP::KiselevITestTaskOMP(const InType &in) {
13 SetTypeOfTask(GetStaticTypeOfTask());
14
1/2
✓ Branch 1 taken 80 times.
✗ Branch 2 not taken.
80 GetInput() = in;
15 80 GetOutput() = 0;
16 80 }
17
18 80 bool KiselevITestTaskOMP::ValidationImpl() {
19 80 return true;
20 }
21
22 80 bool KiselevITestTaskOMP::PreProcessingImpl() {
23 80 GetOutput() = 0.0;
24 80 return true;
25 }
26
27 12685572 double KiselevITestTaskOMP::FunctionTypeChoose(int type_x, double x, double y) {
28
5/5
✓ Branch 0 taken 3321640 times.
✓ Branch 1 taken 804808 times.
✓ Branch 2 taken 4781628 times.
✓ Branch 3 taken 1611864 times.
✓ Branch 4 taken 2165632 times.
12685572 switch (type_x) {
29 3321640 case 0:
30 3321640 return (x * x) + (y * y);
31 804808 case 1:
32 804808 return std::sin(x) * std::cos(y);
33 4781628 case 2:
34 4781628 return std::sin(x) + std::cos(y);
35 1611864 case 3:
36 1611864 return std::exp(x + y);
37 2165632 default:
38 2165632 return x + y;
39 }
40 }
41
42 132 double KiselevITestTaskOMP::ComputeIntegral(const std::vector<int> &steps) {
43 double result = 0.0;
44
45 132 double hx = (GetInput().right_bounds[0] - GetInput().left_bounds[0]) / steps[0];
46 132 double hy = (GetInput().right_bounds[1] - GetInput().left_bounds[1]) / steps[1];
47
48 const double x0 = GetInput().left_bounds[0];
49 const double y0 = GetInput().left_bounds[1];
50
51 int nx = steps[0];
52 int ny = steps[1];
53
54 132 const int func_type = GetInput().type_function;
55
56 132 #pragma omp parallel for reduction(+ : result) default(none) shared(nx, ny, hx, hy, x0, y0, func_type)
57 for (int i = 0; i <= nx; i++) {
58 for (int j = 0; j <= ny; j++) {
59 const double x = x0 + (i * hx);
60 const double y = y0 + (j * hy);
61
62 const double wx = (i == 0 || i == nx) ? 0.5 : 1.0;
63 const double wy = (j == 0 || j == ny) ? 0.5 : 1.0;
64
65 result += wx * wy * FunctionTypeChoose(func_type, x, y);
66 }
67 }
68
69 132 return result * hx * hy;
70 }
71
72 80 bool KiselevITestTaskOMP::RunImpl() {
73 80 std::vector<int> steps = GetInput().step_n_size;
74
2/2
✓ Branch 0 taken 76 times.
✓ Branch 1 taken 4 times.
80 double epsilon = GetInput().epsilon;
75
76 const auto &in = GetInput();
77
6/6
✓ Branch 0 taken 76 times.
✓ Branch 1 taken 4 times.
✓ Branch 2 taken 72 times.
✓ Branch 3 taken 4 times.
✓ Branch 4 taken 4 times.
✓ Branch 5 taken 68 times.
80 if (in.left_bounds.size() != 2 || in.right_bounds.size() != 2 || in.step_n_size.size() != 2) {
78 12 GetOutput() = 0.0;
79 12 return true;
80 }
81
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 64 times.
68 if (epsilon <= 0.0) {
82 4 GetOutput() = ComputeIntegral(steps);
83 4 return true;
84 }
85
86 64 double prev = ComputeIntegral(steps);
87 double current = prev;
88
89 int iter = 0;
90 const int max_iter = 1; // for time_limit
91
92
1/2
✓ Branch 0 taken 64 times.
✗ Branch 1 not taken.
64 while (iter < max_iter) {
93
2/2
✓ Branch 0 taken 128 times.
✓ Branch 1 taken 64 times.
192 for (auto &s : steps) {
94 128 s *= 2;
95 }
96
97 64 current = ComputeIntegral(steps);
98
99
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 64 times.
64 if (std::abs(current - prev) < epsilon) {
100 break;
101 }
102
103 prev = current;
104 iter++;
105 }
106
107 64 GetOutput() = current;
108 64 return true;
109 }
110
111 80 bool KiselevITestTaskOMP::PostProcessingImpl() {
112 80 return true;
113 }
114
115 } // namespace kiselev_i_trapezoidal_method_for_multidimensional_integrals
116