GCC Code Coverage Report


Directory: ./
File: tasks/shemetov_d_find_error_vec/mpi/src/ops_mpi.cpp
Date: 2026-01-27 01:59:34
Exec Total Coverage
Lines: 40 41 97.6%
Functions: 5 6 83.3%
Branches: 31 48 64.6%

Line Branch Exec Source
1 #include "shemetov_d_find_error_vec/mpi/include/ops_mpi.hpp"
2
3 #include <mpi.h>
4
5 #include <algorithm>
6 #include <cassert>
7 #include <vector>
8
9 #include "shemetov_d_find_error_vec/common/include/common.hpp"
10
11 namespace shemetov_d_find_error_vec {
12
13 namespace {
14
15 constexpr double kEpsilon = 1e-10;
16
17 } // namespace
18
19 int ShemetovDFindErrorVecMPI::DetectDrop(double left, double right) noexcept {
20
2/4
✓ Branch 0 taken 1010 times.
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
1020 return (left > right + kEpsilon) ? 1 : 0;
21 }
22
23
1/2
✓ Branch 1 taken 28 times.
✗ Branch 2 not taken.
28 ShemetovDFindErrorVecMPI::ShemetovDFindErrorVecMPI(const InType &input) {
24 SetTypeOfTask(GetStaticTypeOfTask());
25
1/2
✓ Branch 1 taken 28 times.
✗ Branch 2 not taken.
28 GetInput() = input;
26 28 GetOutput() = 0;
27 28 }
28
29 28 bool ShemetovDFindErrorVecMPI::ValidationImpl() {
30 28 return true;
31 }
32
33 28 bool ShemetovDFindErrorVecMPI::PreProcessingImpl() {
34 28 return true;
35 }
36
37
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 24 times.
28 bool ShemetovDFindErrorVecMPI::RunImpl() {
38 const auto &data = GetInput();
39 28 const int data_size = static_cast<int>(data.size());
40
41
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 24 times.
28 if (data_size < 2) {
42 4 GetOutput() = 0;
43 4 return true;
44 }
45
46 24 int world_rank = 0;
47 24 int world_size = 1;
48 24 MPI_Comm_size(MPI_COMM_WORLD, &world_size);
49 24 MPI_Comm_rank(MPI_COMM_WORLD, &world_rank);
50
51 24 std::vector<int> sendcounts(world_size);
52
1/4
✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
24 std::vector<int> displs(world_size);
53
54 24 int base = data_size / world_size;
55 24 int extra = data_size % world_size;
56
57
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 24 times.
72 for (int rank_idx = 0; rank_idx < world_size; rank_idx++) {
58
2/2
✓ Branch 0 taken 32 times.
✓ Branch 1 taken 16 times.
80 sendcounts[rank_idx] = base + (rank_idx < extra ? 1 : 0);
59 48 displs[rank_idx] = (rank_idx * base) + std::min(rank_idx, extra);
60 }
61
62
1/2
✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
24 int local_size = sendcounts[world_rank];
63
2/6
✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 24 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
24 std::vector<double> local_data(local_size);
64
65
1/2
✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
24 MPI_Scatterv(data.data(), sendcounts.data(), displs.data(), MPI_DOUBLE, local_data.data(), local_size, MPI_DOUBLE, 0,
66 MPI_COMM_WORLD);
67
68 24 int local_viol = 0;
69
70
2/2
✓ Branch 0 taken 1020 times.
✓ Branch 1 taken 24 times.
1044 for (int i = 0; i + 1 < local_size; i++) {
71
2/2
✓ Branch 0 taken 1010 times.
✓ Branch 1 taken 10 times.
2030 local_viol += DetectDrop(local_data[i], local_data[i + 1]);
72 }
73
74
4/6
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 12 times.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 12 times.
✗ Branch 5 not taken.
24 if (world_rank > 0 && local_size > 0 && displs[world_rank] > 0) {
75
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 3 times.
12 double left = data[displs[world_rank] - 1];
76
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 3 times.
12 double right = local_data[0];
77 12 local_viol += DetectDrop(left, right);
78 }
79
80 24 int global_viol = 0;
81
1/2
✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
24 MPI_Allreduce(&local_viol, &global_viol, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD);
82
83
1/2
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
24 GetOutput() = global_viol;
84 return true;
85 }
86
87 28 bool ShemetovDFindErrorVecMPI::PostProcessingImpl() {
88 28 return true;
89 }
90
91 } // namespace shemetov_d_find_error_vec
92