GCC Code Coverage Report


Directory: ./
File: tasks/khruev_a_min_elem_vec/mpi/src/ops_mpi.cpp
Date: 2025-12-13 04:24:21
Exec Total Coverage
Lines: 36 36 100.0%
Functions: 5 5 100.0%
Branches: 23 38 60.5%

Line Branch Exec Source
1 #include "khruev_a_min_elem_vec/mpi/include/ops_mpi.hpp"
2
3 #include <mpi.h>
4
5 #include <algorithm>
6 #include <climits>
7 #include <vector>
8
9 #include "khruev_a_min_elem_vec/common/include/common.hpp"
10
11 namespace khruev_a_min_elem_vec {
12
13
1/2
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
20 KhruevAMinElemVecMPI::KhruevAMinElemVecMPI(const InType &in) {
14 SetTypeOfTask(GetStaticTypeOfTask()); // mpi scoreboard
15
1/2
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
20 GetInput() = in; // dannie doljna bit vidna vsem func rodytelya and stabilizaciya
16 20 GetOutput() = 0;
17 20 }
18
19 20 bool KhruevAMinElemVecMPI::ValidationImpl() { // input check
20 20 return GetOutput() == 0;
21 }
22
23 20 bool KhruevAMinElemVecMPI::PreProcessingImpl() {
24 20 return true;
25 }
26
27
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 18 times.
20 bool KhruevAMinElemVecMPI::RunImpl() {
28 const auto &input = GetInput();
29
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 18 times.
20 if (input.empty()) {
30 2 GetOutput() = INT_MAX;
31 2 return true;
32 }
33
34 18 int rank = 0;
35 18 int size = 0;
36 18 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
37 18 MPI_Comm_size(MPI_COMM_WORLD, &size);
38
39 18 int n = static_cast<int>(input.size());
40 18 int int_part = n / size;
41 18 int remainder = n % size;
42
43 18 std::vector<int> sendcounts(size);
44
1/4
✓ Branch 1 taken 18 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
18 std::vector<int> displs(size);
45
46
2/2
✓ Branch 0 taken 36 times.
✓ Branch 1 taken 18 times.
54 for (int i = 0; i < size; ++i) {
47
4/4
✓ Branch 0 taken 26 times.
✓ Branch 1 taken 10 times.
✓ Branch 2 taken 18 times.
✓ Branch 3 taken 18 times.
62 sendcounts[i] = int_part + (i < remainder ? 1 : 0);
48
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 18 times.
36 displs[i] = (i == 0 ? 0 : displs[i - 1] + sendcounts[i - 1]);
49 }
50
51
1/4
✓ Branch 1 taken 18 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
18 std::vector<int> local_chunk(sendcounts[rank] > 0 ? sendcounts[rank] : 1);
52
2/4
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 18 times.
✗ Branch 4 not taken.
36 MPI_Scatterv(input.data(), sendcounts.data(), displs.data(), MPI_INT,
53
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 sendcounts[rank] > 0 ? local_chunk.data() : nullptr, sendcounts[rank], MPI_INT, 0, MPI_COMM_WORLD);
54
55 18 int local_min = INT_MAX;
56
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (sendcounts[rank] > 0) {
57 18 local_min = *std::min_element(local_chunk.begin(), local_chunk.begin() + sendcounts[rank]);
58 }
59
60 18 int global_min = 0;
61
62
1/2
✓ Branch 1 taken 18 times.
✗ Branch 2 not taken.
18 MPI_Reduce(&local_min, &global_min, 1, MPI_INT, MPI_MIN, 0, MPI_COMM_WORLD);
63
1/2
✓ Branch 1 taken 18 times.
✗ Branch 2 not taken.
18 MPI_Bcast(&global_min, 1, MPI_INT, 0, MPI_COMM_WORLD);
64
65
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 GetOutput() = global_min;
66
67 return true;
68 }
69
70 20 bool KhruevAMinElemVecMPI::PostProcessingImpl() {
71 20 return true;
72 }
73
74 } // namespace khruev_a_min_elem_vec
75