GCC Code Coverage Report


Directory: ./
File: tasks/eremin_v_rectangle_method/mpi/src/ops_mpi.cpp
Date: 2025-12-13 04:24:21
Exec Total Coverage
Lines: 36 36 100.0%
Functions: 5 5 100.0%
Branches: 16 28 57.1%

Line Branch Exec Source
1 #include "eremin_v_rectangle_method/mpi/include/ops_mpi.hpp"
2
3 #include <mpi.h>
4
5 #include <cmath>
6 #include <tuple>
7
8 #include "eremin_v_rectangle_method/common/include/common.hpp"
9
10 namespace eremin_v_rectangle_method {
11
12
1/2
✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
12 EreminVRectangleMethodMPI::EreminVRectangleMethodMPI(const InType &in) {
13 SetTypeOfTask(GetStaticTypeOfTask());
14 GetInput() = in;
15 12 GetOutput() = 0;
16 12 }
17
18 12 bool EreminVRectangleMethodMPI::ValidationImpl() {
19 auto &input = GetInput();
20
3/6
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 12 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 12 times.
12 return (std::get<0>(input) < std::get<1>(input)) && (std::get<2>(input) > 0) && (std::get<2>(input) <= 100000000) &&
21
3/6
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 12 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 12 times.
12 (std::get<0>(input) >= -1e9) && (std::get<0>(input) <= 1e9) && (std::get<1>(input) >= -1e9) &&
22
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 12 times.
24 (std::get<1>(input) <= 1e9) && (GetOutput() == 0);
23 }
24
25 12 bool EreminVRectangleMethodMPI::PreProcessingImpl() {
26 12 return true;
27 }
28
29 12 bool EreminVRectangleMethodMPI::RunImpl() {
30 12 int rank = 0;
31 12 int size = 0;
32 12 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
33 12 MPI_Comm_size(MPI_COMM_WORLD, &size);
34
35 12 double lower_bound = 0.0;
36 12 double upper_bound = 0.0;
37 12 int steps = 0;
38 12 double result = 0.0;
39
40
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if (rank == 0) {
41 auto &input = GetInput();
42 6 lower_bound = std::get<0>(input);
43 6 upper_bound = std::get<1>(input);
44 6 steps = std::get<2>(input);
45 }
46 12 MPI_Bcast(&lower_bound, 1, MPI_DOUBLE, 0, MPI_COMM_WORLD);
47 12 MPI_Bcast(&upper_bound, 1, MPI_DOUBLE, 0, MPI_COMM_WORLD);
48 12 MPI_Bcast(&steps, 1, MPI_INT, 0, MPI_COMM_WORLD);
49
50 12 const auto in_function = std::get<3>(GetInput());
51
52 12 double step_size = (upper_bound - lower_bound) / static_cast<double>(steps);
53 12 double local_result = 0.0;
54
55
2/2
✓ Branch 0 taken 311000 times.
✓ Branch 1 taken 12 times.
311012 for (int i = rank; i < steps; i += size) {
56
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 311000 times.
622000 local_result += in_function(lower_bound + ((static_cast<double>(i) + 0.5) * step_size));
57 }
58
59 12 local_result *= step_size;
60
61
1/2
✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
12 MPI_Allreduce(&local_result, &result, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD);
62
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 GetOutput() = result;
63 12 return true;
64 }
65
66 12 bool EreminVRectangleMethodMPI::PostProcessingImpl() {
67 12 return true;
68 }
69
70 } // namespace eremin_v_rectangle_method
71