GCC Code Coverage Report


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

Line Branch Exec Source
1 #include "makovskiy_i_allreduce/mpi/include/ops_mpi.hpp"
2
3 #include <mpi.h>
4
5 #include <numeric>
6 #include <vector>
7
8 #include "makovskiy_i_allreduce/common/include/common.hpp"
9
10 namespace makovskiy_i_allreduce {
11
12
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 TestTaskMPI::TestTaskMPI(const InType &in) {
13
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 InType temp(in);
14 this->GetInput().swap(temp);
15 SetTypeOfTask(GetStaticTypeOfTask());
16 10 }
17
18 10 bool TestTaskMPI::ValidationImpl() {
19 10 return true;
20 }
21
22 10 bool TestTaskMPI::PreProcessingImpl() {
23 10 this->GetOutput().resize(1);
24 10 return true;
25 }
26
27 10 bool TestTaskMPI::RunImpl() {
28 10 int rank = 0;
29 10 int world_size = 0;
30 10 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
31 10 MPI_Comm_size(MPI_COMM_WORLD, &world_size);
32
33 10 int total_size = 0;
34
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 5 times.
10 if (rank == 0) {
35 5 total_size = static_cast<int>(this->GetInput().size());
36 }
37 10 MPI_Bcast(&total_size, 1, MPI_INT, 0, MPI_COMM_WORLD);
38
39
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 8 times.
10 if (total_size == 0) {
40 2 this->GetOutput()[0] = 0;
41 2 return true;
42 }
43
44 8 int delta = total_size / world_size;
45 8 int remainder = total_size % world_size;
46
47 8 std::vector<int> sendcounts(world_size);
48
1/4
✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
8 std::vector<int> displs(world_size);
49
50
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 4 times.
8 if (rank == 0) {
51 int current_displ = 0;
52
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 4 times.
12 for (int i = 0; i < world_size; ++i) {
53
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 3 times.
13 sendcounts[i] = delta + (i < remainder ? 1 : 0);
54 8 displs[i] = current_displ;
55 8 current_displ += sendcounts[i];
56 }
57 }
58
59
1/2
✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
8 int my_count = 0;
60
1/2
✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
8 MPI_Scatter(sendcounts.data(), 1, MPI_INT, &my_count, 1, MPI_INT, 0, MPI_COMM_WORLD);
61
62
1/2
✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
8 local_input_.resize(my_count);
63
64
3/4
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 4 times.
✓ Branch 3 taken 8 times.
✗ Branch 4 not taken.
12 MPI_Scatterv(rank == 0 ? this->GetInput().data() : nullptr, sendcounts.data(), displs.data(), MPI_INT,
65 local_input_.data(), my_count, MPI_INT, 0, MPI_COMM_WORLD);
66
67 8 int local_sum = std::accumulate(local_input_.begin(), local_input_.end(), 0);
68 8 int global_sum = 0;
69
70
1/2
✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
8 MPI_Allreduce(&local_sum, &global_sum, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD);
71
72
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 this->GetOutput()[0] = global_sum;
73
74 return true;
75 }
76
77 10 bool TestTaskMPI::PostProcessingImpl() {
78 10 return true;
79 }
80
81 } // namespace makovskiy_i_allreduce
82