GCC Code Coverage Report


Directory: ./
File: tasks/ovsyannikov_n_num_mistm_in_two_str/mpi/src/ops_mpi.cpp
Date: 2026-01-10 02:40:41
Exec Total Coverage
Lines: 43 43 100.0%
Functions: 5 5 100.0%
Branches: 26 40 65.0%

Line Branch Exec Source
1 #include "ovsyannikov_n_num_mistm_in_two_str/mpi/include/ops_mpi.hpp"
2
3 #include <mpi.h>
4
5 #include <vector>
6
7 #include "ovsyannikov_n_num_mistm_in_two_str/common/include/common.hpp"
8
9 namespace ovsyannikov_n_num_mistm_in_two_str {
10
11
1/2
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
20 OvsyannikovNNumMistmInTwoStrMPI::OvsyannikovNNumMistmInTwoStrMPI(const InType &in) {
12 SetTypeOfTask(GetStaticTypeOfTask());
13 GetInput() = in;
14 20 GetOutput() = 0;
15 20 }
16
17 20 bool OvsyannikovNNumMistmInTwoStrMPI::ValidationImpl() {
18 20 int proc_rank = 0;
19 20 MPI_Comm_rank(MPI_COMM_WORLD, &proc_rank);
20
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 10 times.
20 if (proc_rank == 0) {
21 10 return GetInput().first.size() == GetInput().second.size();
22 }
23 return true;
24 }
25
26 20 bool OvsyannikovNNumMistmInTwoStrMPI::PreProcessingImpl() {
27 20 GetOutput() = 0;
28 20 return true;
29 }
30
31 20 bool OvsyannikovNNumMistmInTwoStrMPI::RunImpl() {
32 20 int proc_rank = 0;
33 20 int proc_num = 0;
34 20 MPI_Comm_rank(MPI_COMM_WORLD, &proc_rank);
35 20 MPI_Comm_size(MPI_COMM_WORLD, &proc_num);
36
37 20 int total_len = 0;
38
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 10 times.
20 if (proc_rank == 0) {
39 10 total_len = static_cast<int>(GetInput().first.size());
40 }
41
42 20 MPI_Bcast(&total_len, 1, MPI_INT, 0, MPI_COMM_WORLD);
43
44
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 2 times.
20 if (total_len == 0) {
45 return true;
46 }
47
48 18 std::vector<int> counts(proc_num);
49
1/4
✓ Branch 1 taken 18 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
18 std::vector<int> displs(proc_num);
50
51 18 int tail = total_len % proc_num;
52 int accum = 0;
53
2/2
✓ Branch 0 taken 36 times.
✓ Branch 1 taken 18 times.
54 for (int i = 0; i < proc_num; i++) {
54
2/2
✓ Branch 0 taken 22 times.
✓ Branch 1 taken 14 times.
58 counts[i] = (total_len / proc_num) + (i < tail ? 1 : 0);
55 36 displs[i] = accum;
56 36 accum += counts[i];
57 }
58
59
1/2
✓ Branch 1 taken 18 times.
✗ Branch 2 not taken.
18 int my_count = counts[proc_rank];
60
1/4
✓ Branch 1 taken 18 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
18 std::vector<char> local_str_1(my_count);
61
1/4
✓ Branch 1 taken 18 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
18 std::vector<char> local_str_2(my_count);
62
63 const char *send_buf_1 = nullptr;
64 const char *send_buf_2 = nullptr;
65
66
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if (proc_rank == 0) {
67 send_buf_1 = GetInput().first.data();
68 send_buf_2 = GetInput().second.data();
69 }
70
71
1/2
✓ Branch 1 taken 18 times.
✗ Branch 2 not taken.
18 MPI_Scatterv(send_buf_1, counts.data(), displs.data(), MPI_CHAR, local_str_1.data(), my_count, MPI_CHAR, 0,
72 MPI_COMM_WORLD);
73
74
1/2
✓ Branch 1 taken 18 times.
✗ Branch 2 not taken.
18 MPI_Scatterv(send_buf_2, counts.data(), displs.data(), MPI_CHAR, local_str_2.data(), my_count, MPI_CHAR, 0,
75 MPI_COMM_WORLD);
76
77 18 int priv_err_cnt = 0;
78
2/2
✓ Branch 0 taken 47 times.
✓ Branch 1 taken 18 times.
65 for (int i = 0; i < my_count; ++i) {
79
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 38 times.
47 if (local_str_1[i] != local_str_2[i]) {
80 9 priv_err_cnt++;
81 }
82 }
83
84 18 int total_err_cnt = 0;
85
1/2
✓ Branch 1 taken 18 times.
✗ Branch 2 not taken.
18 MPI_Allreduce(&priv_err_cnt, &total_err_cnt, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD);
86
2/2
✓ Branch 0 taken 16 times.
✓ Branch 1 taken 2 times.
18 GetOutput() = total_err_cnt;
87
88 return true;
89 }
90
91 20 bool OvsyannikovNNumMistmInTwoStrMPI::PostProcessingImpl() {
92 20 return true;
93 }
94
95 } // namespace ovsyannikov_n_num_mistm_in_two_str
96