GCC Code Coverage Report


Directory: ./
File: tasks/terekhov_d_gauss_vert/omp/src/ops_omp.cpp
Date: 2026-04-02 17:12:27
Exec Total Coverage
Lines: 58 59 98.3%
Functions: 8 8 100.0%
Branches: 28 38 73.7%

Line Branch Exec Source
1 #include "terekhov_d_gauss_vert/omp/include/ops_omp.hpp"
2
3 #include <algorithm>
4 #include <cmath>
5 #include <cstddef>
6 #include <vector>
7
8 #include "terekhov_d_gauss_vert/common/include/common.hpp"
9
10 namespace terekhov_d_gauss_vert {
11
12 namespace {
13
14 5184 inline void ProcessPixel(OutType &output, const std::vector<int> &padded_image, int padded_width, int width, int row,
15 int col) {
16 5184 size_t idx = (static_cast<size_t>(row) * static_cast<size_t>(width)) + static_cast<size_t>(col);
17 float sum = 0.0F;
18
2/2
✓ Branch 0 taken 15552 times.
✓ Branch 1 taken 5184 times.
20736 for (int ky = -1; ky <= 1; ++ky) {
19
2/2
✓ Branch 0 taken 46656 times.
✓ Branch 1 taken 15552 times.
62208 for (int kx = -1; kx <= 1; ++kx) {
20 46656 int px = col + kx + 1;
21 46656 int py = row + ky + 1;
22 46656 int kernel_idx = ((ky + 1) * 3) + (kx + 1);
23 46656 size_t padded_idx = (static_cast<size_t>(py) * static_cast<size_t>(padded_width)) + static_cast<size_t>(px);
24 46656 sum += static_cast<float>(padded_image[padded_idx]) * kGaussKernel[static_cast<size_t>(kernel_idx)];
25 }
26 }
27 5184 output.data[idx] = static_cast<int>(std::lround(sum));
28 5184 }
29
30 48 inline void ProcessBand(OutType &output, const std::vector<int> &padded_image, int padded_width, int width, int height,
31 int band, int band_width, int num_bands) {
32 48 int start_x = band * band_width;
33
2/2
✓ Branch 0 taken 36 times.
✓ Branch 1 taken 12 times.
48 int end_x = (band == num_bands - 1) ? width : ((band + 1) * band_width);
34
2/2
✓ Branch 0 taken 832 times.
✓ Branch 1 taken 48 times.
880 for (int row = 0; row < height; ++row) {
35
2/2
✓ Branch 0 taken 5184 times.
✓ Branch 1 taken 832 times.
6016 for (int col = start_x; col < end_x; ++col) {
36 5184 ProcessPixel(output, padded_image, padded_width, width, row, col);
37 }
38 }
39 48 }
40
41 12 inline OutType SolveOMP(const std::vector<int> &padded_image, int width, int height) {
42 12 OutType output;
43 12 output.width = width;
44 12 output.height = height;
45
1/2
✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
12 output.data.resize(static_cast<size_t>(width) * static_cast<size_t>(height));
46
47 12 const int padded_width = width + 2;
48
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 const int band_width = std::max(width / 4, 1);
49 const int num_bands = 4;
50
51 12 #pragma omp parallel for default(none) \
52 shared(output, padded_image, padded_width, width, height, band_width, num_bands) schedule(static)
53 for (int band = 0; band < num_bands; ++band) {
54 ProcessBand(output, padded_image, padded_width, width, height, band, band_width, num_bands);
55 }
56
57 12 return output;
58 }
59
60 } // namespace
61
62
1/2
✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
12 TerekhovDGaussVertOMP::TerekhovDGaussVertOMP(const InType &in) {
63 SetTypeOfTask(GetStaticTypeOfTask());
64 GetInput() = in;
65 12 }
66
67 12 bool TerekhovDGaussVertOMP::ValidationImpl() {
68 const auto &input = GetInput();
69
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 if (input.width <= 0 || input.height <= 0) {
70 return false;
71 }
72
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if (static_cast<int>(input.data.size()) != input.width * input.height) {
73 return false;
74 }
75 return true;
76 }
77
78 12 bool TerekhovDGaussVertOMP::PreProcessingImpl() {
79 const auto &input = GetInput();
80 12 width_ = input.width;
81 12 height_ = input.height;
82
83 12 int padded_width = width_ + 2;
84 12 int padded_height = height_ + 2;
85 12 padded_image_.resize(static_cast<size_t>(padded_width) * static_cast<size_t>(padded_height));
86
87
2/2
✓ Branch 0 taken 232 times.
✓ Branch 1 taken 12 times.
244 for (int row = 0; row < padded_height; ++row) {
88
2/2
✓ Branch 0 taken 6064 times.
✓ Branch 1 taken 232 times.
6296 for (int col = 0; col < padded_width; ++col) {
89 6064 int src_x = col - 1;
90 6064 int src_y = row - 1;
91
92 6064 if (src_x < 0) {
93 src_x = -src_x - 1;
94 }
95
2/2
✓ Branch 0 taken 232 times.
✓ Branch 1 taken 5832 times.
6064 if (src_x >= width_) {
96 232 src_x = (2 * width_) - src_x - 1;
97 }
98 6064 if (src_y < 0) {
99 src_y = -src_y - 1;
100 }
101
2/2
✓ Branch 0 taken 232 times.
✓ Branch 1 taken 5832 times.
6064 if (src_y >= height_) {
102 232 src_y = (2 * height_) - src_y - 1;
103 }
104
105 6064 size_t padded_idx = (static_cast<size_t>(row) * static_cast<size_t>(padded_width)) + static_cast<size_t>(col);
106 6064 size_t src_idx = (static_cast<size_t>(src_y) * static_cast<size_t>(width_)) + static_cast<size_t>(src_x);
107 6064 padded_image_[padded_idx] = input.data[src_idx];
108 }
109 }
110 12 return true;
111 }
112
113
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 bool TerekhovDGaussVertOMP::RunImpl() {
114 const auto &input = GetInput();
115
3/6
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 12 times.
✗ Branch 5 not taken.
12 if (input.data.empty() || width_ <= 0 || height_ <= 0) {
116 return false;
117 }
118 12 GetOutput() = SolveOMP(padded_image_, width_, height_);
119 12 return true;
120 }
121
122 12 bool TerekhovDGaussVertOMP::PostProcessingImpl() {
123 12 return GetOutput().data.size() == (static_cast<size_t>(GetOutput().width) * static_cast<size_t>(GetOutput().height));
124 }
125
126 } // namespace terekhov_d_gauss_vert
127