GCC Code Coverage Report


Directory: ./
File: tasks/zhurin_i_matrix_sums/mpi/src/ops_mpi.cpp
Date: 2026-01-27 01:59:34
Exec Total Coverage
Lines: 42 42 100.0%
Functions: 5 5 100.0%
Branches: 22 34 64.7%

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