GCC Code Coverage Report


Directory: ./
File: tasks/karpich_i_matrix_elem_sum/mpi/src/ops_mpi.cpp
Date: 2026-01-27 01:59:34
Exec Total Coverage
Lines: 39 39 100.0%
Functions: 5 5 100.0%
Branches: 17 32 53.1%

Line Branch Exec Source
1 #include "karpich_i_matrix_elem_sum/mpi/include/ops_mpi.hpp"
2
3 #include <mpi.h>
4
5 #include <cstddef>
6 #include <cstdint>
7 #include <numeric>
8 #include <vector>
9
10 #include "karpich_i_matrix_elem_sum/common/include/common.hpp"
11
12 namespace karpich_i_matrix_elem_sum {
13
14
1/2
✓ Branch 1 taken 16 times.
✗ Branch 2 not taken.
16 KarpichIMatrixElemSumMPI::KarpichIMatrixElemSumMPI(const InType &in) {
15 SetTypeOfTask(GetStaticTypeOfTask());
16 GetInput() = in;
17 16 GetOutput() = 0;
18 16 }
19
20 16 bool KarpichIMatrixElemSumMPI::ValidationImpl() {
21 16 std::size_t n = std::get<0>(GetInput());
22 16 std::size_t m = std::get<1>(GetInput());
23 16 std::vector<int> val = std::get<2>(GetInput());
24
25
2/4
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 16 times.
16 return (n > 0) && (m > 0) && (val.size() == (n * m));
26 }
27
28 16 bool KarpichIMatrixElemSumMPI::PreProcessingImpl() {
29 16 return true;
30 }
31
32 16 bool KarpichIMatrixElemSumMPI::RunImpl() {
33 std::vector<int> &val = std::get<2>(GetInput());
34
35 16 int rank = 0;
36 16 int mpi_size = 0;
37 16 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
38 16 MPI_Comm_size(MPI_COMM_WORLD, &mpi_size);
39
40 16 int total_elements = 0;
41
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 8 times.
16 if (rank == 0) {
42 8 total_elements = static_cast<int>(val.size());
43 }
44 16 MPI_Bcast(&total_elements, 1, MPI_INT, 0, MPI_COMM_WORLD);
45
46 16 int elements_per_proc = total_elements / mpi_size;
47 16 int remainder = total_elements % mpi_size;
48
49 16 std::vector<int> send_counts(mpi_size, elements_per_proc);
50
1/4
✓ Branch 1 taken 16 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
16 std::vector<int> displacements(mpi_size, 0);
51
52
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 16 times.
22 for (int i = 0; i < remainder; ++i) {
53 6 send_counts[i]++;
54 }
55
56 16 displacements[0] = 0;
57
2/2
✓ Branch 0 taken 16 times.
✓ Branch 1 taken 16 times.
32 for (int i = 1; i < mpi_size; ++i) {
58 16 displacements[i] = displacements[i - 1] + send_counts[i - 1];
59 }
60
61
1/2
✓ Branch 1 taken 16 times.
✗ Branch 2 not taken.
16 int local_size = send_counts[rank];
62
2/6
✓ Branch 1 taken 16 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 16 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
16 std::vector<int> local_data(local_size);
63
64
1/2
✓ Branch 1 taken 16 times.
✗ Branch 2 not taken.
16 MPI_Scatterv(val.data(), send_counts.data(), displacements.data(), MPI_INT, local_data.data(), local_size, MPI_INT, 0,
65 MPI_COMM_WORLD);
66
67 16 std::int64_t local_sum = std::accumulate(local_data.begin(), local_data.end(), static_cast<std::int64_t>(0));
68
69 16 std::int64_t global_sum = 0;
70
1/2
✓ Branch 1 taken 16 times.
✗ Branch 2 not taken.
16 MPI_Reduce(&local_sum, &global_sum, 1, MPI_INT64_T, MPI_SUM, 0, MPI_COMM_WORLD);
71
1/2
✓ Branch 1 taken 16 times.
✗ Branch 2 not taken.
16 MPI_Bcast(&global_sum, 1, MPI_INT64_T, 0, MPI_COMM_WORLD);
72
73
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 GetOutput() = global_sum;
74 16 return true;
75 }
76
77 16 bool KarpichIMatrixElemSumMPI::PostProcessingImpl() {
78 16 return true;
79 }
80
81 } // namespace karpich_i_matrix_elem_sum
82