GCC Code Coverage Report


Directory: ./
File: tasks/lukin_i_ench_contr_lin_hist/all/src/ops_all.cpp
Date: 2026-05-11 08:26:31
Exec Total Coverage
Lines: 55 55 100.0%
Functions: 5 5 100.0%
Branches: 34 58 58.6%

Line Branch Exec Source
1 #include "lukin_i_ench_contr_lin_hist/all/include/ops_all.hpp"
2
3 #include <mpi.h>
4
5 #include <algorithm>
6 #include <vector>
7
8 #include "lukin_i_ench_contr_lin_hist/common/include/common.hpp"
9
10 namespace lukin_i_ench_contr_lin_hist {
11
12
1/2
✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
8 LukinITestTaskALL::LukinITestTaskALL(const InType &in) {
13 SetTypeOfTask(GetStaticTypeOfTask());
14
15 8 int rank = -1;
16
1/2
✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
8 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
17
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 4 times.
8 if (rank == 0) {
18
1/2
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
4 GetInput() = in;
19 }
20
21
1/2
✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
8 GetOutput() = OutType(GetInput().size());
22 8 }
23
24 8 bool LukinITestTaskALL::ValidationImpl() {
25 8 int rank = 0;
26 8 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
27
28
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 4 times.
8 if (rank == 0) {
29 4 return (static_cast<int>(GetInput().size()) != 0);
30 }
31 return true;
32 }
33
34 8 bool LukinITestTaskALL::PreProcessingImpl() {
35 8 int rank = 0;
36 8 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
37
38
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 4 times.
8 if (rank == 0) {
39 4 vec_size_ = static_cast<int>(GetInput().size());
40 }
41 8 return true;
42 }
43
44 8 bool LukinITestTaskALL::RunImpl() {
45 8 int proc_count = -1;
46 8 int proc_rank = -1;
47 8 MPI_Comm_size(MPI_COMM_WORLD, &proc_count);
48 8 MPI_Comm_rank(MPI_COMM_WORLD, &proc_rank);
49
50 8 MPI_Bcast(&vec_size_, 1, MPI_INT, 0, MPI_COMM_WORLD);
51
52 8 GetOutput().resize(vec_size_);
53
54 8 std::vector<int> sendcounts(proc_count);
55
1/4
✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
8 std::vector<int> offsets(proc_count);
56
57 8 const int part = vec_size_ / proc_count;
58 8 const int reminder = vec_size_ % proc_count;
59
60 int offset = 0;
61
2/2
✓ Branch 0 taken 16 times.
✓ Branch 1 taken 8 times.
24 for (int i = 0; i < proc_count; i++) {
62
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
32 sendcounts[i] = part + (i < reminder ? 1 : 0);
63 16 offsets[i] = offset;
64 16 offset += sendcounts[i];
65 }
66
67
1/2
✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
8 int local_size = sendcounts[proc_rank];
68
3/6
✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 4 times.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
8 OutType local_vec(local_size);
69
70
3/4
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 4 times.
✓ Branch 3 taken 8 times.
✗ Branch 4 not taken.
12 MPI_Scatterv(proc_rank == 0 ? GetInput().data() : nullptr, sendcounts.data(), offsets.data(), MPI_UNSIGNED_CHAR,
71 local_vec.data(), local_size, MPI_UNSIGNED_CHAR, 0, MPI_COMM_WORLD);
72
73 8 unsigned char local_min = 255;
74 8 unsigned char local_max = 0;
75
76 8 #pragma omp parallel for default(none) shared(local_vec, local_size) reduction(min : local_min) \
77 reduction(max : local_max)
78 for (int i = 0; i < local_size; i++) {
79 local_min = std::min(local_min, local_vec[i]);
80 local_max = std::max(local_max, local_vec[i]);
81 }
82
83 8 unsigned char min = 255;
84 8 unsigned char max = 0;
85
86
1/2
✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
8 MPI_Allreduce(&local_min, &min, 1, MPI_UNSIGNED_CHAR, MPI_MIN, MPI_COMM_WORLD);
87
1/2
✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
8 MPI_Allreduce(&local_max, &max, 1, MPI_UNSIGNED_CHAR, MPI_MAX, MPI_COMM_WORLD);
88
89
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 6 times.
8 if (max == min) {
90
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
2 if (proc_rank == 0) {
91
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 GetOutput() = GetInput();
92 }
93
1/2
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
2 OutType output = GetOutput();
94
1/2
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
2 MPI_Bcast(output.data(), vec_size_, MPI_UNSIGNED_CHAR, 0, MPI_COMM_WORLD);
95
1/2
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
2 GetOutput() = output;
96 return true;
97 }
98
99 6 float scale = 255.0F / static_cast<float>(max - min);
100
101
1/4
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
6 OutType output(local_size);
102
103
1/2
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
6 #pragma omp parallel for default(none) shared(local_vec, output, min, local_size, scale)
104 for (int i = 0; i < local_size; i++) {
105 output[i] = static_cast<unsigned char>(static_cast<float>(local_vec[i] - min) * scale);
106 }
107
108
1/2
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
6 MPI_Allgatherv(output.data(), local_size, MPI_UNSIGNED_CHAR, GetOutput().data(), sendcounts.data(), offsets.data(),
109 MPI_UNSIGNED_CHAR, MPI_COMM_WORLD);
110 return true;
111 }
112
113 8 bool LukinITestTaskALL::PostProcessingImpl() {
114 8 return true;
115 }
116
117 } // namespace lukin_i_ench_contr_lin_hist
118