GCC Code Coverage Report


Directory: ./
File: tasks/potashnik_m_star_topol/mpi/src/ops_mpi.cpp
Date: 2026-01-10 02:40:41
Exec Total Coverage
Lines: 36 41 87.8%
Functions: 5 5 100.0%
Branches: 22 38 57.9%

Line Branch Exec Source
1 #include "potashnik_m_star_topol/mpi/include/ops_mpi.hpp"
2
3 #include <mpi.h>
4
5 #include <tuple>
6 #include <utility>
7 #include <vector>
8
9 #include "potashnik_m_star_topol/common/include/common.hpp"
10
11 namespace potashnik_m_star_topol {
12
13
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 PotashnikMStarTopolMPI::PotashnikMStarTopolMPI(const InType &in) {
14 SetTypeOfTask(GetStaticTypeOfTask());
15
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 GetInput() = in;
16 GetOutput() = std::make_tuple(0, 0);
17 10 }
18
19 10 bool PotashnikMStarTopolMPI::ValidationImpl() {
20 10 return !GetInput().empty();
21 }
22
23 10 bool PotashnikMStarTopolMPI::PreProcessingImpl() {
24 10 return true;
25 }
26
27 10 bool PotashnikMStarTopolMPI::RunImpl() {
28 auto &input = GetInput();
29
30 10 int size = static_cast<int>(input.size());
31 int star_center = 0;
32
33 10 int world_size = 0;
34 10 MPI_Comm_size(MPI_COMM_WORLD, &world_size);
35 10 int rank = 0;
36 10 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
37
38 10 std::vector<int> received_data;
39 std::pair<int, int> src_dst = {0, 0};
40
41 // If world_size = 1, just make it passs CI
42
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
10 if (world_size == 1) {
43 std::vector<int> tmp;
44 tmp.reserve(10000000);
45
46 for (int i = 0; i < 10000000; i++) {
47 tmp.push_back(i);
48 }
49
50 int sum = 0;
51 for (int i = 0; i < 10000000; i++) {
52 sum += tmp[i];
53 }
54
55 GetOutput() = std::make_tuple(sum, 0);
56 return true;
57 }
58
59 // Going through calls
60
2/2
✓ Branch 0 taken 272 times.
✓ Branch 1 taken 10 times.
282 for (int i = 0; i < size; i++) {
61
2/2
✓ Branch 0 taken 136 times.
✓ Branch 1 taken 136 times.
272 src_dst = potashnik_m_star_topol::GetCyclicSrcDst(world_size, i);
62 int src = src_dst.first;
63 int dst = src_dst.second;
64
2/2
✓ Branch 0 taken 136 times.
✓ Branch 1 taken 136 times.
272 if (rank == star_center) { // Center receives data from source, sends it to destination
65 136 int data = 0;
66
1/2
✓ Branch 1 taken 136 times.
✗ Branch 2 not taken.
136 MPI_Recv(&data, 1, MPI_INT, src, i, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
67
1/2
✓ Branch 1 taken 136 times.
✗ Branch 2 not taken.
136 MPI_Send(&data, 1, MPI_INT, dst, i, MPI_COMM_WORLD);
68 }
69
2/2
✓ Branch 0 taken 136 times.
✓ Branch 1 taken 136 times.
272 if (rank == src) { // Source sends data to center
70
1/2
✓ Branch 1 taken 136 times.
✗ Branch 2 not taken.
136 int data = input[i];
71
1/2
✓ Branch 1 taken 136 times.
✗ Branch 2 not taken.
136 MPI_Send(&data, 1, MPI_INT, star_center, i, MPI_COMM_WORLD);
72 }
73
2/2
✓ Branch 0 taken 136 times.
✓ Branch 1 taken 136 times.
272 if (rank == dst) { // Destination receives data from center
74 136 int data = 0;
75
1/2
✓ Branch 1 taken 136 times.
✗ Branch 2 not taken.
136 MPI_Recv(&data, 1, MPI_INT, star_center, i, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
76 received_data.push_back(data);
77 }
78 }
79
80 // To check correctness, sum all recieved data
81 10 int local_sum = 0;
82
2/2
✓ Branch 0 taken 136 times.
✓ Branch 1 taken 10 times.
146 for (int value : received_data) {
83 136 local_sum += value;
84 }
85
86 10 int global_sum = 0;
87
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 MPI_Reduce(&local_sum, &global_sum, 1, MPI_INT, MPI_SUM, star_center, MPI_COMM_WORLD);
88
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 MPI_Bcast(&global_sum, 1, MPI_INT, star_center, MPI_COMM_WORLD);
89
90 GetOutput() = std::make_tuple(global_sum, 1);
91 10 return true;
92 }
93
94 10 bool PotashnikMStarTopolMPI::PostProcessingImpl() {
95 10 return true;
96 }
97
98 } // namespace potashnik_m_star_topol
99