GCC Code Coverage Report


Directory: ./
File: tasks/krymova_k_quick_sort_simple_merge/mpi/src/ops_mpi.cpp
Date: 2026-02-02 01:14:38
Exec Total Coverage
Lines: 55 55 100.0%
Functions: 5 5 100.0%
Branches: 39 58 67.2%

Line Branch Exec Source
1 #include "krymova_k_quick_sort_simple_merge/mpi/include/ops_mpi.hpp"
2
3 #include <mpi.h>
4
5 #include <algorithm>
6 #include <vector>
7
8 #include "krymova_k_quick_sort_simple_merge/common/include/common.hpp"
9
10 namespace krymova_k_quick_sort_simple_merge {
11
12
1/2
✓ Branch 1 taken 50 times.
✗ Branch 2 not taken.
50 KrymovaKQuickSortSimpleMergeMPI::KrymovaKQuickSortSimpleMergeMPI(const InType &in) {
13 SetTypeOfTask(GetStaticTypeOfTask());
14
1/2
✓ Branch 1 taken 50 times.
✗ Branch 2 not taken.
50 GetInput() = in;
15 50 GetOutput() = std::vector<int>();
16 50 }
17
18 50 bool KrymovaKQuickSortSimpleMergeMPI::ValidationImpl() {
19 50 return true;
20 }
21
22 50 bool KrymovaKQuickSortSimpleMergeMPI::PreProcessingImpl() {
23 50 return true;
24 }
25
26 50 bool KrymovaKQuickSortSimpleMergeMPI::RunImpl() {
27 50 int rank = 0;
28 50 int size = 0;
29 50 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
30 50 MPI_Comm_size(MPI_COMM_WORLD, &size);
31
32 50 int total_size = 0;
33
2/2
✓ Branch 0 taken 25 times.
✓ Branch 1 taken 25 times.
50 if (rank == 0) {
34 25 total_size = static_cast<int>(GetInput().size());
35 }
36
37 50 MPI_Bcast(&total_size, 1, MPI_INT, 0, MPI_COMM_WORLD);
38
39
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 48 times.
50 if (total_size == 0) {
40 2 GetOutput() = std::vector<int>();
41 2 return true;
42 }
43
44 48 int base_chunk = total_size / size;
45 48 int remainder = total_size % size;
46
47 48 std::vector<int> send_counts(size, base_chunk);
48
1/4
✓ Branch 1 taken 48 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
48 std::vector<int> send_displs(size, 0);
49
50
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 48 times.
60 for (int i = 0; i < remainder; ++i) {
51 12 send_counts[i]++;
52 }
53
54
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 48 times.
96 for (int i = 1; i < size; ++i) {
55 48 send_displs[i] = send_displs[i - 1] + send_counts[i - 1];
56 }
57
58 int local_size = 0;
59
1/2
✓ Branch 1 taken 48 times.
✗ Branch 2 not taken.
48 local_size = send_counts[rank];
60
1/4
✓ Branch 1 taken 48 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
48 std::vector<int> local_data(local_size);
61
62
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 24 times.
48 if (rank == 0) {
63
1/2
✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
24 MPI_Scatterv(GetInput().data(), send_counts.data(), send_displs.data(), MPI_INT, local_data.data(), local_size,
64 MPI_INT, 0, MPI_COMM_WORLD);
65 } else {
66
1/2
✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
24 MPI_Scatterv(nullptr, nullptr, nullptr, MPI_INT, local_data.data(), local_size, MPI_INT, 0, MPI_COMM_WORLD);
67 }
68
69
2/2
✓ Branch 0 taken 45 times.
✓ Branch 1 taken 3 times.
48 if (!local_data.empty()) {
70
1/2
✓ Branch 1 taken 45 times.
✗ Branch 2 not taken.
45 QuickSortIterative(local_data);
71 }
72
73 48 std::vector<int> result;
74
75
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 24 times.
48 if (rank == 0) {
76
1/2
✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
24 result.resize(total_size);
77 }
78
79
3/4
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 24 times.
✓ Branch 3 taken 48 times.
✗ Branch 4 not taken.
72 MPI_Gatherv(local_data.data(), local_size, MPI_INT, (rank == 0) ? result.data() : nullptr, send_counts.data(),
80 send_displs.data(), MPI_INT, 0, MPI_COMM_WORLD);
81
82
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 24 times.
48 if (rank == 0) {
83
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 24 times.
48 for (int i = 1; i < size; ++i) {
84 int start = 0;
85 24 start = send_displs[i];
86 int end = 0;
87 24 end = start + send_counts[i];
88 24 std::inplace_merge(result.begin(), result.begin() + start, result.begin() + end);
89 }
90 }
91
92 48 int result_size = 0;
93
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 24 times.
48 if (rank == 0) {
94 24 result_size = static_cast<int>(result.size());
95 }
96
97
1/2
✓ Branch 1 taken 48 times.
✗ Branch 2 not taken.
48 MPI_Bcast(&result_size, 1, MPI_INT, 0, MPI_COMM_WORLD);
98
99
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 24 times.
48 if (rank != 0) {
100
1/2
✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
24 result.resize(result_size);
101 }
102
103
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if (result_size > 0) {
104
1/2
✓ Branch 1 taken 48 times.
✗ Branch 2 not taken.
48 MPI_Bcast(result.data(), result_size, MPI_INT, 0, MPI_COMM_WORLD);
105 }
106
1/2
✓ Branch 1 taken 48 times.
✗ Branch 2 not taken.
48 GetOutput() = result;
107
108 return true;
109 }
110
111 50 bool KrymovaKQuickSortSimpleMergeMPI::PostProcessingImpl() {
112 50 return true;
113 }
114
115 } // namespace krymova_k_quick_sort_simple_merge
116