GCC Code Coverage Report


Directory: ./
File: tasks/yushkova_p_min_in_matrix/mpi/src/ops_mpi.cpp
Date: 2026-02-23 23:20:07
Exec Total Coverage
Lines: 0 40 0.0%
Functions: 0 5 0.0%
Branches: 0 22 0.0%

Line Branch Exec Source
1 #include "yushkova_p_min_in_matrix/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 <vector>
10
11 #include "yushkova_p_min_in_matrix/common/include/common.hpp"
12
13 namespace yushkova_p_min_in_matrix {
14
15 namespace {
16
17 inline int GenerateValue(int64_t i, int64_t j) {
18 constexpr int64_t kA = 1103515245LL;
19 constexpr int64_t kC = 12345LL;
20 constexpr int64_t kM = 2147483648LL;
21
22 int64_t seed = ((i % kM) * (100000007LL % kM) + (j % kM) * (1000000009LL % kM)) % kM;
23 seed = (seed ^ 42LL) % kM;
24 int64_t val = ((kA % kM) * (seed % kM) + kC) % kM;
25
26 return static_cast<int>((val % 2000001LL) - 1000000LL);
27 }
28
29 } // namespace
30
31 YushkovaPMinInMatrixMPI::YushkovaPMinInMatrixMPI(const InType &in) {
32 SetTypeOfTask(GetStaticTypeOfTask());
33 GetInput() = in;
34 }
35
36 bool YushkovaPMinInMatrixMPI::ValidationImpl() {
37 return GetInput() > 0;
38 }
39
40 bool YushkovaPMinInMatrixMPI::PreProcessingImpl() {
41 GetOutput().assign(GetInput(), 0);
42 return true;
43 }
44
45 bool YushkovaPMinInMatrixMPI::RunImpl() {
46 int n = static_cast<int>(GetInput());
47 int world_size = 0;
48 int rank = 0;
49 MPI_Comm_size(MPI_COMM_WORLD, &world_size);
50 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
51
52 int base_rows = n / world_size;
53 int extra = n % world_size;
54
55 int my_start = (rank * base_rows) + std::min(rank, extra);
56 int my_count = base_rows + (rank < extra ? 1 : 0);
57
58 std::vector<int> local_results(my_count);
59 for (int i = 0; i < my_count; ++i) {
60 int current_row = my_start + i;
61 int row_min = std::numeric_limits<int>::max();
62
63 for (int j = 0; j < n; ++j) {
64 int val = GenerateValue(current_row, j);
65 row_min = std::min(row_min, val);
66 }
67 local_results[i] = row_min;
68 }
69
70 std::vector<int> recv_counts(world_size);
71 std::vector<int> offsets(world_size);
72
73 int current_offset = 0;
74 for (int i = 0; i < world_size; ++i) {
75 recv_counts[i] = base_rows + (i < extra ? 1 : 0);
76 offsets[i] = current_offset;
77 current_offset += recv_counts[i];
78 }
79
80 MPI_Allgatherv(local_results.data(), my_count, MPI_INT, GetOutput().data(), recv_counts.data(), offsets.data(),
81 MPI_INT, MPI_COMM_WORLD);
82
83 return true;
84 }
85
86 bool YushkovaPMinInMatrixMPI::PostProcessingImpl() {
87 return GetOutput().size() == static_cast<size_t>(GetInput());
88 }
89
90 } // namespace yushkova_p_min_in_matrix
91