GCC Code Coverage Report


Directory: ./
File: tasks/otcheskov_s_elem_vec_avg/mpi/src/ops_mpi.cpp
Date: 2026-01-27 01:59:34
Exec Total Coverage
Lines: 41 41 100.0%
Functions: 5 5 100.0%
Branches: 28 36 77.8%

Line Branch Exec Source
1 #include "otcheskov_s_elem_vec_avg/mpi/include/ops_mpi.hpp"
2
3 #include <mpi.h>
4
5 #include <cmath>
6 #include <cstdint>
7 #include <numeric>
8 #include <vector>
9
10 #include "otcheskov_s_elem_vec_avg/common/include/common.hpp"
11
12 namespace otcheskov_s_elem_vec_avg {
13
14
1/2
✓ Branch 1 taken 18 times.
✗ Branch 2 not taken.
18 OtcheskovSElemVecAvgMPI::OtcheskovSElemVecAvgMPI(const InType &in) {
15
1/2
✓ Branch 1 taken 18 times.
✗ Branch 2 not taken.
18 MPI_Comm_rank(MPI_COMM_WORLD, &proc_rank_);
16
1/2
✓ Branch 1 taken 18 times.
✗ Branch 2 not taken.
18 MPI_Comm_size(MPI_COMM_WORLD, &proc_num_);
17 SetTypeOfTask(GetStaticTypeOfTask());
18
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if (proc_rank_ == 0) {
19
1/2
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
9 GetInput() = in;
20 }
21 18 GetOutput() = NAN;
22 18 }
23
24 18 bool OtcheskovSElemVecAvgMPI::ValidationImpl() {
25 18 bool is_valid = true;
26
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if (proc_rank_ == 0) {
27
4/4
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 7 times.
11 is_valid = !GetInput().empty() && std::isnan(GetOutput());
28 }
29 18 MPI_Bcast(&is_valid, 1, MPI_C_BOOL, 0, MPI_COMM_WORLD);
30 18 return is_valid;
31 }
32
33 18 bool OtcheskovSElemVecAvgMPI::PreProcessingImpl() {
34 18 return true;
35 }
36
37 18 bool OtcheskovSElemVecAvgMPI::RunImpl() {
38 // передача размера исходного массива
39 18 int total_size = 0;
40
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if (proc_rank_ == 0) {
41 9 total_size = static_cast<int>(GetInput().size());
42 }
43 18 MPI_Bcast(&total_size, 1, MPI_INT, 0, MPI_COMM_WORLD);
44
45 // распределение данных
46 18 int batch_size = total_size / proc_num_;
47 18 int remainder = total_size % proc_num_;
48
2/2
✓ Branch 0 taken 13 times.
✓ Branch 1 taken 5 times.
18 int proc_size = batch_size + (proc_rank_ < remainder ? 1 : 0);
49 18 InType local_data(proc_size);
50 18 std::vector<int> displacements;
51 18 std::vector<int> counts;
52
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if (proc_rank_ == 0) {
53
1/2
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
9 displacements.resize(proc_num_);
54
1/2
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
9 counts.resize(proc_num_);
55 int offset = 0;
56
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for (int i = 0; i < proc_num_; i++) {
57
2/2
✓ Branch 0 taken 13 times.
✓ Branch 1 taken 5 times.
31 counts[i] = batch_size + (i < remainder ? 1 : 0);
58 18 displacements[i] = offset;
59 18 offset += counts[i];
60 }
61 }
62
1/2
✓ Branch 1 taken 18 times.
✗ Branch 2 not taken.
18 MPI_Scatterv(GetInput().data(), counts.data(), displacements.data(), MPI_INT, local_data.data(), proc_size, MPI_INT,
63 0, MPI_COMM_WORLD);
64
65 // вычисления среднего элементов вектора
66 18 int64_t local_sum = std::reduce(local_data.begin(), local_data.end(), int64_t{0});
67 18 int64_t total_sum = 0;
68
1/2
✓ Branch 1 taken 18 times.
✗ Branch 2 not taken.
18 MPI_Allreduce(&local_sum, &total_sum, 1, MPI_INT64_T, MPI_SUM, MPI_COMM_WORLD);
69 18 GetOutput() = static_cast<double>(total_sum) / static_cast<double>(total_size);
70
71
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
36 return !std::isnan(GetOutput());
72 }
73
74 18 bool OtcheskovSElemVecAvgMPI::PostProcessingImpl() {
75 18 return true;
76 }
77
78 } // namespace otcheskov_s_elem_vec_avg
79