GCC Code Coverage Report


Directory: ./
File: tasks/zorin_d_avg_vec/mpi/src/ops_mpi.cpp
Date: 2026-01-27 01:59:34
Exec Total Coverage
Lines: 40 40 100.0%
Functions: 5 5 100.0%
Branches: 24 36 66.7%

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