GCC Code Coverage Report


Directory: ./
File: tasks/levonychev_i_min_val_rows_matrix/mpi/src/ops_mpi.cpp
Date: 2025-12-13 04:24:21
Exec Total Coverage
Lines: 61 61 100.0%
Functions: 5 5 100.0%
Branches: 36 62 58.1%

Line Branch Exec Source
1 #include "levonychev_i_min_val_rows_matrix/mpi/include/ops_mpi.hpp"
2
3 #include <mpi.h>
4
5 #include <algorithm>
6 #include <cstddef>
7 #include <vector>
8
9 #include "levonychev_i_min_val_rows_matrix/common/include/common.hpp"
10
11 namespace levonychev_i_min_val_rows_matrix {
12
13
1/2
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
20 LevonychevIMinValRowsMatrixMPI::LevonychevIMinValRowsMatrixMPI(const InType &in) {
14 SetTypeOfTask(GetStaticTypeOfTask());
15
16 20 int rank = 0;
17
1/2
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
20 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
18
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 10 times.
20 if (rank == 0) {
19 GetInput() = in;
20 }
21 GetOutput() = {};
22 20 }
23 20 bool LevonychevIMinValRowsMatrixMPI::ValidationImpl() {
24 20 int rank = 0;
25 20 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
26
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 10 times.
20 if (rank == 0) {
27 const size_t vector_size = std::get<0>(GetInput()).size();
28 10 const int rows = std::get<1>(GetInput());
29 10 const int cols = std::get<2>(GetInput());
30
2/4
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 10 times.
✗ Branch 3 not taken.
10 return vector_size != 0 && rows != 0 && cols != 0 &&
31
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
10 (vector_size == static_cast<size_t>(rows) * static_cast<size_t>(cols));
32 }
33 return true;
34 }
35
36 20 bool LevonychevIMinValRowsMatrixMPI::PreProcessingImpl() {
37 20 int rank = 0;
38 20 int rows = 0;
39 20 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
40
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 10 times.
20 if (rank == 0) {
41 10 rows = std::get<1>(GetInput());
42 }
43 20 MPI_Bcast(&rows, 1, MPI_INT, 0, MPI_COMM_WORLD);
44 20 GetOutput().resize(rows);
45 20 return true;
46 }
47
48 20 bool LevonychevIMinValRowsMatrixMPI::RunImpl() {
49 20 int proc_num = 0;
50 20 int proc_rank = 0;
51 20 MPI_Comm_size(MPI_COMM_WORLD, &proc_num);
52 20 MPI_Comm_rank(MPI_COMM_WORLD, &proc_rank);
53
54 OutType &global_min_values = GetOutput();
55
56 20 int rows = 0;
57 20 int cols = 0;
58 20 std::vector<int> recvcounts_scatterv(proc_num);
59
1/4
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
20 std::vector<int> displs_scatterv(proc_num);
60
1/4
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
20 std::vector<int> recvcounts_gatherv(proc_num);
61
1/4
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
20 std::vector<int> displs_gatherv(proc_num);
62
63
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 10 times.
20 if (proc_rank == 0) {
64 10 rows = std::get<1>(GetInput());
65 10 cols = std::get<2>(GetInput());
66
67
2/2
✓ Branch 0 taken 20 times.
✓ Branch 1 taken 10 times.
30 for (int i = 0; i < proc_num; ++i) {
68
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 10 times.
20 int local_count_of_rows = i == (proc_num - 1) ? ((rows / proc_num) + (rows % proc_num)) : (rows / proc_num);
69 20 recvcounts_scatterv[i] = local_count_of_rows * cols;
70 20 recvcounts_gatherv[i] = local_count_of_rows;
71 20 int start = i * (rows / proc_num);
72 20 displs_scatterv[i] = start * cols;
73 20 displs_gatherv[i] = start;
74 }
75 }
76
1/2
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
20 MPI_Bcast(&rows, 1, MPI_INT, 0, MPI_COMM_WORLD);
77
1/2
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
20 MPI_Bcast(&cols, 1, MPI_INT, 0, MPI_COMM_WORLD);
78
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 10 times.
20 int local_count_of_rows = (proc_rank == (proc_num - 1)) ? ((rows / proc_num) + (rows % proc_num)) : (rows / proc_num);
79 20 int recvcount = local_count_of_rows * cols;
80
2/6
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 20 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
20 OutType local_matrix(recvcount);
81
1/2
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
20 MPI_Scatterv(std::get<0>(GetInput()).data(), recvcounts_scatterv.data(), displs_scatterv.data(), MPI_INT,
82 local_matrix.data(), recvcount, MPI_INT, 0, MPI_COMM_WORLD);
83
84
1/4
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
20 OutType local_min_values(local_count_of_rows);
85
86
2/2
✓ Branch 0 taken 51 times.
✓ Branch 1 taken 20 times.
71 for (int i = 0; i < local_count_of_rows; ++i) {
87 51 const int start = cols * i;
88 51 int min_value = local_matrix[start];
89
2/2
✓ Branch 0 taken 224 times.
✓ Branch 1 taken 51 times.
275 for (int j = 1; j < cols; ++j) {
90
2/2
✓ Branch 0 taken 117 times.
✓ Branch 1 taken 107 times.
341 min_value = std::min(local_matrix[start + j], min_value);
91 }
92 51 local_min_values[i] = min_value;
93 }
94
95
1/2
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
20 MPI_Gatherv(local_min_values.data(), local_count_of_rows, MPI_INT, global_min_values.data(),
96 recvcounts_gatherv.data(), displs_gatherv.data(), MPI_INT, 0, MPI_COMM_WORLD);
97
1/2
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
20 MPI_Bcast(global_min_values.data(), rows, MPI_INT, 0, MPI_COMM_WORLD);
98 20 return true;
99 }
100
101 20 bool LevonychevIMinValRowsMatrixMPI::PostProcessingImpl() {
102 20 return true;
103 }
104
105 } // namespace levonychev_i_min_val_rows_matrix
106