GCC Code Coverage Report


Directory: ./
File: tasks/morozov_n_sentence_count/mpi/src/ops_mpi.cpp
Date: 2026-01-27 01:59:34
Exec Total Coverage
Lines: 33 33 100.0%
Functions: 5 5 100.0%
Branches: 21 32 65.6%

Line Branch Exec Source
1 #include "morozov_n_sentence_count/mpi/include/ops_mpi.hpp"
2
3 #include <mpi.h>
4
5 #include <cstddef>
6 #include <iostream>
7 #include <string>
8
9 #include "morozov_n_sentence_count/common/include/common.hpp"
10
11 namespace morozov_n_sentence_count {
12
13
1/2
✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
12 MorozovNSentenceCountMPI::MorozovNSentenceCountMPI(const InType &in) {
14 SetTypeOfTask(GetStaticTypeOfTask());
15 GetInput() = in;
16 12 GetOutput() = 0;
17 12 }
18
19
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 bool MorozovNSentenceCountMPI::ValidationImpl() {
20
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 12 times.
12 validated_ = (!GetInput().empty()) && (GetOutput() == 0);
21 12 return validated_;
22 }
23
24 12 bool MorozovNSentenceCountMPI::PreProcessingImpl() {
25
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if (!validated_) {
26 return false;
27 }
28
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 10 times.
12 if (GetInput()[0] == '.' || GetInput()[0] == '!' || GetInput()[0] == '?') {
29 2 GetInput()[0] = ' ';
30 }
31 return true;
32 }
33
34 12 bool MorozovNSentenceCountMPI::RunImpl() {
35
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if (!validated_) {
36 return false;
37 }
38 std::string &input = GetInput();
39
40 12 int mpi_size = 0;
41 12 int rank = 0;
42
43 std::size_t index_start = 0;
44 std::size_t index_end = 0;
45
46 12 MPI_Comm_size(MPI_COMM_WORLD, &mpi_size);
47 12 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
48
49 12 std::size_t step = input.length() / mpi_size;
50
51 12 index_start = step * rank;
52 12 index_end = step + index_start;
53
54
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if (rank == mpi_size - 1) {
55 index_end = input.length();
56 }
57
58 std::size_t counter = 0;
59
2/2
✓ Branch 0 taken 6234 times.
✓ Branch 1 taken 12 times.
6246 for (std::size_t i = index_start; i < index_end; i++) {
60
4/4
✓ Branch 0 taken 341 times.
✓ Branch 1 taken 5893 times.
✓ Branch 2 taken 116 times.
✓ Branch 3 taken 225 times.
6234 if ((input[i] == '.' || input[i] == '!' || input[i] == '?') && (input[i - 1] != '.') && (input[i - 1] != '?') &&
61 (input[i - 1] != '!')) {
62 116 counter++;
63 }
64 }
65
66 12 const std::size_t k_counter = counter;
67 12 std::size_t counter_sum = 0;
68 12 MPI_Reduce(&k_counter, &counter_sum, 1, MPI_UNSIGNED_LONG, MPI_SUM, 0, MPI_COMM_WORLD);
69
70 12 MPI_Bcast(&counter_sum, 1, MPI_UNSIGNED_LONG, 0, MPI_COMM_WORLD);
71
72 12 GetOutput() = counter_sum;
73
74 // debug output
75
4/8
✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 12 times.
✗ Branch 5 not taken.
✓ Branch 8 taken 12 times.
✗ Branch 9 not taken.
✓ Branch 11 taken 12 times.
✗ Branch 12 not taken.
48 std::cout << std::to_string(rank) + " : " + std::to_string(index_start) + " - " + std::to_string(index_end) +
76
1/2
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
24 "\nanswer: " + std::to_string(counter_sum) + "\n";
77
78 12 return true;
79 }
80
81 12 bool MorozovNSentenceCountMPI::PostProcessingImpl() {
82 12 return validated_;
83 }
84
85 } // namespace morozov_n_sentence_count
86