GCC Code Coverage Report


Directory: ./
File: tasks/kosolapov_v_calc_mult_integrals_m_rectangles/omp/src/ops_omp.cpp
Date: 2026-04-02 17:12:27
Exec Total Coverage
Lines: 44 50 88.0%
Functions: 8 12 66.7%
Branches: 10 14 71.4%

Line Branch Exec Source
1 #include "kosolapov_v_calc_mult_integrals_m_rectangles/omp/include/ops_omp.hpp"
2
3 #include <omp.h>
4
5 #include <cmath>
6 #include <tuple>
7
8 #include "kosolapov_v_calc_mult_integrals_m_rectangles/common/include/common.hpp"
9
10 namespace kosolapov_v_calc_mult_integrals_m_rectangles {
11
12 32 KosolapovVCalcMultIntegralsMRectanglesOMP::KosolapovVCalcMultIntegralsMRectanglesOMP(const InType &in) {
13 SetTypeOfTask(GetStaticTypeOfTask());
14 32 GetInput() = InType(in);
15 GetOutput() = 0.0;
16 32 }
17
18 32 bool KosolapovVCalcMultIntegralsMRectanglesOMP::ValidationImpl() {
19 32 int steps = std::get<0>(GetInput());
20 32 int func_id = std::get<1>(GetInput());
21
2/4
✓ Branch 0 taken 32 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 32 times.
32 return steps > 0 && func_id >= 1 && func_id <= 4;
22 }
23
24 32 bool KosolapovVCalcMultIntegralsMRectanglesOMP::PreProcessingImpl() {
25 32 return true;
26 }
27
28 32 bool KosolapovVCalcMultIntegralsMRectanglesOMP::RunImpl() {
29 32 int steps = std::get<0>(GetInput());
30 32 int func_id = std::get<1>(GetInput());
31 32 std::tuple<double, double, double, double> temp = GetBounds(func_id);
32 32 double a = std::get<0>(temp);
33 32 double b = std::get<1>(temp);
34 32 double c = std::get<2>(temp);
35 32 double d = std::get<3>(temp);
36 32 double integral = RectanglesIntegral(func_id, steps, a, b, c, d);
37 32 GetOutput() = integral;
38 32 return true;
39 }
40
41 32 bool KosolapovVCalcMultIntegralsMRectanglesOMP::PostProcessingImpl() {
42 32 return true;
43 }
44
45 double KosolapovVCalcMultIntegralsMRectanglesOMP::Function1(double x, double y) {
46 // f(x,y) = x^2 + y^2
47 8000 return (x * x) + (y * y);
48 }
49 double KosolapovVCalcMultIntegralsMRectanglesOMP::Function2(double x, double y) {
50 // f(x,y) = sin(x) * cos(y)
51 8000 return std::sin(x) * std::cos(y);
52 }
53 double KosolapovVCalcMultIntegralsMRectanglesOMP::Function3(double x, double y) {
54 // f(x,y) = exp(-(x^2 + y^2))
55 8000 return std::exp(-((x * x) + (y * y)));
56 }
57 double KosolapovVCalcMultIntegralsMRectanglesOMP::Function4(double x, double y) {
58 // f(x,y) = sin(x + y)
59 8000 return std::sin(x + y);
60 }
61 32000 double KosolapovVCalcMultIntegralsMRectanglesOMP::CallFunction(int func_id, double x, double y) {
62
4/5
✓ Branch 0 taken 8000 times.
✓ Branch 1 taken 8000 times.
✓ Branch 2 taken 8000 times.
✓ Branch 3 taken 8000 times.
✗ Branch 4 not taken.
32000 switch (func_id) {
63 case 1:
64 8000 return Function1(x, y);
65 case 2:
66 8000 return Function2(x, y);
67 case 3:
68 8000 return Function3(x, y);
69 case 4:
70 8000 return Function4(x, y);
71 default:
72 return Function1(x, y);
73 }
74 }
75 32 std::tuple<double, double, double, double> KosolapovVCalcMultIntegralsMRectanglesOMP::GetBounds(int func_id) {
76
4/5
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 8 times.
✓ Branch 2 taken 8 times.
✓ Branch 3 taken 8 times.
✗ Branch 4 not taken.
32 switch (func_id) {
77 8 case 1:
78 return {0.0, 1.0, 0.0, 1.0};
79 8 case 2:
80 return {0.0, kPi, 0.0, kPi / 2.0};
81 8 case 3:
82 return {-1.0, 1.0, -1.0, 1.0};
83 8 case 4:
84 return {0.0, kPi, 0.0, kPi};
85 default:
86 return {0.0, 1.0, 0.0, 1.0};
87 }
88 }
89 32 double KosolapovVCalcMultIntegralsMRectanglesOMP::RectanglesIntegral(int func_id, int steps, double a, double b,
90 double c, double d) {
91 32 double hx = (b - a) / steps;
92 32 double hy = (d - c) / steps;
93 double result = 0.0;
94 32 #pragma omp parallel for reduction(+ : result) default(none) shared(steps, a, hx, c, hy, func_id)
95 for (int i = 0; i < steps; i++) {
96 double x = a + ((i + 0.5) * hx);
97 for (int j = 0; j < steps; j++) {
98 double y = c + ((j + 0.5) * hy);
99 result += CallFunction(func_id, x, y);
100 }
101 }
102 32 result *= (hx * hy);
103 32 return result;
104 }
105
106 } // namespace kosolapov_v_calc_mult_integrals_m_rectangles
107