GCC Code Coverage Report


Directory: ./
File: tasks/nikitina_v_quick_sort_merge/mpi/src/ops_mpi.cpp
Date: 2026-01-10 02:40:41
Exec Total Coverage
Lines: 40 40 100.0%
Functions: 5 5 100.0%
Branches: 32 44 72.7%

Line Branch Exec Source
1 #include "nikitina_v_quick_sort_merge/mpi/include/ops_mpi.hpp"
2
3 #include <mpi.h>
4
5 #include <algorithm>
6 #include <vector>
7
8 #include "nikitina_v_quick_sort_merge/common/include/common.hpp"
9
10 namespace nikitina_v_quick_sort_merge {
11
12
1/2
✓ Branch 1 taken 22 times.
✗ Branch 2 not taken.
22 TestTaskMPI::TestTaskMPI(const InType &in) {
13 SetTypeOfTask(GetStaticTypeOfTask());
14
1/2
✓ Branch 1 taken 22 times.
✗ Branch 2 not taken.
22 GetInput() = in;
15 22 }
16
17 22 bool TestTaskMPI::ValidationImpl() {
18 22 return true;
19 }
20
21 22 bool TestTaskMPI::PreProcessingImpl() {
22 22 return true;
23 }
24
25 22 bool TestTaskMPI::RunImpl() {
26 22 int size = 0;
27 22 int rank = 0;
28 22 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
29 22 MPI_Comm_size(MPI_COMM_WORLD, &size);
30
31 22 int total_elements = 0;
32
2/2
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 11 times.
22 if (rank == 0) {
33 11 total_elements = static_cast<int>(GetInput().size());
34 }
35
36 22 MPI_Bcast(&total_elements, 1, MPI_INT, 0, MPI_COMM_WORLD);
37
38
2/2
✓ Branch 0 taken 20 times.
✓ Branch 1 taken 2 times.
22 if (total_elements == 0) {
39 return true;
40 }
41
42 20 std::vector<int> send_counts(size);
43
1/4
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
20 std::vector<int> displs(size);
44
45 20 int base_count = total_elements / size;
46 20 int remainder = total_elements % size;
47
48 int current_displ = 0;
49
2/2
✓ Branch 0 taken 40 times.
✓ Branch 1 taken 20 times.
60 for (int i = 0; i < size; ++i) {
50
2/2
✓ Branch 0 taken 30 times.
✓ Branch 1 taken 10 times.
70 send_counts[i] = base_count + (i < remainder ? 1 : 0);
51 40 displs[i] = current_displ;
52 40 current_displ += send_counts[i];
53 }
54
55
1/4
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
20 std::vector<int> local_vec(send_counts[rank]);
56
57
3/4
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 10 times.
✓ Branch 3 taken 20 times.
✗ Branch 4 not taken.
30 MPI_Scatterv(rank == 0 ? GetInput().data() : nullptr, send_counts.data(), displs.data(), MPI_INT, local_vec.data(),
58
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 10 times.
20 send_counts[rank], MPI_INT, 0, MPI_COMM_WORLD);
59
60
2/2
✓ Branch 0 taken 19 times.
✓ Branch 1 taken 1 times.
20 if (!local_vec.empty()) {
61
1/2
✓ Branch 1 taken 19 times.
✗ Branch 2 not taken.
19 QuickSortImpl(local_vec, 0, static_cast<int>(local_vec.size()) - 1);
62 }
63
64
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 10 times.
20 if (rank == 0) {
65
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 GetOutput().resize(total_elements);
66 }
67
68
3/4
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 10 times.
✓ Branch 3 taken 20 times.
✗ Branch 4 not taken.
30 MPI_Gatherv(local_vec.data(), send_counts[rank], MPI_INT, rank == 0 ? GetOutput().data() : nullptr,
69 send_counts.data(), displs.data(), MPI_INT, 0, MPI_COMM_WORLD);
70
71
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 10 times.
20 if (rank == 0) {
72 10 auto current_end = GetOutput().begin() + send_counts[0];
73
74
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 10 times.
20 for (int i = 1; i < size; ++i) {
75
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 1 times.
10 if (send_counts[i] > 0) {
76 auto next_end = current_end + send_counts[i];
77 9 std::inplace_merge(GetOutput().begin(), current_end, next_end);
78 current_end = next_end;
79 }
80 }
81 }
82
83 return true;
84 }
85
86 22 bool TestTaskMPI::PostProcessingImpl() {
87 22 return true;
88 }
89
90 } // namespace nikitina_v_quick_sort_merge
91