GCC Code Coverage Report


Directory: ./
File: tasks/sinev_a_min_in_vector/mpi/src/ops_mpi.cpp
Date: 2026-01-27 01:59:34
Exec Total Coverage
Lines: 46 48 95.8%
Functions: 5 5 100.0%
Branches: 28 44 63.6%

Line Branch Exec Source
1 #include "sinev_a_min_in_vector/mpi/include/ops_mpi.hpp"
2
3 #include <mpi.h>
4
5 #include <algorithm>
6 #include <limits>
7 #include <vector>
8
9 #include "sinev_a_min_in_vector/common/include/common.hpp"
10
11 namespace sinev_a_min_in_vector {
12
13
1/2
✓ Branch 1 taken 14 times.
✗ Branch 2 not taken.
14 SinevAMinInVectorMPI::SinevAMinInVectorMPI(const InType &in) {
14 SetTypeOfTask(GetStaticTypeOfTask());
15
1/2
✓ Branch 1 taken 14 times.
✗ Branch 2 not taken.
14 GetInput() = in;
16 14 GetOutput() = std::numeric_limits<int>::max();
17 14 }
18
19 14 bool SinevAMinInVectorMPI::ValidationImpl() {
20 14 int proc_rank = 0;
21 14 MPI_Comm_rank(MPI_COMM_WORLD, &proc_rank);
22
23 14 bool is_valid = true;
24
25
2/2
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 7 times.
14 if (proc_rank == 0) {
26 7 is_valid = !GetInput().empty();
27 }
28
29 14 MPI_Bcast(&is_valid, 1, MPI_C_BOOL, 0, MPI_COMM_WORLD);
30
31 14 return is_valid;
32 }
33
34 14 bool SinevAMinInVectorMPI::PreProcessingImpl() {
35 14 return true;
36 }
37
38 14 bool SinevAMinInVectorMPI::RunImpl() {
39 14 int proc_num = 0;
40 14 int proc_rank = 0;
41 14 MPI_Comm_size(MPI_COMM_WORLD, &proc_num);
42 14 MPI_Comm_rank(MPI_COMM_WORLD, &proc_rank);
43
44 14 std::vector<int> local_data;
45 14 int global_size = 0;
46
47
2/2
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 7 times.
14 if (proc_rank == 0) {
48 7 global_size = static_cast<int>(GetInput().size());
49 }
50
51 // Рассылаем размер всем процессам
52
1/2
✓ Branch 1 taken 14 times.
✗ Branch 2 not taken.
14 MPI_Bcast(&global_size, 1, MPI_INT, 0, MPI_COMM_WORLD);
53
54
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14 times.
14 if (global_size == 0) {
55 GetOutput() = std::numeric_limits<int>::max();
56 return true;
57 }
58
59 14 int block_size = global_size / proc_num;
60 14 int remainder = global_size % proc_num;
61
62
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 5 times.
14 int local_size = block_size + (proc_rank < remainder ? 1 : 0);
63
1/2
✓ Branch 1 taken 14 times.
✗ Branch 2 not taken.
14 local_data.resize(local_size);
64
65
1/4
✓ Branch 1 taken 14 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
14 std::vector<int> sendcounts(proc_num);
66
1/4
✓ Branch 1 taken 14 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
14 std::vector<int> displacements(proc_num);
67
68
2/2
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 7 times.
14 if (proc_rank == 0) {
69
2/2
✓ Branch 0 taken 14 times.
✓ Branch 1 taken 7 times.
21 for (int i = 0; i < proc_num; i++) {
70
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 5 times.
23 sendcounts[i] = block_size + (i < remainder ? 1 : 0);
71 14 displacements[i] = (i * block_size) + std::min(i, remainder);
72 }
73 }
74
75
1/2
✓ Branch 1 taken 14 times.
✗ Branch 2 not taken.
14 MPI_Bcast(sendcounts.data(), proc_num, MPI_INT, 0, MPI_COMM_WORLD);
76
1/2
✓ Branch 1 taken 14 times.
✗ Branch 2 not taken.
14 MPI_Bcast(displacements.data(), proc_num, MPI_INT, 0, MPI_COMM_WORLD);
77
78
3/4
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 7 times.
✓ Branch 3 taken 14 times.
✗ Branch 4 not taken.
21 MPI_Scatterv(proc_rank == 0 ? GetInput().data() : nullptr, sendcounts.data(), displacements.data(), MPI_INT,
79 local_data.data(), local_size, MPI_INT, 0, MPI_COMM_WORLD);
80
81 14 int local_min = std::numeric_limits<int>::max();
82
2/2
✓ Branch 0 taken 29 times.
✓ Branch 1 taken 14 times.
43 for (int value : local_data) {
83 29 local_min = std::min(local_min, value);
84 }
85
86 14 int global_min = std::numeric_limits<int>::max();
87
1/2
✓ Branch 1 taken 14 times.
✗ Branch 2 not taken.
14 MPI_Allreduce(&local_min, &global_min, 1, MPI_INT, MPI_MIN, MPI_COMM_WORLD);
88
89
1/2
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
14 GetOutput() = global_min;
90 return true;
91 }
92
93 14 bool SinevAMinInVectorMPI::PostProcessingImpl() {
94 14 return true;
95 }
96
97 } // namespace sinev_a_min_in_vector
98