GCC Code Coverage Report


Directory: ./
File: tasks/gonozov_l_elem_vec_sum/mpi/src/ops_mpi.cpp
Date: 2026-01-10 02:40:41
Exec Total Coverage
Lines: 39 39 100.0%
Functions: 5 5 100.0%
Branches: 23 34 67.6%

Line Branch Exec Source
1 #include "gonozov_l_elem_vec_sum/mpi/include/ops_mpi.hpp"
2
3 #include <mpi.h>
4
5 #include <numeric>
6 #include <vector>
7
8 #include "gonozov_l_elem_vec_sum/common/include/common.hpp"
9
10 namespace gonozov_l_elem_vec_sum {
11
12
1/2
✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
12 GonozovLElemVecSumMPI::GonozovLElemVecSumMPI(const InType &in) {
13 SetTypeOfTask(GetStaticTypeOfTask());
14
1/2
✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
12 GetInput() = in;
15 12 GetOutput() = 0;
16 12 }
17
18 12 bool GonozovLElemVecSumMPI::ValidationImpl() {
19 12 return !GetInput().empty();
20 }
21
22 12 bool GonozovLElemVecSumMPI::PreProcessingImpl() {
23 12 vector_size_ = static_cast<int>(GetInput().size());
24 12 return true;
25 }
26
27 12 bool GonozovLElemVecSumMPI::RunImpl() {
28 12 int proc_num = 0;
29 12 int proc_rank = 0;
30 12 MPI_Comm_size(MPI_COMM_WORLD, &proc_num);
31 12 MPI_Comm_rank(MPI_COMM_WORLD, &proc_rank);
32
33
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 10 times.
12 if (vector_size_ < proc_num) {
34 2 OutType result = 0;
35
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
2 if (proc_rank == 0) {
36
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
2 for (int i = 0; i < vector_size_; i++) {
37 1 result += GetInput()[i];
38 }
39 }
40 2 MPI_Bcast(&result, 1, MPI_LONG_LONG, 0, MPI_COMM_WORLD);
41 2 GetOutput() = result;
42 return true;
43 }
44
45 10 int n = vector_size_ / proc_num;
46 10 int remainder = vector_size_ % proc_num;
47
2/2
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 3 times.
10 int local_size = n + (proc_rank < remainder ? 1 : 0);
48
49 10 std::vector<int> sendcounts(proc_num);
50
1/4
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
10 std::vector<int> displs(proc_num);
51
1/4
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
10 std::vector<int> subvector(local_size);
52
53
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 5 times.
10 if (proc_rank == 0) {
54 int offset = 0;
55
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 5 times.
15 for (int i = 0; i < proc_num; i++) {
56
2/2
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 3 times.
17 sendcounts[i] = n + (i < remainder ? 1 : 0);
57 10 displs[i] = offset;
58 10 offset += sendcounts[i];
59 }
60 }
61
62
3/4
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 5 times.
✓ Branch 3 taken 10 times.
✗ Branch 4 not taken.
15 MPI_Scatterv((proc_rank == 0) ? GetInput().data() : nullptr, sendcounts.data(), displs.data(), MPI_INT,
63 subvector.data(), local_size, MPI_INT, 0, MPI_COMM_WORLD);
64
65 10 OutType local_sum = std::accumulate(subvector.begin(), subvector.end(), 0LL);
66
67 10 OutType global_sum = 0;
68
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 MPI_Allreduce(&local_sum, &global_sum, 1, MPI_LONG_LONG, MPI_SUM, MPI_COMM_WORLD);
69
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 GetOutput() = global_sum;
70
71 return true;
72 }
73
74 12 bool GonozovLElemVecSumMPI::PostProcessingImpl() {
75 12 return true;
76 }
77
78 } // namespace gonozov_l_elem_vec_sum
79