GCC Code Coverage Report


Directory: ./
File: tasks/shemetov_d_increasing_contrast/mpi/src/ops_mpi.cpp
Date: 2026-01-27 01:59:34
Exec Total Coverage
Lines: 38 39 97.4%
Functions: 5 5 100.0%
Branches: 19 42 45.2%

Line Branch Exec Source
1 #include "shemetov_d_increasing_contrast/mpi/include/ops_mpi.hpp"
2
3 #include <mpi.h>
4
5 #include <algorithm>
6 #include <cstddef>
7 #include <cstdint>
8 #include <utility>
9 #include <vector>
10
11 #include "shemetov_d_increasing_contrast/common/include/common.hpp"
12
13 namespace shemetov_d_increasing_contrast {
14
15
1/2
✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
8 IncreaseContrastTaskMPI::IncreaseContrastTaskMPI(const InType &in) {
16 SetTypeOfTask(GetStaticTypeOfTask());
17
1/2
✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
8 GetInput() = in;
18
1/2
✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
8 GetOutput().resize(in.size());
19 8 }
20
21 8 bool IncreaseContrastTaskMPI::ValidationImpl() {
22 8 return !GetInput().empty();
23 }
24
25 8 bool IncreaseContrastTaskMPI::PreProcessingImpl() {
26 8 GetOutput().resize(GetInput().size());
27 8 return true;
28 }
29
30 8 bool IncreaseContrastTaskMPI::RunImpl() {
31 8 int rank = 0;
32 8 int size = 0;
33 8 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
34 8 MPI_Comm_size(MPI_COMM_WORLD, &size);
35
36 const size_t total_size = GetInput().size();
37
38 8 std::vector<int> count(size, static_cast<int>(total_size / size));
39
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 for (size_t i = 0; std::cmp_less(i, static_cast<int>(total_size % size)); ++i) {
40 count[i]++;
41 }
42
43
1/4
✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
8 std::vector<int> displacement(size, 0);
44
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 8 times.
16 for (int i = 1; i < size; ++i) {
45 8 displacement[i] = displacement[i - 1] + count[i - 1];
46 }
47
48
1/4
✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
8 std::vector<int> count_to_bytes(size);
49
1/4
✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
8 std::vector<int> displacement_to_bytes(size);
50
51
2/2
✓ Branch 0 taken 16 times.
✓ Branch 1 taken 8 times.
24 for (int i = 0; i < size; ++i) {
52 16 count_to_bytes[i] = count[i] * static_cast<int>(sizeof(Pixel));
53 16 displacement_to_bytes[i] = displacement[i] * static_cast<int>(sizeof(Pixel));
54 }
55
56
1/4
✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
8 std::vector<Pixel> local_input(count[rank]);
57
1/4
✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
8 std::vector<Pixel> local_output(count[rank]);
58
59
1/2
✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
8 MPI_Scatterv(GetInput().data(), count_to_bytes.data(), displacement_to_bytes.data(), MPI_BYTE, local_input.data(),
60
1/2
✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
8 count_to_bytes[rank], MPI_BYTE, 0, MPI_COMM_WORLD);
61
62 constexpr float kFactor = 1.3F;
63
64
2/2
✓ Branch 0 taken 263396 times.
✓ Branch 1 taken 8 times.
263404 for (size_t i = 0; i < local_input.size(); ++i) {
65 263396 const auto m_red = static_cast<float>(local_input[i].channel_red) * kFactor;
66 const auto m_green = static_cast<float>(local_input[i].channel_red) * kFactor;
67 const auto m_blue = static_cast<float>(local_input[i].channel_red) * kFactor;
68
69 263396 local_output[i].channel_red = static_cast<uint8_t>(std::clamp(m_red, 0.F, 255.F));
70 263396 local_output[i].channel_green = static_cast<uint8_t>(std::clamp(m_green, 0.F, 255.F));
71 263396 local_output[i].channel_blue = static_cast<uint8_t>(std::clamp(m_blue, 0.F, 255.F));
72 }
73
74
1/2
✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
8 MPI_Gatherv(local_output.data(), count_to_bytes[rank], MPI_BYTE, GetOutput().data(), count_to_bytes.data(),
75 displacement_to_bytes.data(), MPI_BYTE, 0, MPI_COMM_WORLD);
76
77
1/2
✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
8 MPI_Barrier(MPI_COMM_WORLD);
78 8 return true;
79 }
80
81 8 bool IncreaseContrastTaskMPI::PostProcessingImpl() {
82 8 return !GetOutput().empty();
83 }
84
85 } // namespace shemetov_d_increasing_contrast
86