GCC Code Coverage Report


Directory: ./
File: tasks/klimenko_v_max_matrix_elems_val/mpi/src/ops_mpi.cpp
Date: 2026-01-27 01:59:34
Exec Total Coverage
Lines: 35 35 100.0%
Functions: 5 5 100.0%
Branches: 17 20 85.0%

Line Branch Exec Source
1 #include "klimenko_v_max_matrix_elems_val/mpi/include/ops_mpi.hpp"
2
3 #include <mpi.h>
4
5 #include <algorithm>
6 #include <climits>
7
8 #include "klimenko_v_max_matrix_elems_val/common/include/common.hpp"
9
10 namespace klimenko_v_max_matrix_elems_val {
11
12
1/2
✓ Branch 1 taken 14 times.
✗ Branch 2 not taken.
14 KlimenkoVMaxMatrixElemsValMPI::KlimenkoVMaxMatrixElemsValMPI(const InType &in) {
13 SetTypeOfTask(GetStaticTypeOfTask());
14
1/2
✓ Branch 1 taken 14 times.
✗ Branch 2 not taken.
14 GetInput() = InType(in);
15 14 GetOutput() = 0;
16 14 }
17
18
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 2 times.
14 bool KlimenkoVMaxMatrixElemsValMPI::ValidationImpl() {
19
3/4
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 12 times.
14 if (GetInput().empty() || GetInput()[0].empty()) {
20 2 GetOutput() = 0;
21 }
22 14 return true;
23 }
24
25 14 bool KlimenkoVMaxMatrixElemsValMPI::PreProcessingImpl() {
26 14 return GetOutput() == 0;
27 }
28
29 14 bool KlimenkoVMaxMatrixElemsValMPI::RunImpl() {
30 const auto &matrix = GetInput();
31
32 14 int rank = 0;
33 14 int size = 1;
34
35 14 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
36 14 MPI_Comm_size(MPI_COMM_WORLD, &size);
37
38 14 int n = 0;
39
2/2
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 7 times.
14 if (rank == 0) {
40 7 n = static_cast<int>(matrix.size());
41 }
42
43 14 MPI_Bcast(&n, 1, MPI_INT, 0, MPI_COMM_WORLD);
44
45
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 12 times.
14 if (n == 0) {
46 2 int result = 0;
47 2 MPI_Bcast(&result, 1, MPI_INT, 0, MPI_COMM_WORLD);
48 2 GetOutput() = result;
49 return true;
50 }
51
52 12 int global_max = INT_MIN;
53
54
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if (rank == 0) {
55 6 int local_max = INT_MIN;
56
2/2
✓ Branch 0 taken 126 times.
✓ Branch 1 taken 6 times.
132 for (const auto &row : matrix) {
57
2/2
✓ Branch 0 taken 10184 times.
✓ Branch 1 taken 126 times.
10310 for (int v : row) {
58 10184 local_max = std::max(local_max, v);
59 }
60 }
61 6 global_max = local_max;
62 }
63
64 12 MPI_Bcast(&global_max, 1, MPI_INT, 0, MPI_COMM_WORLD);
65
66 12 GetOutput() = global_max;
67
68 12 return true;
69 }
70
71 14 bool KlimenkoVMaxMatrixElemsValMPI::PostProcessingImpl() {
72 14 return true;
73 }
74
75 } // namespace klimenko_v_max_matrix_elems_val
76