GCC Code Coverage Report


Directory: ./
File: tasks/kondrashova_v_ring_topology/mpi/src/ops_mpi.cpp
Date: 2026-01-27 01:59:34
Exec Total Coverage
Lines: 65 71 91.5%
Functions: 7 7 100.0%
Branches: 34 54 63.0%

Line Branch Exec Source
1 #include "kondrashova_v_ring_topology/mpi/include/ops_mpi.hpp"
2
3 #include <mpi.h>
4
5 #include <cassert>
6 #include <vector>
7
8 #include "kondrashova_v_ring_topology/common/include/common.hpp"
9
10 namespace kondrashova_v_ring_topology {
11
12
1/2
✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
12 KondrashovaVRingTopologyMPI::KondrashovaVRingTopologyMPI(const InType &in) {
13 SetTypeOfTask(GetStaticTypeOfTask());
14 GetInput() = in;
15 12 }
16
17 12 bool KondrashovaVRingTopologyMPI::ValidationImpl() {
18 12 int rank = 0;
19 12 int world_size = 0;
20 12 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
21 12 MPI_Comm_size(MPI_COMM_WORLD, &world_size);
22
23 12 int is_valid = 1;
24
25
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if (rank == 0) {
26 const auto &input = GetInput();
27
28
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 6 times.
6 if (input.source < 0 || input.source >= world_size) {
29 is_valid = 0;
30 }
31
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 6 times.
6 if (input.recipient < 0 || input.recipient >= world_size) {
32 is_valid = 0;
33 }
34 }
35
36 12 MPI_Bcast(&is_valid, 1, MPI_INT, 0, MPI_COMM_WORLD);
37
38 12 return is_valid == 1;
39 }
40
41
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 bool KondrashovaVRingTopologyMPI::PreProcessingImpl() {
42 GetOutput().clear();
43 12 return true;
44 }
45
46 8 void KondrashovaVRingTopologyMPI::SendData(int rank, int sender, int receiver, int step, int data_size,
47 const std::vector<int> &data, const std::vector<int> &buffer) {
48
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 4 times.
8 if (rank != sender) {
49 return;
50 }
51
52
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if (step == 0) {
53 4 MPI_Send(&data_size, 1, MPI_INT, receiver, 0, MPI_COMM_WORLD);
54
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if (data_size > 0) {
55 4 MPI_Send(data.data(), data_size, MPI_INT, receiver, 1, MPI_COMM_WORLD);
56 }
57 } else {
58 int buf_size = static_cast<int>(buffer.size());
59 MPI_Send(&buf_size, 1, MPI_INT, receiver, 0, MPI_COMM_WORLD);
60 if (buf_size > 0) {
61 MPI_Send(buffer.data(), buf_size, MPI_INT, receiver, 1, MPI_COMM_WORLD);
62 }
63 }
64 }
65
66 8 void KondrashovaVRingTopologyMPI::ReceiveData(int rank, int sender, int receiver, int recipient,
67 std::vector<int> &buffer) {
68
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 4 times.
8 if (rank != receiver) {
69 4 return;
70 }
71
72 4 int recv_size = 0;
73 4 MPI_Recv(&recv_size, 1, MPI_INT, sender, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
74 4 buffer.resize(recv_size);
75
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if (recv_size > 0) {
76 4 MPI_Recv(buffer.data(), recv_size, MPI_INT, sender, 1, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
77 }
78
79
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if (rank == recipient) {
80 4 GetOutput() = buffer;
81 }
82 }
83
84 12 bool KondrashovaVRingTopologyMPI::RunImpl() {
85 12 int rank = 0;
86 12 int world_size = 0;
87 12 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
88 12 MPI_Comm_size(MPI_COMM_WORLD, &world_size);
89
90 12 int source = 0;
91 12 int recipient = 0;
92 12 int data_size = 0;
93
94
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if (rank == 0) {
95 6 source = GetInput().source;
96 6 recipient = GetInput().recipient;
97 6 data_size = static_cast<int>(GetInput().data.size());
98 }
99
100 12 MPI_Bcast(&source, 1, MPI_INT, 0, MPI_COMM_WORLD);
101 12 MPI_Bcast(&recipient, 1, MPI_INT, 0, MPI_COMM_WORLD);
102 12 MPI_Bcast(&data_size, 1, MPI_INT, 0, MPI_COMM_WORLD);
103
104 12 std::vector<int> data(data_size);
105
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if (rank == 0) {
106
1/2
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
6 data = GetInput().data;
107 }
108
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if (data_size > 0) {
109
1/2
✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
12 MPI_Bcast(data.data(), data_size, MPI_INT, 0, MPI_COMM_WORLD);
110 }
111
112
3/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✓ Branch 3 taken 8 times.
12 if (world_size == 1 || source == recipient) {
113
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2 times.
4 if (rank == recipient) {
114
1/2
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
2 GetOutput() = data;
115 }
116 4 return true;
117 }
118
119 8 int steps = (recipient - source + world_size) % world_size;
120
121 8 std::vector<int> buffer;
122
123
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 8 times.
16 for (int step = 0; step < steps; step++) {
124 8 int sender = (source + step) % world_size;
125 8 int receiver = (sender + 1) % world_size;
126
127
1/2
✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
8 SendData(rank, sender, receiver, step, data_size, data, buffer);
128
1/2
✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
8 ReceiveData(rank, sender, receiver, recipient, buffer);
129
130
1/2
✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
8 MPI_Barrier(MPI_COMM_WORLD);
131 }
132
133 return true;
134 }
135
136 12 bool KondrashovaVRingTopologyMPI::PostProcessingImpl() {
137 12 return true;
138 }
139
140 } // namespace kondrashova_v_ring_topology
141