GCC Code Coverage Report


Directory: ./
File: tasks/marin_l_cnt_mismat_chrt_in_two_str/mpi/src/ops_mpi.cpp
Date: 2026-01-27 01:59:34
Exec Total Coverage
Lines: 50 52 96.2%
Functions: 5 5 100.0%
Branches: 26 38 68.4%

Line Branch Exec Source
1 #include "marin_l_cnt_mismat_chrt_in_two_str/mpi/include/ops_mpi.hpp"
2
3 #include <mpi.h>
4
5 #include <algorithm>
6 #include <array>
7 #include <cstddef>
8 #include <string>
9 #include <utility>
10
11 #include "marin_l_cnt_mismat_chrt_in_two_str/common/include/common.hpp"
12
13 namespace marin_l_cnt_mismat_chrt_in_two_str {
14
15
1/2
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
20 MarinLCntMismatChrtInTwoStrMPI::MarinLCntMismatChrtInTwoStrMPI(const InType &in) {
16 SetTypeOfTask(GetStaticTypeOfTask());
17 GetInput() = in;
18 20 GetOutput() = 0;
19 20 }
20
21 20 bool MarinLCntMismatChrtInTwoStrMPI::ValidationImpl() {
22 20 return true;
23 }
24
25 20 bool MarinLCntMismatChrtInTwoStrMPI::PreProcessingImpl() {
26 20 int rank = 0;
27 20 int size = 1;
28 20 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
29 20 MPI_Comm_size(MPI_COMM_WORLD, &size);
30
31
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 10 times.
20 std::array<int, 2> lengths{};
32 std::string s1_local;
33 std::string s2_local;
34
35
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 10 times.
20 if (rank == 0) {
36
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 s1_local = GetInput().first;
37
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 s2_local = GetInput().second;
38 10 lengths[0] = static_cast<int>(s1_local.size());
39 10 lengths[1] = static_cast<int>(s2_local.size());
40 }
41
42
1/2
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
20 MPI_Bcast(lengths.data(), 2, MPI_INT, 0, MPI_COMM_WORLD);
43
44
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 10 times.
20 if (rank != 0) {
45
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 s1_local.resize(lengths[0]);
46
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 s2_local.resize(lengths[1]);
47 }
48
49
1/2
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
20 MPI_Bcast(s1_local.data(), lengths[0], MPI_CHAR, 0, MPI_COMM_WORLD);
50
1/2
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
20 MPI_Bcast(s2_local.data(), lengths[1], MPI_CHAR, 0, MPI_COMM_WORLD);
51
52 20 local_s1_ = std::move(s1_local);
53 20 local_s2_ = std::move(s2_local);
54
55 20 GetOutput() = 0;
56 20 return true;
57 }
58
59 20 bool MarinLCntMismatChrtInTwoStrMPI::RunImpl() {
60 20 int rank = 0;
61 20 int size = 1;
62 20 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
63 20 MPI_Comm_size(MPI_COMM_WORLD, &size);
64
65 const std::string &s1 = local_s1_;
66 const std::string &s2 = local_s2_;
67
68 20 std::size_t len1 = s1.size();
69
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 20 times.
20 std::size_t len2 = s2.size();
70 std::size_t total_len = std::max(len1, len2);
71
72
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 20 times.
20 if (total_len == 0) {
73 GetOutput() = 0;
74 return true;
75 }
76
77 20 std::size_t chunk = total_len / static_cast<std::size_t>(size);
78 20 std::size_t remainder = total_len % static_cast<std::size_t>(size);
79
80 std::size_t start =
81
1/2
✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
20 (static_cast<std::size_t>(rank) * chunk) + std::min<std::size_t>(static_cast<std::size_t>(rank), remainder);
82
1/2
✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
20 std::size_t end = start + chunk;
83 if (std::cmp_less(rank, remainder)) {
84 8 end += 1;
85 }
86
87 20 int local_count = 0;
88
2/2
✓ Branch 0 taken 50 times.
✓ Branch 1 taken 20 times.
70 for (std::size_t i = start; i < end && i < total_len; ++i) {
89
6/6
✓ Branch 0 taken 39 times.
✓ Branch 1 taken 11 times.
✓ Branch 2 taken 34 times.
✓ Branch 3 taken 5 times.
✓ Branch 4 taken 19 times.
✓ Branch 5 taken 15 times.
50 if (i >= len1 || i >= len2 || s1[i] != s2[i]) {
90 35 ++local_count;
91 }
92 }
93
94 20 int global_count = 0;
95 20 MPI_Reduce(&local_count, &global_count, 1, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD);
96 20 MPI_Bcast(&global_count, 1, MPI_INT, 0, MPI_COMM_WORLD);
97
98 20 GetOutput() = global_count;
99 20 return true;
100 }
101
102 20 bool MarinLCntMismatChrtInTwoStrMPI::PostProcessingImpl() {
103 20 return true;
104 }
105
106 } // namespace marin_l_cnt_mismat_chrt_in_two_str
107