GCC Code Coverage Report


Directory: ./
File: tasks/zavyalov_a_qsort_simple_merge/mpi/src/ops_mpi.cpp
Date: 2026-01-10 02:40:41
Exec Total Coverage
Lines: 36 36 100.0%
Functions: 5 5 100.0%
Branches: 22 42 52.4%

Line Branch Exec Source
1 #include "zavyalov_a_qsort_simple_merge/mpi/include/ops_mpi.hpp"
2
3 #include <mpi.h>
4
5 #include <algorithm>
6 #include <cstring>
7 #include <vector>
8
9 #include "zavyalov_a_qsort_simple_merge/common/include/common.hpp"
10
11 namespace zavyalov_a_qsort_simple_merge {
12
13
1/2
✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
24 ZavyalovAQsortMPI::ZavyalovAQsortMPI(const InType &in) {
14 SetTypeOfTask(GetStaticTypeOfTask());
15
1/2
✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
24 GetInput() = in;
16 24 }
17
18 24 bool ZavyalovAQsortMPI::ValidationImpl() {
19 24 return !GetInput().empty();
20 }
21
22 24 bool ZavyalovAQsortMPI::PreProcessingImpl() {
23 24 return true;
24 }
25
26 24 bool ZavyalovAQsortMPI::RunImpl() {
27 24 int world_size = 0;
28 24 int rank = 0;
29
30 24 MPI_Comm_size(MPI_COMM_WORLD, &world_size);
31 24 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
32
33 24 int vec_size = static_cast<int>(GetInput().size());
34
35 24 MPI_Bcast(&vec_size, 1, MPI_INT, 0, MPI_COMM_WORLD);
36
37 24 std::vector<int> sendcounts(world_size);
38
1/4
✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
24 std::vector<int> displs(world_size);
39
40 24 int blocksize = vec_size / world_size;
41 int elements_left = vec_size - (world_size * blocksize);
42 int elements_processed = 0;
43
44
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 24 times.
72 for (int i = 0; i < world_size; i++) {
45
2/2
✓ Branch 0 taken 38 times.
✓ Branch 1 taken 10 times.
86 sendcounts[i] = blocksize + (i < elements_left ? 1 : 0);
46 48 displs[i] = elements_processed;
47 48 elements_processed += sendcounts[i];
48 }
49
50
1/2
✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
24 int elements_count = sendcounts[rank];
51
2/6
✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 24 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
24 std::vector<double> local_vector(elements_count);
52
53
1/2
✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
24 MPI_Scatterv(GetInput().data(), sendcounts.data(), displs.data(), MPI_DOUBLE, local_vector.data(), elements_count,
54 MPI_DOUBLE, 0, MPI_COMM_WORLD);
55
56
1/2
✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
24 MyQsort(local_vector.data(), 0, elements_count - 1);
57
58
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 12 times.
24 if (rank == 0) {
59
2/6
✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 12 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
12 std::vector<double> res(vec_size);
60
1/2
✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
12 MPI_Gatherv(local_vector.data(), elements_count, MPI_DOUBLE, res.data(), sendcounts.data(), displs.data(),
61 MPI_DOUBLE, 0, MPI_COMM_WORLD);
62
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 12 times.
24 for (int i = 1; i < world_size; i++) {
63 12 std::inplace_merge(res.data(), res.data() + displs[i], res.data() + displs[i] + sendcounts[i]);
64 }
65
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if (!res.empty()) {
66
1/2
✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
12 GetOutput() = res;
67 }
68 } else {
69
1/2
✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
12 MPI_Gatherv(local_vector.data(), elements_count, MPI_DOUBLE, nullptr, sendcounts.data(), displs.data(), MPI_DOUBLE,
70 0, MPI_COMM_WORLD);
71 }
72
73 24 return true;
74 }
75
76 24 bool ZavyalovAQsortMPI::PostProcessingImpl() {
77 24 return true;
78 }
79
80 } // namespace zavyalov_a_qsort_simple_merge
81