GCC Code Coverage Report


Directory: ./
File: tasks/nalitov_d_matrix_min_by_columns/mpi/src/ops_mpi.cpp
Date: 2026-01-27 01:59:34
Exec Total Coverage
Lines: 37 37 100.0%
Functions: 5 5 100.0%
Branches: 21 36 58.3%

Line Branch Exec Source
1 #include "nalitov_d_matrix_min_by_columns/mpi/include/ops_mpi.hpp"
2
3 #include <mpi.h>
4
5 #include <algorithm>
6 #include <cstddef>
7 #include <cstdint>
8 #include <limits>
9 #include <utility>
10 #include <vector>
11
12 #include "nalitov_d_matrix_min_by_columns/common/include/common.hpp"
13
14 namespace nalitov_d_matrix_min_by_columns {
15
16 22 NalitovDMinMatrixMPI::NalitovDMinMatrixMPI(const InType &in) {
17 SetTypeOfTask(GetStaticTypeOfTask());
18 22 GetInput() = in;
19 GetOutput().clear();
20 22 }
21
22 22 bool NalitovDMinMatrixMPI::ValidationImpl() {
23
2/4
✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 22 times.
22 return (GetInput() > 0) && (GetOutput().empty());
24 }
25
26
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 22 times.
22 bool NalitovDMinMatrixMPI::PreProcessingImpl() {
27 GetOutput().clear();
28 22 GetOutput().reserve(GetInput());
29 22 return true;
30 }
31
32 22 bool NalitovDMinMatrixMPI::RunImpl() {
33 auto generate = [](int64_t i, int64_t j) -> InType {
34 368289 uint64_t seed = (i * 100000007ULL + j * 1000000009ULL) ^ 42ULL;
35
36 368289 seed ^= seed >> 12;
37 368289 seed ^= seed << 25;
38 368289 seed ^= seed >> 27;
39 368289 uint64_t value = seed * 0x2545F4914F6CDD1DULL;
40
41 368289 return static_cast<InType>((value % 2000001) - 1000000);
42 };
43
44 22 InType n = GetInput();
45
1/2
✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
22 if (n == 0) {
46 return false;
47 }
48
49 22 int rank = 0;
50 22 int size = 0;
51
52 22 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
53 22 MPI_Comm_size(MPI_COMM_WORLD, &size);
54
55 22 int rows_per_process = n / size;
56 22 int leftover = n % size;
57
2/2
✓ Branch 0 taken 17 times.
✓ Branch 1 taken 5 times.
22 int process_rows_number = rows_per_process + (rank < leftover ? 1 : 0);
58
59 22 int first_row = (rank * rows_per_process) + std::min(rank, leftover);
60 22 int last_row = first_row + process_rows_number;
61
62 22 std::vector<InType> local_min_columns(static_cast<size_t>(n), std::numeric_limits<InType>::max());
63
64
2/2
✓ Branch 0 taken 1187 times.
✓ Branch 1 taken 22 times.
1209 for (InType i = first_row; i < last_row; i++) {
65
2/2
✓ Branch 0 taken 368289 times.
✓ Branch 1 taken 1187 times.
369476 for (InType j = 0; j < n; j++) {
66
2/2
✓ Branch 0 taken 12406 times.
✓ Branch 1 taken 355883 times.
368289 InType val = generate(static_cast<int64_t>(i), static_cast<int64_t>(j));
67 368289 local_min_columns[static_cast<size_t>(j)] = std::min(local_min_columns[static_cast<size_t>(j)], val);
68 }
69 }
70
71
2/6
✓ Branch 1 taken 22 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 22 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
22 std::vector<InType> global_min_columns(static_cast<size_t>(n), std::numeric_limits<InType>::max());
72
73
1/2
✓ Branch 1 taken 22 times.
✗ Branch 2 not taken.
22 MPI_Reduce(local_min_columns.data(), global_min_columns.data(), static_cast<int>(n), MPI_INT, MPI_MIN, 0,
74 MPI_COMM_WORLD);
75
76
1/2
✓ Branch 1 taken 22 times.
✗ Branch 2 not taken.
22 MPI_Bcast(global_min_columns.data(), static_cast<int>(n), MPI_INT, 0, MPI_COMM_WORLD);
77
78 GetOutput() = std::move(global_min_columns);
79
80
2/4
✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 22 times.
22 return !GetOutput().empty() && (GetOutput().size() == static_cast<size_t>(n));
81 }
82
83
1/2
✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
22 bool NalitovDMinMatrixMPI::PostProcessingImpl() {
84
2/4
✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 22 times.
22 return !GetOutput().empty() && (GetOutput().size() == static_cast<size_t>(GetInput()));
85 }
86
87 } // namespace nalitov_d_matrix_min_by_columns
88