GCC Code Coverage Report


Directory: ./
File: tasks/ovsyannikov_n_simpson_method/omp/src/ops_omp.cpp
Date: 2026-04-02 17:12:27
Exec Total Coverage
Lines: 22 27 81.5%
Functions: 5 7 71.4%
Branches: 4 12 33.3%

Line Branch Exec Source
1 #include "ovsyannikov_n_simpson_method/omp/include/ops_omp.hpp"
2
3 #include <omp.h>
4
5 #include <cmath>
6
7 #include "ovsyannikov_n_simpson_method/common/include/common.hpp"
8
9 namespace ovsyannikov_n_simpson_method {
10
11 double OvsyannikovNSimpsonMethodOMP::Function(double x, double y) {
12 return x + y;
13 }
14
15 double OvsyannikovNSimpsonMethodOMP::GetCoeff(int i, int n) {
16 if (i == 0 || i == n) {
17 return 1.0;
18 }
19 return (i % 2 == 1) ? 4.0 : 2.0;
20 }
21
22 24 OvsyannikovNSimpsonMethodOMP::OvsyannikovNSimpsonMethodOMP(const InType &in) {
23 SetTypeOfTask(GetStaticTypeOfTask());
24 24 GetInput() = in;
25 24 }
26
27 24 bool OvsyannikovNSimpsonMethodOMP::ValidationImpl() {
28
4/8
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 24 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 24 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 24 times.
24 return GetInput().nx > 0 && GetInput().nx % 2 == 0 && GetInput().ny > 0 && GetInput().ny % 2 == 0;
29 }
30
31 24 bool OvsyannikovNSimpsonMethodOMP::PreProcessingImpl() {
32 24 params_ = GetInput();
33 24 res_ = 0.0;
34 24 return true;
35 }
36
37 24 bool OvsyannikovNSimpsonMethodOMP::RunImpl() {
38 24 const int nx_l = params_.nx;
39 24 const int ny_l = params_.ny;
40 24 const double ax_l = params_.ax;
41 24 const double ay_l = params_.ay;
42 24 const double hx_l = (params_.bx - params_.ax) / nx_l;
43 24 const double hy_l = (params_.by - params_.ay) / ny_l;
44
45 double total_sum = 0.0;
46
47 24 #pragma omp parallel for default(none) shared(nx_l, ny_l, ax_l, ay_l, hx_l, hy_l) reduction(+ : total_sum)
48 for (int i = 0; i <= nx_l; ++i) {
49 const double x = ax_l + (i * hx_l);
50 const double coeff_x = GetCoeff(i, nx_l);
51 double row_sum = 0.0;
52 for (int j = 0; j <= ny_l; ++j) {
53 const double y = ay_l + (j * hy_l);
54 const double coeff_y = GetCoeff(j, ny_l);
55 row_sum += coeff_y * Function(x, y);
56 }
57 total_sum += coeff_x * row_sum;
58 }
59
60 24 res_ = (hx_l * hy_l / 9.0) * total_sum;
61 24 return true;
62 }
63
64 24 bool OvsyannikovNSimpsonMethodOMP::PostProcessingImpl() {
65 24 GetOutput() = res_;
66 24 return true;
67 }
68
69 } // namespace ovsyannikov_n_simpson_method
70