GCC Code Coverage Report


Directory: ./
File: tasks/chernykh_s_hypercube/mpi/src/ops_mpi.cpp
Date: 2026-01-09 01:27:18
Exec Total Coverage
Lines: 45 46 97.8%
Functions: 6 6 100.0%
Branches: 25 34 73.5%

Line Branch Exec Source
1 #include "chernykh_s_hypercube/mpi/include/ops_mpi.hpp"
2
3 #include <mpi.h>
4
5 #include <algorithm>
6 #include <vector>
7
8 #include "chernykh_s_hypercube/common/include/common.hpp"
9
10 namespace chernykh_s_hypercube {
11
12 namespace {
13 4 bool ProcessHypercubeStep(int &local_data, int step, int rank, int size) {
14 4 int mask = 1 << step;
15 4 int neighbor = rank ^ mask;
16
17
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if ((rank & (mask - 1)) != 0) {
18 return false;
19 }
20
21
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2 times.
4 if ((rank & mask) != 0) {
22 2 MPI_Send(&local_data, 1, MPI_INT, neighbor, 0, MPI_COMM_WORLD);
23 2 return false;
24 }
25
26
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if (neighbor < size) {
27 2 int received_val = 0;
28 2 MPI_Recv(&received_val, 1, MPI_INT, neighbor, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
29 2 local_data += received_val;
30 }
31 return true;
32 }
33 } // namespace
34
35
1/2
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
4 ChernykhSHypercubeMPI::ChernykhSHypercubeMPI(const InType &in) {
36 SetTypeOfTask(GetStaticTypeOfTask());
37
1/2
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
4 GetInput() = InType(in);
38 4 GetOutput() = 0;
39 4 }
40
41 4 bool ChernykhSHypercubeMPI::ValidationImpl() {
42 4 int size = 0;
43 4 MPI_Comm_size(MPI_COMM_WORLD, &size);
44
45
2/4
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
4 bool is_power_of_two = (size > 0) && ((size & (size - 1)) == 0);
46 if (!is_power_of_two) {
47 return false;
48 }
49
50
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if (GetInput().empty()) {
51 return false;
52 }
53
54
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 return std::ranges::all_of(GetInput(), [size](int r) { return r >= 0 && r < size; });
55 }
56
57 4 bool ChernykhSHypercubeMPI::PreProcessingImpl() {
58 4 return true;
59 }
60
61 4 bool ChernykhSHypercubeMPI::RunImpl() {
62 4 int rank = 0;
63 4 int size = 0;
64 4 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
65 4 MPI_Comm_size(MPI_COMM_WORLD, &size);
66
67 const std::vector<int> &active_nodes = GetInput();
68
69 4 int current_val = 0;
70
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 1 times.
4 if (std::ranges::find(active_nodes, rank) != active_nodes.end()) {
71 3 current_val = rank;
72 }
73
74 4 volatile double workload_accumulator = 0.0;
75
2/2
✓ Branch 0 taken 40000 times.
✓ Branch 1 taken 4 times.
40004 for (int idx = 0; idx < 10000; idx++) {
76
2/2
✓ Branch 0 taken 399960000 times.
✓ Branch 1 taken 40000 times.
400000000 for (int jdx = 1; jdx < 10000; jdx++) {
77 399960000 workload_accumulator += static_cast<double>(idx) / static_cast<double>(jdx);
78 }
79 }
80
81
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if (workload_accumulator < 0) {
82 rank += 1;
83 }
84
85 int dims = 0;
86
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 4 times.
8 while ((1 << dims) < size) {
87 4 dims++;
88 }
89
90
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 2 times.
6 for (int i = 0; i < dims; ++i) {
91
2/2
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 2 times.
4 if (!ProcessHypercubeStep(current_val, i, rank, size)) {
92 break;
93 }
94 }
95
96
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2 times.
4 if (rank == 0) {
97 2 GetOutput() = current_val;
98 }
99
100 4 return true;
101 }
102
103 4 bool ChernykhSHypercubeMPI::PostProcessingImpl() {
104 4 return true;
105 }
106 } // namespace chernykh_s_hypercube
107