GCC Code Coverage Report


Directory: ./
File: tasks/kolotukhin_a_elem_vec_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: 19 26 73.1%

Line Branch Exec Source
1 #include "kolotukhin_a_elem_vec_sum/mpi/include/ops_mpi.hpp"
2
3 #include <mpi.h>
4
5 #include <cstdint>
6 #include <numeric>
7 #include <vector>
8
9 #include "kolotukhin_a_elem_vec_sum/common/include/common.hpp"
10
11 namespace kolotukhin_a_elem_vec_sum {
12
13 10 KolotukhinAElemVecSumMPI::KolotukhinAElemVecSumMPI(const InType &in) {
14 SetTypeOfTask(GetStaticTypeOfTask());
15 10 GetInput() = in;
16 GetOutput() = 0;
17 10 }
18
19 10 bool KolotukhinAElemVecSumMPI::ValidationImpl() {
20 10 return std::equal_to<>()(typeid(GetInput()), typeid(std::uint64_t &));
21 }
22
23 10 bool KolotukhinAElemVecSumMPI::PreProcessingImpl() {
24 10 GetOutput() = 0;
25 10 return true;
26 }
27
28 10 bool KolotukhinAElemVecSumMPI::RunImpl() {
29 10 int p_id = -1;
30 10 int pcount = 0;
31 10 MPI_Comm_rank(MPI_COMM_WORLD, &p_id);
32 10 MPI_Comm_size(MPI_COMM_WORLD, &pcount);
33
34 10 std::vector<int> input_data{};
35 10 std::uint64_t input_size = 0;
36
37
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 5 times.
10 if (p_id == 0) {
38 5 input_size = GetInput();
39
1/2
✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
5 input_data.resize(input_size);
40 int seed = 42;
41
2/2
✓ Branch 0 taken 10144 times.
✓ Branch 1 taken 5 times.
10149 for (std::uint64_t i = 0; i < input_size; i++) {
42 10144 seed = (seed * 13 + 7) % 10000;
43 10144 input_data[i] = seed;
44 }
45 }
46
47
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 MPI_Bcast(&input_size, 1, MPI_UINT64_T, 0, MPI_COMM_WORLD);
48
49 10 auto p_count = static_cast<uint64_t>(pcount);
50 10 std::uint64_t base_size = input_size / p_count;
51 std::uint64_t proc_size = base_size;
52
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 5 times.
10 if (p_id == 0) {
53 5 proc_size += input_size % p_count;
54 }
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_data(proc_size);
57
58
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 MPI_Scatter(input_data.data(), static_cast<int>(base_size), MPI_INT, local_data.data(), static_cast<int>(base_size),
59 MPI_INT, 0, MPI_COMM_WORLD);
60
61
4/4
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 5 times.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 3 times.
10 if (p_id == 0 && input_size % p_count != 0) {
62 2 std::uint64_t remainder_start = base_size * p_count;
63 std::uint64_t remainder_size = input_size % p_count;
64
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2 times.
4 for (std::uint64_t i = 0; i < remainder_size; i++) {
65 2 local_data[base_size + i] = input_data[remainder_start + i];
66 }
67 }
68
69 10 std::int64_t local_sum = std::accumulate(local_data.begin(), local_data.end(), 0LL);
70 10 std::int64_t global_sum = 0;
71
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 MPI_Allreduce(&local_sum, &global_sum, 1, MPI_INT64_T, MPI_SUM, MPI_COMM_WORLD);
72
73
2/2
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 3 times.
10 GetOutput() = global_sum;
74 10 return true;
75 }
76
77 10 bool KolotukhinAElemVecSumMPI::PostProcessingImpl() {
78 10 return true;
79 }
80
81 } // namespace kolotukhin_a_elem_vec_sum
82