GCC Code Coverage Report


Directory: ./
File: tasks/titaev_m_avg_el_vector/mpi/src/ops_mpi.cpp
Date: 2026-01-10 02:40:41
Exec Total Coverage
Lines: 35 35 100.0%
Functions: 5 5 100.0%
Branches: 17 28 60.7%

Line Branch Exec Source
1 #include "titaev_m_avg_el_vector/mpi/include/ops_mpi.hpp"
2
3 #include <mpi.h>
4
5 #include <cstddef>
6 #include <vector>
7
8 #include "titaev_m_avg_el_vector/common/include/common.hpp"
9
10 namespace titaev_m_avg_el_vector {
11
12
1/2
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
6 TitaevMElemVecsAvgMPI::TitaevMElemVecsAvgMPI(const InType &in) {
13 SetTypeOfTask(GetStaticTypeOfTask());
14
1/2
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
6 GetInput() = in;
15 6 GetOutput() = 0.0;
16 6 }
17
18 6 bool TitaevMElemVecsAvgMPI::ValidationImpl() {
19 6 return !GetInput().empty();
20 }
21
22 6 bool TitaevMElemVecsAvgMPI::PreProcessingImpl() {
23 6 return true;
24 }
25
26 6 bool TitaevMElemVecsAvgMPI::RunImpl() {
27 const auto &vec = GetInput();
28
29 6 int size = 0;
30 6 int rank = 0;
31 6 MPI_Comm_size(MPI_COMM_WORLD, &size);
32 6 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
33
34 6 std::vector<int> counts(size);
35
1/4
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
6 std::vector<int> displs(size);
36
37 size_t n = vec.size();
38 6 int base = static_cast<int>(n / size);
39 6 int rem = static_cast<int>(n % size);
40
41
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 6 times.
18 for (int i = 0; i < size; ++i) {
42
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 counts[i] = base;
43
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if (i < rem) {
44 6 counts[i]++;
45 }
46 }
47
48 6 displs[0] = 0;
49
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 for (int i = 1; i < size; ++i) {
50 6 displs[i] = displs[i - 1] + counts[i - 1];
51 }
52
53
1/4
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
6 std::vector<int> local(counts[rank]);
54
55
1/2
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
6 MPI_Scatterv(vec.data(), counts.data(), displs.data(), MPI_INT, local.data(), counts[rank], MPI_INT, 0,
56 MPI_COMM_WORLD);
57
58 6 double local_sum = 0.0;
59
2/2
✓ Branch 0 taken 15 times.
✓ Branch 1 taken 6 times.
21 for (int x : local) {
60 15 local_sum += x;
61 }
62
63 6 double global_sum = 0.0;
64
65
1/2
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
6 MPI_Allreduce(&local_sum, &global_sum, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD);
66
67
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 GetOutput() = global_sum / static_cast<double>(n);
68 6 return true;
69 }
70
71 6 bool TitaevMElemVecsAvgMPI::PostProcessingImpl() {
72 6 return true;
73 }
74
75 } // namespace titaev_m_avg_el_vector
76