GCC Code Coverage Report


Directory: ./
File: tasks/zhurin_i_ring_topology/mpi/src/ops_mpi.cpp
Date: 2026-01-27 01:59:34
Exec Total Coverage
Lines: 52 54 96.3%
Functions: 8 8 100.0%
Branches: 27 44 61.4%

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