GCC Code Coverage Report


Directory: ./
File: tasks/luzan_e_simps_int/mpi/src/ops_mpi.cpp
Date: 2026-01-10 02:40:41
Exec Total Coverage
Lines: 68 68 100.0%
Functions: 5 5 100.0%
Branches: 37 53 69.8%

Line Branch Exec Source
1 #include "luzan_e_simps_int/mpi/include/ops_mpi.hpp"
2
3 #include <mpi.h>
4
5 #include <tuple>
6 #include <vector>
7
8 #include "luzan_e_simps_int/common/include/common.hpp"
9
10 namespace luzan_e_simps_int {
11
12
1/2
✓ Branch 1 taken 32 times.
✗ Branch 2 not taken.
32 LuzanESimpsIntMPI::LuzanESimpsIntMPI(const InType &in) {
13 SetTypeOfTask(GetStaticTypeOfTask());
14 GetOutput() = {};
15
16 32 int rank = 0;
17
1/2
✓ Branch 1 taken 32 times.
✗ Branch 2 not taken.
32 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
18
19
2/2
✓ Branch 0 taken 16 times.
✓ Branch 1 taken 16 times.
32 if (rank == 0) {
20 GetInput() = in;
21 } else {
22 GetInput() = {};
23 }
24 32 }
25
26 32 bool LuzanESimpsIntMPI::ValidationImpl() {
27 32 int rank = 0;
28 32 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
29
2/2
✓ Branch 0 taken 16 times.
✓ Branch 1 taken 16 times.
32 if (rank != 0) {
30 return true;
31 }
32
33 16 int n = std::get<0>(GetInput());
34 16 double a = std::get<0>(std::get<1>(GetInput()));
35 16 double b = std::get<1>(std::get<1>(GetInput()));
36 16 double c = std::get<0>(std::get<2>(GetInput()));
37 16 double d = std::get<1>(std::get<2>(GetInput()));
38 16 int func_num = std::get<3>(GetInput());
39
3/6
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 16 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 16 times.
✗ Branch 5 not taken.
16 bool flag = (a < b) && (c < d) && (n % 2 == 0) && (n > 0) && (func_num >= 0);
40 return flag;
41 }
42
43 32 bool LuzanESimpsIntMPI::PreProcessingImpl() {
44 32 int rank = 0;
45 32 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
46
2/2
✓ Branch 0 taken 16 times.
✓ Branch 1 taken 16 times.
32 if (rank != 0) {
47 return true;
48 }
49
50 16 GetOutput() = 0.0;
51 16 return true;
52 }
53
54 32 bool LuzanESimpsIntMPI::RunImpl() {
55 32 int rank = 0;
56 32 int size = 0;
57 32 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
58 32 MPI_Comm_size(MPI_COMM_WORLD, &size);
59
60 double a = 0.0;
61 double b = 0.0;
62 double c = 0.0;
63 double d = 0.0;
64 32 int n = 0; // кол-во отрезков
65 32 int func_num = 0;
66
67 // sharing data
68 32 std::vector<double> tmp(4, 0);
69
2/2
✓ Branch 0 taken 16 times.
✓ Branch 1 taken 16 times.
32 if (rank == 0) {
70 16 n = std::get<0>(GetInput());
71 16 a = std::get<0>(std::get<1>(GetInput()));
72 16 b = std::get<1>(std::get<1>(GetInput()));
73 16 c = std::get<0>(std::get<2>(GetInput()));
74 16 d = std::get<1>(std::get<2>(GetInput()));
75 16 func_num = std::get<3>(GetInput());
76
1/4
✓ Branch 1 taken 16 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
32 tmp = {a, b, c, d};
77 }
78
1/2
✓ Branch 1 taken 32 times.
✗ Branch 2 not taken.
32 MPI_Bcast(&n, 1, MPI_INT, 0, MPI_COMM_WORLD);
79
1/2
✓ Branch 1 taken 32 times.
✗ Branch 2 not taken.
32 MPI_Bcast(&func_num, 1, MPI_INT, 0, MPI_COMM_WORLD);
80
1/2
✓ Branch 1 taken 32 times.
✗ Branch 2 not taken.
32 MPI_Bcast(tmp.data(), 4, MPI_DOUBLE, 0, MPI_COMM_WORLD);
81 32 a = tmp[0];
82 32 b = tmp[1];
83 32 c = tmp[2];
84 32 d = tmp[3];
85
1/2
✓ Branch 1 taken 32 times.
✗ Branch 2 not taken.
32 tmp.resize(0);
86
87 // mpi things
88 32 int rest = (n + 1) % size;
89 32 int per_proc = (n + 1) / size;
90
91 32 int i_start = (rank * per_proc) + (rest > rank ? rank : rest);
92
2/2
✓ Branch 0 taken 16 times.
✓ Branch 1 taken 16 times.
32 int i_end = i_start + per_proc + (rest > rank ? 1 : 0);
93
94 // calculations
95
5/5
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 4 times.
✓ Branch 2 taken 10 times.
✓ Branch 3 taken 2 times.
✓ Branch 4 taken 12 times.
32 double (*fp)(double, double) = GetFunc(func_num);
96 32 double hx = (b - a) / n;
97 32 double hy = (d - c) / n;
98
99 double wx = 1.0;
100 double wy = 1.0;
101 double x = 0.0;
102 double y = 0.0;
103
104 32 double local_sum = 0.0;
105 /// printf_s("rnak: %i, st = %i, end = %i\n", rank, i_start, i_end);
106
107
2/2
✓ Branch 0 taken 1090 times.
✓ Branch 1 taken 32 times.
1122 for (int i = i_start; i < i_end; i++) {
108 1090 x = a + (hx * i);
109
2/2
✓ Branch 0 taken 1058 times.
✓ Branch 1 taken 32 times.
1090 wx = GetWeight(i, n);
110
111
2/2
✓ Branch 0 taken 173544 times.
✓ Branch 1 taken 1090 times.
174634 for (int j = 0; j < n + 1; j++) {
112
2/2
✓ Branch 0 taken 171364 times.
✓ Branch 1 taken 2180 times.
173544 y = c + (hy * j);
113 wy = GetWeight(j, n);
114
1/2
✓ Branch 1 taken 173544 times.
✗ Branch 2 not taken.
173544 local_sum += wy * wx * fp(x, y);
115 }
116 }
117 32 local_sum *= hx * hy / (3 * 3);
118 32 double sum = 0;
119
1/2
✓ Branch 1 taken 32 times.
✗ Branch 2 not taken.
32 MPI_Reduce(&local_sum, &sum, 1, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD);
120
121 // finalize
122
1/2
✓ Branch 1 taken 32 times.
✗ Branch 2 not taken.
32 MPI_Bcast(&sum, 1, MPI_DOUBLE, 0, MPI_COMM_WORLD);
123
1/2
✓ Branch 0 taken 32 times.
✗ Branch 1 not taken.
32 GetOutput() = sum;
124 32 return true;
125 }
126
127 32 bool LuzanESimpsIntMPI::PostProcessingImpl() {
128 32 return true;
129 }
130
131 } // namespace luzan_e_simps_int
132