GCC Code Coverage Report


Directory: ./
File: tasks/lopatin_a_trapezoidal_integration/mpi/src/ops_mpi.cpp
Date: 2026-01-09 01:27:18
Exec Total Coverage
Lines: 48 48 100.0%
Functions: 6 6 100.0%
Branches: 28 40 70.0%

Line Branch Exec Source
1 #include "lopatin_a_trapezoidal_integration/mpi/include/ops_mpi.hpp"
2
3 #include <mpi.h>
4
5 #include "lopatin_a_trapezoidal_integration/common/include/common.hpp"
6
7 namespace lopatin_a_trapezoidal_integration {
8
9
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 LopatinATrapezoidalIntegrationMPI::LopatinATrapezoidalIntegrationMPI(const InType &in) {
10 SetTypeOfTask(GetStaticTypeOfTask());
11 GetInput() = in;
12 10 }
13
14 10 bool LopatinATrapezoidalIntegrationMPI::ValidationImpl() {
15 const auto &input = GetInput();
16
4/8
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 10 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 10 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 10 times.
10 return (input.b > input.a) && (input.d > input.c) && (input.f != nullptr) && (input.n > 0);
17 }
18
19 10 bool LopatinATrapezoidalIntegrationMPI::PreProcessingImpl() {
20 10 GetOutput() = 0.0;
21 10 return GetOutput() == 0.0;
22 }
23
24 5 double LopatinATrapezoidalIntegrationMPI::CalcTail(int start, const IntegrationData &input, double h, double k) {
25 double tail_res = 0.0;
26
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 5 times.
10 for (int i = start; i <= input.n; ++i) {
27 5 double xi = input.a + (i * h);
28 double wx = 1.0;
29
2/4
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 5 times.
5 if (xi == 0 || xi == input.n) {
30 wx = 0.5;
31 }
32
33
2/2
✓ Branch 0 taken 2505 times.
✓ Branch 1 taken 5 times.
2510 for (int j = 0; j <= input.n; ++j) {
34 2505 double yi = input.c + (j * k);
35 double wy = 1.0;
36
2/4
✓ Branch 0 taken 2505 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2505 times.
2505 if (yi == 0 || yi == input.n) {
37 wy = 0.5;
38 }
39
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2505 times.
5010 tail_res += wx * wy * input.f(xi, yi);
40 }
41 }
42 5 tail_res *= h * k;
43 5 return tail_res;
44 }
45
46 10 bool LopatinATrapezoidalIntegrationMPI::RunImpl() {
47 10 int proc_num = 0;
48 10 MPI_Comm_size(MPI_COMM_WORLD, &proc_num);
49 10 int proc_rank = 0;
50 10 MPI_Comm_rank(MPI_COMM_WORLD, &proc_rank);
51
52 const auto &input = GetInput();
53 const auto &f = input.f;
54
55 10 double h = (input.b - input.a) / input.n;
56 10 double k = (input.d - input.c) / input.n;
57
58 10 int local_n = (input.n + 1) / proc_num;
59 10 double local_res = 0.0;
60
61 10 int start = proc_rank * local_n;
62 10 int end = start + local_n;
63
64
2/2
✓ Branch 0 taken 2500 times.
✓ Branch 1 taken 10 times.
2510 for (int i = start; i < end; ++i) {
65 2500 double xi = input.a + (i * h);
66 double wx = 1.0;
67
3/4
✓ Branch 0 taken 2495 times.
✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2495 times.
2500 if (i == 0 || i == input.n) {
68 wx = 0.5;
69 }
70
71
2/2
✓ Branch 0 taken 1252500 times.
✓ Branch 1 taken 2500 times.
1255000 for (int j = 0; j <= input.n; ++j) {
72 1252500 double yi = input.c + (j * k);
73 double wy = 1.0;
74
4/4
✓ Branch 0 taken 1250000 times.
✓ Branch 1 taken 2500 times.
✓ Branch 2 taken 2500 times.
✓ Branch 3 taken 1247500 times.
1252500 if (j == 0 || j == input.n) {
75 wy = 0.5;
76 }
77
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1252500 times.
2505000 local_res += wx * wy * f(xi, yi);
78 }
79 }
80 10 local_res *= h * k;
81
82 10 double global_res = 0.0;
83 10 MPI_Reduce(&local_res, &global_res, 1, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD);
84
85
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 5 times.
10 if (proc_rank == 0) {
86 5 start = proc_num * local_n;
87 5 double tail_res = CalcTail(start, input, h, k);
88 5 global_res += tail_res;
89 }
90
91 10 MPI_Bcast(&global_res, 1, MPI_DOUBLE, 0, MPI_COMM_WORLD);
92 10 GetOutput() = global_res;
93
94 10 MPI_Barrier(MPI_COMM_WORLD);
95 10 return true;
96 }
97
98 10 bool LopatinATrapezoidalIntegrationMPI::PostProcessingImpl() {
99 10 return true;
100 }
101
102 } // namespace lopatin_a_trapezoidal_integration
103