GCC Code Coverage Report


Directory: ./
File: tasks/fedoseev_linear_image_filtering_vertical/all/src/ops_all.cpp
Date: 2026-06-04 20:25:32
Exec Total Coverage
Lines: 53 56 94.6%
Functions: 6 6 100.0%
Branches: 24 40 60.0%

Line Branch Exec Source
1 #include "fedoseev_linear_image_filtering_vertical/all/include/ops_all.hpp"
2
3 #include <mpi.h>
4
5 #include <algorithm>
6 #include <array>
7 #include <cstddef>
8 #include <utility>
9 #include <vector>
10
11 #include "fedoseev_linear_image_filtering_vertical/common/include/common.hpp"
12 #include "util/include/util.hpp"
13
14 namespace fedoseev_linear_image_filtering_vertical {
15
16 namespace {
17 3512 int ComputePixel(const std::vector<int> &img, int w, int h, int row, int col,
18 const std::array<std::array<int, 3>, 3> &kernel) {
19 const int kernel_sum = 16;
20 int sum = 0;
21
2/2
✓ Branch 0 taken 10536 times.
✓ Branch 1 taken 3512 times.
14048 for (int ky = -1; ky <= 1; ++ky) {
22
2/2
✓ Branch 0 taken 31608 times.
✓ Branch 1 taken 10536 times.
42144 for (int kx = -1; kx <= 1; ++kx) {
23 31608 int px = col + kx;
24 31608 int py = row + ky;
25 31608 px = std::clamp(px, 0, w - 1);
26 31608 py = std::clamp(py, 0, h - 1);
27 31608 sum += img[(static_cast<size_t>(py) * static_cast<size_t>(w)) + static_cast<size_t>(px)] *
28 31608 kernel.at(ky + 1).at(kx + 1);
29 }
30 }
31 3512 return sum / kernel_sum;
32 }
33 } // namespace
34
35
1/2
✓ Branch 1 taken 40 times.
✗ Branch 2 not taken.
40 LinearImageFilteringVerticalAll::LinearImageFilteringVerticalAll(const InType &in) {
36 SetTypeOfTask(GetStaticTypeOfTask());
37 GetInput() = in;
38 40 GetOutput() = InType{};
39 40 }
40
41 40 bool LinearImageFilteringVerticalAll::ValidationImpl() {
42 const InType &input = GetInput();
43
2/4
✓ Branch 0 taken 40 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 40 times.
✗ Branch 3 not taken.
40 if (input.width < 3 || input.height < 3) {
44 return false;
45 }
46
1/2
✓ Branch 0 taken 40 times.
✗ Branch 1 not taken.
40 if (input.data.size() != static_cast<size_t>(input.width) * static_cast<size_t>(input.height)) {
47 return false;
48 }
49 40 int initialized = 0;
50 40 MPI_Initialized(&initialized);
51 40 return initialized != 0;
52 }
53
54 40 bool LinearImageFilteringVerticalAll::PreProcessingImpl() {
55 40 return true;
56 }
57
58 40 bool LinearImageFilteringVerticalAll::RunImpl() {
59 40 int rank = 0;
60 40 int size = 1;
61 40 bool is_mpi = ppc::util::IsUnderMpirun();
62
1/2
✓ Branch 0 taken 40 times.
✗ Branch 1 not taken.
40 if (is_mpi) {
63 40 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
64 40 MPI_Comm_size(MPI_COMM_WORLD, &size);
65 }
66
67 40 int w = 0;
68 40 int h = 0;
69 40 std::vector<int> img;
70
2/2
✓ Branch 0 taken 20 times.
✓ Branch 1 taken 20 times.
40 if (rank == 0) {
71 const InType &input = GetInput();
72 20 w = input.width;
73 20 h = input.height;
74
1/2
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
20 img = input.data;
75 }
76
77
1/2
✓ Branch 0 taken 40 times.
✗ Branch 1 not taken.
40 if (is_mpi) {
78
1/2
✓ Branch 1 taken 40 times.
✗ Branch 2 not taken.
40 MPI_Bcast(&w, 1, MPI_INT, 0, MPI_COMM_WORLD);
79
1/2
✓ Branch 1 taken 40 times.
✗ Branch 2 not taken.
40 MPI_Bcast(&h, 1, MPI_INT, 0, MPI_COMM_WORLD);
80
2/2
✓ Branch 0 taken 20 times.
✓ Branch 1 taken 20 times.
40 if (rank != 0) {
81
1/2
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
20 img.resize(static_cast<size_t>(w) * static_cast<size_t>(h));
82 }
83
1/2
✓ Branch 1 taken 40 times.
✗ Branch 2 not taken.
40 MPI_Bcast(img.data(), static_cast<int>(img.size()), MPI_INT, 0, MPI_COMM_WORLD);
84 } else {
85 const InType &input = GetInput();
86 w = input.width;
87 h = input.height;
88 img = input.data;
89 }
90
91 40 const std::array<std::array<int, 3>, 3> kernel = {{{{1, 2, 1}}, {{2, 4, 2}}, {{1, 2, 1}}}};
92
1/4
✓ Branch 1 taken 40 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
40 std::vector<int> result(static_cast<size_t>(w) * static_cast<size_t>(h), 0);
93
94
2/2
✓ Branch 0 taken 328 times.
✓ Branch 1 taken 40 times.
368 for (int row = 0; row < h; ++row) {
95
2/2
✓ Branch 0 taken 3512 times.
✓ Branch 1 taken 328 times.
3840 for (int col = 0; col < w; ++col) {
96 3512 result[(static_cast<size_t>(row) * static_cast<size_t>(w)) + static_cast<size_t>(col)] =
97 3512 ComputePixel(img, w, h, row, col, kernel);
98 }
99 }
100
101 40 OutType out;
102 40 out.width = w;
103 40 out.height = h;
104 out.data = std::move(result);
105 GetOutput() = out;
106
107 40 return true;
108 }
109
110 40 bool LinearImageFilteringVerticalAll::PostProcessingImpl() {
111 40 return true;
112 }
113
114 } // namespace fedoseev_linear_image_filtering_vertical
115