GCC Code Coverage Report


Directory: ./
File: tasks/kondakov_v_reduce/mpi/src/ops_mpi.cpp
Date: 2026-01-10 02:40:41
Exec Total Coverage
Lines: 38 38 100.0%
Functions: 5 5 100.0%
Branches: 25 30 83.3%

Line Branch Exec Source
1 #include "kondakov_v_reduce/mpi/include/ops_mpi.hpp"
2
3 #include <mpi.h>
4
5 #include <algorithm>
6 #include <cstddef>
7
8 #include "kondakov_v_reduce/common/include/common.hpp"
9
10 namespace kondakov_v_reduce {
11
12
1/2
✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
8 KondakovVReduceTaskMPI::KondakovVReduceTaskMPI(const InType &in) {
13 SetTypeOfTask(GetStaticTypeOfTask());
14 GetInput() = in;
15 8 GetOutput() = 0;
16 8 }
17
18 8 bool KondakovVReduceTaskMPI::ValidationImpl() {
19 8 return true;
20 }
21
22 8 bool KondakovVReduceTaskMPI::PreProcessingImpl() {
23 8 GetOutput() = 0;
24 8 return true;
25 }
26
27 8 bool KondakovVReduceTaskMPI::RunImpl() {
28 8 int rank = 0;
29 8 int size = 0;
30 8 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
31 8 MPI_Comm_size(MPI_COMM_WORLD, &size);
32
33 const auto &values = GetInput().values;
34
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 2 times.
8 const ReduceOp op = GetInput().op;
35 const std::size_t n = values.size();
36
37 8 std::size_t block_size = n / size;
38 8 std::size_t remainder = n % size;
39 8 auto r = static_cast<std::size_t>(rank);
40
41
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 2 times.
8 std::size_t local_start = (r * block_size) + std::min(r, remainder);
42
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 2 times.
8 std::size_t local_end = local_start + block_size + (r < remainder ? 1 : 0);
43
44 OutType local_result = 0;
45 bool has_data = (local_start < local_end);
46
47
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if (has_data) {
48 8 local_result = values[local_start];
49
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 8 times.
14 for (std::size_t i = local_start + 1; i < local_end; ++i) {
50
4/5
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
6 local_result = ApplyReduceOp(local_result, values[i], op);
51 }
52 } else {
53 local_result = GetNeutralElement(op);
54 }
55
56 8 OutType current = local_result;
57 int mask = 1;
58
59
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 4 times.
12 while (mask < size) {
60 8 int partner = rank ^ mask;
61
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if (partner < size) {
62
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 4 times.
8 if ((rank & mask) == 0) {
63 4 OutType received = 0;
64 4 MPI_Recv(&received, 1, MPI_INT64_T, partner, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
65
4/5
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
8 current = ApplyReduceOp(current, received, op);
66 } else {
67 4 MPI_Send(&current, 1, MPI_INT64_T, partner, 0, MPI_COMM_WORLD);
68 break;
69 }
70 }
71 4 mask <<= 1;
72 }
73
74
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 4 times.
8 if (rank == 0) {
75 4 GetOutput() = current;
76 }
77
78 8 return true;
79 }
80
81 8 bool KondakovVReduceTaskMPI::PostProcessingImpl() {
82 8 return true;
83 }
84
85 } // namespace kondakov_v_reduce
86