GCC Code Coverage Report


Directory: ./
File: tasks/sizov_d_string_mismatch_count/mpi/src/ops_mpi.cpp
Date: 2025-12-11 15:42:14
Exec Total Coverage
Lines: 41 41 100.0%
Functions: 5 5 100.0%
Branches: 21 34 61.8%

Line Branch Exec Source
1 #include "sizov_d_string_mismatch_count/mpi/include/ops_mpi.hpp"
2
3 #include <mpi.h>
4
5 #include <vector>
6
7 #include "sizov_d_string_mismatch_count/common/include/common.hpp"
8
9 namespace sizov_d_string_mismatch_count {
10
11
1/2
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
20 SizovDStringMismatchCountMPI::SizovDStringMismatchCountMPI(const InType &in) {
12 SetTypeOfTask(GetStaticTypeOfTask());
13 GetInput() = in;
14 20 GetOutput() = 0;
15 20 }
16
17
1/2
✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
20 bool SizovDStringMismatchCountMPI::ValidationImpl() {
18 const auto &[a, b] = GetInput();
19
2/4
✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 20 times.
20 return !a.empty() && (a.size() == b.size());
20 }
21
22 20 bool SizovDStringMismatchCountMPI::PreProcessingImpl() {
23 const auto &[a, b] = GetInput();
24 20 str_a_ = a;
25 20 str_b_ = b;
26 20 return true;
27 }
28
29 20 bool SizovDStringMismatchCountMPI::RunImpl() {
30 20 int rank = 0;
31 20 int world_size = 1;
32
33 20 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
34 20 MPI_Comm_size(MPI_COMM_WORLD, &world_size);
35
36 20 int total_size = 0;
37
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 10 times.
20 if (rank == 0) {
38 10 total_size = static_cast<int>(str_a_.size());
39 }
40
41 20 MPI_Bcast(&total_size, 1, MPI_INT, 0, MPI_COMM_WORLD);
42
43 20 const int base = total_size / world_size;
44 20 const int remainder = total_size % world_size;
45
46 20 std::vector<int> counts(world_size);
47
1/4
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
20 std::vector<int> displs(world_size);
48
49 int offset = 0;
50
2/2
✓ Branch 0 taken 40 times.
✓ Branch 1 taken 20 times.
60 for (int i = 0; i < world_size; i++) {
51
2/2
✓ Branch 0 taken 28 times.
✓ Branch 1 taken 12 times.
68 counts[i] = base + (i < remainder ? 1 : 0);
52 40 displs[i] = offset;
53 40 offset += counts[i];
54 }
55
56
1/2
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
20 const int local_size = counts[rank];
57
1/2
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
20 std::string local_a(local_size, '\0');
58 std::string local_b(local_size, '\0');
59
60
1/2
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
20 MPI_Scatterv(str_a_.data(), counts.data(), displs.data(), MPI_CHAR, local_a.data(), local_size, MPI_CHAR, 0,
61 MPI_COMM_WORLD);
62
1/2
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
20 MPI_Scatterv(str_b_.data(), counts.data(), displs.data(), MPI_CHAR, local_b.data(), local_size, MPI_CHAR, 0,
63 MPI_COMM_WORLD);
64
65 20 int local_result = 0;
66
2/2
✓ Branch 0 taken 92 times.
✓ Branch 1 taken 20 times.
112 for (int i = 0; i < local_size; ++i) {
67
2/2
✓ Branch 0 taken 33 times.
✓ Branch 1 taken 59 times.
92 if (local_a[i] != local_b[i]) {
68 33 ++local_result;
69 }
70 }
71
72 20 int global_result = 0;
73
1/2
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
20 MPI_Reduce(&local_result, &global_result, 1, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD);
74
75
1/2
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
20 MPI_Bcast(&global_result, 1, MPI_INT, 0, MPI_COMM_WORLD);
76
77 20 GetOutput() = global_result;
78 20 return true;
79 }
80
81 20 bool SizovDStringMismatchCountMPI::PostProcessingImpl() {
82 20 return true;
83 }
84
85 } // namespace sizov_d_string_mismatch_count
86