GCC Code Coverage Report


Directory: ./
File: tasks/guseva_a_matrix_sums/mpi/src/ops_mpi.cpp
Date: 2025-12-11 15:42:14
Exec Total Coverage
Lines: 41 41 100.0%
Functions: 5 5 100.0%
Branches: 26 48 54.2%

Line Branch Exec Source
1 #include "guseva_a_matrix_sums/mpi/include/ops_mpi.hpp"
2
3 #include <mpi.h>
4
5 #include <cstdint>
6 #include <vector>
7
8 #include "guseva_a_matrix_sums/common/include/common.hpp"
9
10 namespace guseva_a_matrix_sums {
11
12
1/2
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
20 GusevaAMatrixSumsMPI::GusevaAMatrixSumsMPI(const InType &in) {
13 SetTypeOfTask(GetStaticTypeOfTask());
14 GetInput() = in;
15 GetOutput() = {};
16 20 }
17
18 20 bool GusevaAMatrixSumsMPI::ValidationImpl() {
19
2/4
✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 20 times.
20 return (static_cast<uint64_t>(std::get<0>(GetInput())) * std::get<1>(GetInput()) == std::get<2>(GetInput()).size()) &&
20 20 (GetOutput().empty());
21 }
22
23
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 20 times.
20 bool GusevaAMatrixSumsMPI::PreProcessingImpl() {
24 GetOutput().clear();
25 20 return true;
26 }
27
28 20 bool GusevaAMatrixSumsMPI::RunImpl() {
29 20 int rank = 0;
30 20 int wsize = 0;
31
32 20 MPI_Comm_size(MPI_COMM_WORLD, &wsize);
33 20 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
34
35 20 int rows = static_cast<int>(std::get<0>(GetInput()));
36 20 int columns = static_cast<int>(std::get<1>(GetInput()));
37
38 20 MPI_Bcast(&rows, 1, MPI_INT, 0, MPI_COMM_WORLD);
39 20 MPI_Bcast(&columns, 1, MPI_INT, 0, MPI_COMM_WORLD);
40 20 int size = rows * columns;
41
42 20 int elems_per_proc = size / wsize;
43 20 int remainder = size % wsize;
44
45 20 std::vector<int> counts(wsize, 0);
46
1/4
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
20 std::vector<int> displs(wsize, 0);
47
48 int displ = 0;
49 int shift = 0;
50 int total = 0;
51
52
2/2
✓ Branch 0 taken 40 times.
✓ Branch 1 taken 20 times.
60 for (int proc = 0; proc < wsize; proc++) {
53
4/4
✓ Branch 0 taken 34 times.
✓ Branch 1 taken 6 times.
✓ Branch 2 taken 20 times.
✓ Branch 3 taken 20 times.
74 counts[proc] = elems_per_proc + (proc < remainder ? 1 : 0);
54 40 displs[proc] = displ;
55 40 displ += counts[proc];
56
2/2
✓ Branch 0 taken 20 times.
✓ Branch 1 taken 20 times.
40 if (rank == proc) {
57 20 shift = total % columns;
58 }
59 total += counts[proc];
60 }
61
62
1/4
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
20 std::vector<double> matrix(size, 0);
63
64
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 10 times.
20 if (rank == 0) {
65
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 matrix = std::get<2>(GetInput());
66 }
67
68
1/4
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
20 std::vector<double> local_buff(counts[rank], 0);
69
70
1/2
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
20 MPI_Scatterv(matrix.data(), counts.data(), displs.data(), MPI_DOUBLE, local_buff.data(), counts[rank], MPI_DOUBLE, 0,
71 MPI_COMM_WORLD);
72
73
1/4
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
20 std::vector<double> local_sums(columns, 0.0);
74
75
2/2
✓ Branch 0 taken 206451 times.
✓ Branch 1 taken 20 times.
206471 for (int i = 0; i < counts[rank]; i++) {
76 206451 local_sums[(i + shift) % columns] += local_buff[i];
77 }
78
79
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 10 times.
20 if (rank == 0) {
80
1/4
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
10 GetOutput().resize(columns, 0.0);
81 }
82
83
1/2
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
20 MPI_Reduce(local_sums.data(), GetOutput().data(), columns, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD);
84
85 20 return true;
86 }
87
88 20 bool GusevaAMatrixSumsMPI::PostProcessingImpl() {
89 20 return true;
90 }
91
92 } // namespace guseva_a_matrix_sums
93