GCC Code Coverage Report


Directory: ./
File: tasks/telnov_a_integral_rectangle/omp/src/ops_omp.cpp
Date: 2026-04-02 17:12:27
Exec Total Coverage
Lines: 18 18 100.0%
Functions: 5 5 100.0%
Branches: 2 4 50.0%

Line Branch Exec Source
1 #include "telnov_a_integral_rectangle/omp/include/ops_omp.hpp"
2
3 #include <omp.h>
4
5 #include <cmath>
6 #include <cstdint>
7
8 #include "telnov_a_integral_rectangle/common/include/common.hpp"
9
10 namespace telnov_a_integral_rectangle {
11
12 32 TelnovAIntegralRectangleOMP::TelnovAIntegralRectangleOMP(const InType &in) {
13 SetTypeOfTask(GetStaticTypeOfTask());
14 GetInput() = in;
15 GetOutput() = 0;
16 32 }
17
18 32 bool TelnovAIntegralRectangleOMP::ValidationImpl() {
19
2/4
✓ Branch 0 taken 32 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 32 times.
32 return GetInput().first > 0 && GetInput().second > 0;
20 }
21
22 32 bool TelnovAIntegralRectangleOMP::PreProcessingImpl() {
23 32 GetOutput() = 0.0;
24 32 return true;
25 }
26
27 32 bool TelnovAIntegralRectangleOMP::RunImpl() {
28 32 const int n = GetInput().first;
29 32 const int d = GetInput().second;
30
31 const double a = 0.0;
32 const double b = 1.0;
33 32 const double h = (b - a) / static_cast<double>(n);
34
35 32 const auto total_points = static_cast<int64_t>(std::pow(n, d));
36
37 double result = 0.0;
38
39 32 #pragma omp parallel for default(none) reduction(+ : result) shared(total_points, n, d, a, h)
40 for (int64_t idx = 0; idx < total_points; idx++) {
41 int64_t tmp = idx;
42 double f_value = 0.0;
43
44 for (int dim = 0; dim < d; dim++) {
45 const int coord_index = static_cast<int>(tmp % n);
46 tmp /= n;
47
48 const double x = a + ((static_cast<double>(coord_index) + 0.5) * h);
49 f_value += x;
50 }
51
52 result += f_value;
53 }
54
55 32 result *= std::pow(h, d);
56
57 32 GetOutput() = result;
58 32 return true;
59 }
60
61 32 bool TelnovAIntegralRectangleOMP::PostProcessingImpl() {
62 32 return true;
63 }
64
65 } // namespace telnov_a_integral_rectangle
66