GCC Code Coverage Report


Directory: ./
File: tasks/kopilov_d_ring_2/mpi/src/ops_mpi.cpp
Date: 2026-01-27 01:59:34
Exec Total Coverage
Lines: 44 44 100.0%
Functions: 5 5 100.0%
Branches: 29 48 60.4%

Line Branch Exec Source
1 #include "kopilov_d_ring_2/mpi/include/ops_mpi.hpp"
2
3 #include <mpi.h>
4
5 #include <utility>
6 #include <vector>
7
8 #include "kopilov_d_ring_2/common/include/common.hpp"
9
10 namespace kopilov_d_ring_2 {
11
12
1/2
✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
8 KopilovDRingMPI::KopilovDRingMPI(const InType &in) {
13 SetTypeOfTask(GetStaticTypeOfTask());
14 GetInput() = in;
15 8 }
16
17 8 bool KopilovDRingMPI::ValidationImpl() {
18 8 return true;
19 }
20
21
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
8 bool KopilovDRingMPI::PreProcessingImpl() {
22 GetOutput().data.clear();
23 8 return true;
24 }
25
26 8 bool KopilovDRingMPI::RunImpl() {
27 8 int rank = 0;
28 8 int world_size = 0;
29 8 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
30 8 MPI_Comm_size(MPI_COMM_WORLD, &world_size);
31
32 8 std::vector<int> current_data;
33
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 4 times.
8 if (rank == 0) {
34
1/2
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
4 current_data = GetInput().data;
35 }
36
37 auto apply_offset = [rank](std::vector<int> &data) {
38
4/6
✓ Branch 0 taken 108 times.
✓ Branch 1 taken 4 times.
✓ Branch 2 taken 108 times.
✓ Branch 3 taken 4 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
224 for (int &val : data) {
39 216 val += rank;
40 }
41 8 };
42
43
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if (world_size > 1) {
44 8 const int next_proc = (rank + 1) % world_size;
45 8 const int prev_proc = (rank - 1 + world_size) % world_size;
46
47
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 4 times.
8 if (rank == 0) {
48 apply_offset(current_data);
49 4 auto size = static_cast<int>(current_data.size());
50
1/2
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
4 MPI_Send(&size, 1, MPI_INT, next_proc, 0, MPI_COMM_WORLD);
51
1/2
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
4 MPI_Send(current_data.data(), size, MPI_INT, next_proc, 1, MPI_COMM_WORLD);
52
1/2
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
4 MPI_Recv(&size, 1, MPI_INT, prev_proc, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
53
1/2
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
4 current_data.resize(size);
54
1/2
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
4 MPI_Recv(current_data.data(), size, MPI_INT, prev_proc, 1, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
55 } else {
56 4 int size = 0;
57
1/2
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
4 MPI_Recv(&size, 1, MPI_INT, prev_proc, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
58
1/2
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
4 current_data.resize(size);
59
1/2
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
4 MPI_Recv(current_data.data(), size, MPI_INT, prev_proc, 1, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
60
61 apply_offset(current_data);
62
63
1/2
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
4 MPI_Send(&size, 1, MPI_INT, next_proc, 0, MPI_COMM_WORLD);
64
1/2
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
4 MPI_Send(current_data.data(), size, MPI_INT, next_proc, 1, MPI_COMM_WORLD);
65 }
66 } else {
67 apply_offset(current_data);
68 }
69
70 8 int final_size = 0;
71
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 4 times.
8 if (rank == 0) {
72 4 final_size = static_cast<int>(current_data.size());
73 }
74
1/2
✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
8 MPI_Bcast(&final_size, 1, MPI_INT, 0, MPI_COMM_WORLD);
75
76
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 4 times.
8 if (rank != 0) {
77
1/2
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
4 current_data.resize(final_size);
78 }
79
80
1/2
✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
8 MPI_Bcast(current_data.data(), final_size, MPI_INT, 0, MPI_COMM_WORLD);
81 8 GetOutput().data = std::move(current_data);
82
83 8 return true;
84 }
85
86 8 bool KopilovDRingMPI::PostProcessingImpl() {
87 8 return true;
88 }
89
90 } // namespace kopilov_d_ring_2
91