GCC Code Coverage Report


Directory: ./
File: tasks/romanov_a_integration_rect_method/mpi/src/ops_mpi.cpp
Date: 2026-01-10 02:40:41
Exec Total Coverage
Lines: 40 41 97.6%
Functions: 5 5 100.0%
Branches: 15 26 57.7%

Line Branch Exec Source
1 #include "romanov_a_integration_rect_method/mpi/include/ops_mpi.hpp"
2
3 #include <mpi.h>
4
5 #include <algorithm>
6
7 #include "romanov_a_integration_rect_method/common/include/common.hpp"
8
9 namespace romanov_a_integration_rect_method {
10
11
1/2
✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
12 RomanovAIntegrationRectMethodMPI::RomanovAIntegrationRectMethodMPI(const InType &in) {
12 SetTypeOfTask(GetStaticTypeOfTask());
13 GetInput() = in;
14 12 GetOutput() = 0.0;
15 12 }
16
17 12 bool RomanovAIntegrationRectMethodMPI::ValidationImpl() {
18
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if (!IsEqual(GetOutput(), 0.0)) {
19 return false;
20 }
21
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if (std::get<3>(GetInput()) <= 0) {
22 return false;
23 }
24
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if (std::get<1>(GetInput()) >= std::get<2>(GetInput())) {
25 return false;
26 }
27 return true;
28 }
29
30 12 bool RomanovAIntegrationRectMethodMPI::PreProcessingImpl() {
31 12 return true;
32 }
33
34 12 bool RomanovAIntegrationRectMethodMPI::RunImpl() {
35 12 const auto f = std::get<0>(GetInput());
36
37 12 int rank = 0;
38
1/2
✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
12 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
39
40 12 int num_processes = 0;
41
1/2
✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
12 MPI_Comm_size(MPI_COMM_WORLD, &num_processes);
42
43 12 double a = 0.0;
44 12 double b = 0.0;
45 12 int n = 0;
46
47
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if (rank == 0) {
48 6 a = std::get<1>(GetInput());
49 6 b = std::get<2>(GetInput());
50 6 n = std::get<3>(GetInput());
51 }
52
53
1/2
✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
12 MPI_Bcast(&a, 1, MPI_DOUBLE, 0, MPI_COMM_WORLD);
54
1/2
✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
12 MPI_Bcast(&b, 1, MPI_DOUBLE, 0, MPI_COMM_WORLD);
55
1/2
✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
12 MPI_Bcast(&n, 1, MPI_INT, 0, MPI_COMM_WORLD);
56
57 12 int block_size = (n + num_processes - 1) / num_processes;
58
59 12 int left_border = rank * block_size;
60 12 int right_border = std::min(n, (rank + 1) * block_size);
61
62 12 double delta_x = (b - a) / static_cast<double>(n);
63 12 double mid = a + (delta_x * static_cast<double>(left_border)) + (delta_x / 2.0);
64
65 12 double current_result = 0.0;
66
67
2/2
✓ Branch 0 taken 4000013 times.
✓ Branch 1 taken 12 times.
4000025 for (int i = left_border; i < right_border; ++i) {
68 4000013 current_result += f(mid) * delta_x;
69 4000013 mid += delta_x;
70 }
71
72 12 double result = 0.0;
73
1/2
✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
12 MPI_Allreduce(&current_result, &result, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD);
74
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 GetOutput() = result;
75
76 12 return true;
77 }
78
79 12 bool RomanovAIntegrationRectMethodMPI::PostProcessingImpl() {
80 12 return true;
81 }
82
83 } // namespace romanov_a_integration_rect_method
84