GCC Code Coverage Report


Directory: ./
File: tasks/gutyansky_a_img_contrast_incr/all/src/ops_all.cpp
Date: 2026-06-04 20:25:32
Exec Total Coverage
Lines: 45 45 100.0%
Functions: 5 5 100.0%
Branches: 18 32 56.2%

Line Branch Exec Source
1 #include "gutyansky_a_img_contrast_incr/all/include/ops_all.hpp"
2
3 #include <mpi.h>
4
5 #include <algorithm>
6 #include <array>
7 #include <cstddef>
8 #include <cstdint>
9 #include <limits>
10 #include <utility>
11 #include <vector>
12
13 #include "gutyansky_a_img_contrast_incr/common/include/common.hpp"
14
15 namespace gutyansky_a_img_contrast_incr {
16
17
1/2
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
20 GutyanskyAImgContrastIncrALL::GutyanskyAImgContrastIncrALL(const InType &in) {
18 SetTypeOfTask(GetStaticTypeOfTask());
19
1/2
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
20 GetInput() = in;
20 GetOutput() = {};
21 20 }
22
23 20 bool GutyanskyAImgContrastIncrALL::ValidationImpl() {
24 20 return !GetInput().empty();
25 }
26
27 20 bool GutyanskyAImgContrastIncrALL::PreProcessingImpl() {
28 20 return true;
29 }
30
31 20 bool GutyanskyAImgContrastIncrALL::RunImpl() {
32 20 int rank = -1;
33 20 int p_count = -1;
34
35 20 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
36 20 MPI_Comm_size(MPI_COMM_WORLD, &p_count);
37
38 20 size_t sz = GetInput().size();
39
40 20 MPI_Bcast(&sz, 1, MPI_UINT64_T, 0, MPI_COMM_WORLD);
41
42 20 size_t chunk_size = sz / static_cast<size_t>(p_count);
43 20 size_t remainder_size = sz % static_cast<size_t>(p_count);
44
45
1/2
✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
20 size_t local_count = chunk_size + (std::cmp_less(rank, remainder_size) ? 1 : 0);
46
47 20 std::vector<uint8_t> local_data(local_count);
48
49
1/4
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
20 std::vector<int> send_counts(p_count);
50
1/4
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
20 std::vector<int> locs(p_count);
51
52
2/2
✓ Branch 0 taken 40 times.
✓ Branch 1 taken 20 times.
60 for (int i = 0; i < p_count; i++) {
53 40 size_t elems_for_proc = chunk_size + (std::cmp_less(i, remainder_size) ? 1 : 0);
54 40 send_counts[i] = static_cast<int>(elems_for_proc);
55 }
56
57
2/2
✓ Branch 0 taken 20 times.
✓ Branch 1 taken 20 times.
40 for (int i = 1; i < p_count; i++) {
58 20 locs[i] = locs[i - 1] + send_counts[i - 1];
59 }
60
61
1/2
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
20 MPI_Scatterv(GetInput().data(), send_counts.data(), locs.data(), MPI_UINT8_T, local_data.data(),
62 static_cast<int>(local_count), MPI_UINT8_T, 0, MPI_COMM_WORLD);
63
64 20 uint8_t local_lower_bound = std::numeric_limits<uint8_t>::max();
65 20 uint8_t local_upper_bound = std::numeric_limits<uint8_t>::min();
66
67 20 #pragma omp parallel for default(none) shared(local_data, local_count) reduction(min : local_lower_bound) \
68 reduction(max : local_upper_bound)
69 for (size_t i = 0; i < local_count; i++) {
70 uint8_t val = local_data[i];
71 local_lower_bound = std::min(local_lower_bound, val);
72 local_upper_bound = std::max(local_upper_bound, val);
73 }
74
75 20 uint8_t lower_bound = std::numeric_limits<uint8_t>::max();
76 20 uint8_t upper_bound = std::numeric_limits<uint8_t>::min();
77
78
1/2
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
20 MPI_Allreduce(&local_lower_bound, &lower_bound, 1, MPI_UINT8_T, MPI_MIN, MPI_COMM_WORLD);
79
1/2
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
20 MPI_Allreduce(&local_upper_bound, &upper_bound, 1, MPI_UINT8_T, MPI_MAX, MPI_COMM_WORLD);
80
81 20 uint8_t delta = upper_bound - lower_bound;
82
83
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 8 times.
20 if (delta != 0) {
84 12 std::array<uint8_t, 256> lut{};
85
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for (int pix = 0; pix < 256; pix++) {
86 3072 int shifted = pix - lower_bound;
87 3072 lut.at(pix) = static_cast<uint8_t>(255 * shifted / delta);
88 }
89
90 12 #pragma omp parallel for default(none) shared(local_data, local_count, lut)
91 for (size_t i = 0; i < local_count; i++) {
92 local_data[i] = lut.at(local_data[i]);
93 }
94 }
95
96
1/2
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
20 GetOutput().resize(sz);
97
1/2
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
20 MPI_Allgatherv(local_data.data(), static_cast<int>(local_count), MPI_UINT8_T, GetOutput().data(), send_counts.data(),
98 locs.data(), MPI_UINT8_T, MPI_COMM_WORLD);
99
100 20 return true;
101 }
102
103 20 bool GutyanskyAImgContrastIncrALL::PostProcessingImpl() {
104 20 return true;
105 }
106
107 } // namespace gutyansky_a_img_contrast_incr
108