GCC Code Coverage Report


Directory: ./
File: tasks/galkin_d_trapezoid_method/mpi/src/ops_mpi.cpp
Date: 2026-01-27 01:59:34
Exec Total Coverage
Lines: 40 43 93.0%
Functions: 5 5 100.0%
Branches: 9 16 56.2%

Line Branch Exec Source
1 #include "galkin_d_trapezoid_method/mpi/include/ops_mpi.hpp"
2
3 #include <mpi.h>
4
5 #include <algorithm>
6
7 #include "galkin_d_trapezoid_method/common/include/common.hpp"
8
9 namespace galkin_d_trapezoid_method {
10
11 8 GalkinDTrapezoidMethodMPI::GalkinDTrapezoidMethodMPI(const InType &in) {
12 SetTypeOfTask(GetStaticTypeOfTask());
13 8 GetInput() = in;
14 GetOutput() = 0.0;
15 8 }
16
17 8 bool GalkinDTrapezoidMethodMPI::ValidationImpl() {
18 const auto &in = GetInput();
19
2/4
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 8 times.
8 return (in.n > 0) && (in.b > in.a);
20 }
21
22 8 bool GalkinDTrapezoidMethodMPI::PreProcessingImpl() {
23 8 GetOutput() = 0.0;
24 8 return true;
25 }
26
27 8 bool GalkinDTrapezoidMethodMPI::RunImpl() {
28 8 int rank = 0;
29 8 int size = 0;
30 8 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
31 8 MPI_Comm_size(MPI_COMM_WORLD, &size);
32
33
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 4 times.
8 InType in = (rank == 0) ? GetInput() : InType{};
34
35 8 MPI_Bcast(&in, sizeof(InType), MPI_BYTE, 0, MPI_COMM_WORLD);
36
37 8 GetInput() = in;
38
39 8 double a = in.a;
40 8 double b = in.b;
41 8 int n = in.n;
42
43
2/4
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 8 times.
8 if (n <= 0 || !(a < b)) {
44 if (rank == 0) {
45 GetOutput() = 0.0;
46 }
47 return true;
48 }
49
50 8 int base = n / size;
51 8 int rem = n % size;
52
53
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 int local_n = base + (rank < rem ? 1 : 0);
54
55 8 int start_i = (rank * base) + std::min(rank, rem);
56 8 int end_i = start_i + local_n;
57 8 double h = (b - a) / static_cast<double>(n);
58
59 8 double local_sum = 0.0;
60
2/2
✓ Branch 0 taken 7500 times.
✓ Branch 1 taken 8 times.
7508 for (int i = start_i; i < end_i; ++i) {
61 7500 double x_left = a + (static_cast<double>(i) * h);
62 7500 double x_right = a + (static_cast<double>(i + 1) * h);
63
64 7500 double f_left = Function(x_left, in.func_id);
65 7500 double f_right = Function(x_right, in.func_id);
66
67 7500 local_sum += (f_left + f_right) * 0.5 * h;
68 }
69
70 8 double global_sum = 0.0;
71 8 MPI_Reduce(&local_sum, &global_sum, 1, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD);
72
73 8 MPI_Bcast(&global_sum, 1, MPI_DOUBLE, 0, MPI_COMM_WORLD);
74
75 8 GetOutput() = global_sum;
76
77 8 return true;
78 }
79
80 8 bool GalkinDTrapezoidMethodMPI::PostProcessingImpl() {
81 8 return true;
82 }
83
84 } // namespace galkin_d_trapezoid_method
85