GCC Code Coverage Report


Directory: ./
File: tasks/lopatin_a_star_topology/mpi/src/ops_mpi.cpp
Date: 2026-02-02 01:14:38
Exec Total Coverage
Lines: 47 58 81.0%
Functions: 5 5 100.0%
Branches: 20 40 50.0%

Line Branch Exec Source
1 #include "lopatin_a_star_topology/mpi/include/ops_mpi.hpp"
2
3 #include <mpi.h>
4
5 #include <utility>
6 #include <vector>
7
8 #include "lopatin_a_star_topology/common/include/common.hpp"
9
10 namespace lopatin_a_star_topology {
11
12
1/2
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
6 LopatinAStarTopologyMPI::LopatinAStarTopologyMPI(const InType &in) {
13 SetTypeOfTask(GetStaticTypeOfTask());
14 6 int proc_rank = 0;
15
1/2
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
6 MPI_Comm_rank(MPI_COMM_WORLD, &proc_rank);
16 6 int src_rank = std::get<0>(in);
17
18
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 3 times.
6 if (proc_rank == src_rank) {
19 GetInput() = in;
20 } else {
21 3 GetInput() = InType{};
22 3 std::get<0>(GetInput()) = std::get<0>(in);
23 3 std::get<1>(GetInput()) = std::get<1>(in);
24 3 std::get<2>(GetInput()) = std::get<2>(in);
25 }
26
27 6 GetOutput() = OutType{};
28 6 }
29
30 6 bool LopatinAStarTopologyMPI::ValidationImpl() {
31 6 int proc_num = 0;
32 6 MPI_Comm_size(MPI_COMM_WORLD, &proc_num);
33 6 int proc_rank = 0;
34 6 MPI_Comm_rank(MPI_COMM_WORLD, &proc_rank);
35
36 6 int src_rank = std::get<0>(GetInput());
37 6 int dst_rank = std::get<1>(GetInput());
38 6 int msg_size = std::get<2>(GetInput());
39
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 3 times.
6 if (proc_rank == src_rank) {
40 const auto &input = std::get<3>(GetInput());
41
2/4
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
3 return (src_rank >= 0) && (dst_rank >= 0) && (src_rank < proc_num) && (dst_rank < proc_num) &&
42
2/4
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
6 std::cmp_equal(msg_size, input.size()) && !input.empty();
43 }
44
45 return true;
46 }
47
48 6 bool LopatinAStarTopologyMPI::PreProcessingImpl() {
49 6 GetOutput() = OutType{};
50 6 return GetOutput().empty();
51 }
52
53 6 bool LopatinAStarTopologyMPI::RunImpl() {
54 6 int proc_num = 0;
55 6 MPI_Comm_size(MPI_COMM_WORLD, &proc_num);
56 6 int proc_rank = 0;
57 6 MPI_Comm_rank(MPI_COMM_WORLD, &proc_rank);
58
59 const int center_rank = 0;
60 6 const int src_rank = std::get<0>(GetInput());
61 6 const int dst_rank = std::get<1>(GetInput());
62
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 4 times.
6 const int msg_size = std::get<2>(GetInput());
63 OutType &output = GetOutput();
64
65
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 4 times.
6 if (src_rank == dst_rank) {
66
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
2 if (proc_rank == src_rank) {
67 const auto &input = std::get<3>(GetInput());
68 1 output = input;
69 }
70 2 return true;
71 }
72
73
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if ((src_rank * dst_rank) == 0) {
74
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2 times.
4 if (proc_rank == src_rank) {
75 const auto &input = std::get<3>(GetInput());
76 2 MPI_Send(input.data(), msg_size, MPI_DOUBLE, dst_rank, 0, MPI_COMM_WORLD);
77
78
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 } else if (proc_rank == dst_rank) {
79 2 output.resize(msg_size);
80 2 MPI_Status status{};
81 2 MPI_Recv(output.data(), msg_size, MPI_DOUBLE, src_rank, 0, MPI_COMM_WORLD, &status);
82 }
83 } else {
84 if (proc_rank == src_rank) {
85 const auto &input = std::get<3>(GetInput());
86 MPI_Send(input.data(), msg_size, MPI_DOUBLE, center_rank, 0, MPI_COMM_WORLD);
87
88 } else if (proc_rank == center_rank) {
89 std::vector<double> buf(msg_size);
90 MPI_Status status{};
91 MPI_Recv(buf.data(), msg_size, MPI_DOUBLE, src_rank, 0, MPI_COMM_WORLD, &status);
92 MPI_Send(buf.data(), msg_size, MPI_DOUBLE, dst_rank, 0, MPI_COMM_WORLD);
93
94 } else if (proc_rank == dst_rank) {
95 output.resize(msg_size);
96 MPI_Status status{};
97 MPI_Recv(output.data(), msg_size, MPI_DOUBLE, center_rank, 0, MPI_COMM_WORLD, &status);
98 }
99 }
100
101 4 MPI_Barrier(MPI_COMM_WORLD);
102 return true;
103 }
104
105 6 bool LopatinAStarTopologyMPI::PostProcessingImpl() {
106 6 return true;
107 }
108
109 } // namespace lopatin_a_star_topology
110