GCC Code Coverage Report


Directory: ./
File: tasks/yurkin_g_ruler/mpi/src/ops_mpi.cpp
Date: 2026-01-10 02:40:41
Exec Total Coverage
Lines: 34 41 82.9%
Functions: 5 5 100.0%
Branches: 9 16 56.2%

Line Branch Exec Source
1 #include "yurkin_g_ruler/mpi/include/ops_mpi.hpp"
2
3 #include <mpi.h>
4
5 #include <algorithm>
6
7 #include "yurkin_g_ruler/common/include/common.hpp"
8
9 namespace yurkin_g_ruler {
10
11 6 YurkinGRulerMPI::YurkinGRulerMPI(const InType &in) {
12 SetTypeOfTask(YurkinGRulerMPI::GetStaticTypeOfTask());
13 6 GetInput() = in;
14 GetOutput() = 0;
15 6 }
16
17 6 bool YurkinGRulerMPI::ValidationImpl() {
18
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 6 times.
6 return (GetInput() >= 0) && (GetOutput() == 0);
19 }
20
21 6 bool YurkinGRulerMPI::PreProcessingImpl() {
22 6 GetOutput() = 0;
23 6 return true;
24 }
25
26 6 bool YurkinGRulerMPI::RunImpl() {
27 6 int rank = 0;
28 6 int size = 0;
29 6 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
30 6 MPI_Comm_size(MPI_COMM_WORLD, &size);
31
32
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if (size <= 0) {
33 return false;
34 }
35
36 6 int src = 0;
37 6 int dst = size - 1;
38
39 src = std::clamp(src, 0, size - 1);
40 6 dst = std::clamp(dst, 0, size - 1);
41
42 6 GetOutput() = GetInput();
43 6 int payload = GetInput();
44
45
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if (src == dst) {
46 MPI_Barrier(MPI_COMM_WORLD);
47 return true;
48 }
49
50 const int low = std::min(src, dst);
51 const int high = std::max(src, dst);
52 const int direction = (dst > src) ? +1 : -1;
53
54
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 6 times.
6 if (rank < low || rank > high) {
55 MPI_Barrier(MPI_COMM_WORLD);
56 return true;
57 }
58
59
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 3 times.
6 if (rank == src) {
60 const int next = rank + direction;
61 3 MPI_Send(&payload, 1, MPI_INT, next, 0, MPI_COMM_WORLD);
62 3 MPI_Barrier(MPI_COMM_WORLD);
63 3 return true;
64 }
65
66 3 const int prev = rank - direction;
67 3 int recv_val = 0;
68 3 MPI_Recv(&recv_val, 1, MPI_INT, prev, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
69
70
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 if (rank == dst) {
71 3 GetOutput() = recv_val;
72 3 MPI_Barrier(MPI_COMM_WORLD);
73 3 return true;
74 }
75
76 const int next = rank + direction;
77 MPI_Send(&recv_val, 1, MPI_INT, next, 0, MPI_COMM_WORLD);
78
79 MPI_Barrier(MPI_COMM_WORLD);
80 return true;
81 }
82
83 6 bool YurkinGRulerMPI::PostProcessingImpl() {
84 6 return GetOutput() >= 0;
85 }
86
87 } // namespace yurkin_g_ruler
88