GCC Code Coverage Report


Directory: ./
File: tasks/kutuzov_i_convex_hull_jarvis/omp/src/ops_omp.cpp
Date: 2026-04-02 17:12:27
Exec Total Coverage
Lines: 19 31 61.3%
Functions: 5 9 55.6%
Branches: 8 16 50.0%

Line Branch Exec Source
1 #include "kutuzov_i_convex_hull_jarvis/omp/include/ops_omp.hpp"
2
3 #include <omp.h>
4
5 #include <cmath>
6 #include <cstddef>
7 #include <vector>
8
9 #include "kutuzov_i_convex_hull_jarvis/common/include/common.hpp"
10
11 namespace kutuzov_i_convex_hull_jarvis {
12
13
1/2
✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
12 KutuzovITestConvexHullOMP::KutuzovITestConvexHullOMP(const InType &in) {
14 SetTypeOfTask(GetStaticTypeOfTask());
15
1/2
✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
12 GetInput() = in;
16 GetOutput() = {};
17 12 }
18
19 double KutuzovITestConvexHullOMP::DistanceSquared(double a_x, double a_y, double b_x, double b_y) {
20 return ((a_x - b_x) * (a_x - b_x)) + ((a_y - b_y) * (a_y - b_y));
21 }
22
23 double KutuzovITestConvexHullOMP::CrossProduct(double o_x, double o_y, double a_x, double a_y, double b_x, double b_y) {
24 return ((a_x - o_x) * (b_y - o_y)) - ((a_y - o_y) * (b_x - o_x));
25 }
26
27 size_t KutuzovITestConvexHullOMP::FindLeftmostPoint(const InType &input) {
28 size_t leftmost = 0;
29
30 12 #pragma omp parallel default(none) shared(input, leftmost)
31 {
32 size_t local_leftmost = 0;
33 double local_leftmost_x = std::get<0>(input[local_leftmost]);
34 double local_leftmost_y = std::get<1>(input[local_leftmost]);
35
36 #pragma omp for nowait
37 for (size_t i = 0; i < input.size(); ++i) {
38 double x = std::get<0>(input[i]);
39 double y = std::get<1>(input[i]);
40
41 if ((x < local_leftmost_x) || ((x == local_leftmost_x) && (y < local_leftmost_y))) {
42 local_leftmost = i;
43 local_leftmost_x = x;
44 local_leftmost_y = y;
45 }
46 }
47
48 #pragma omp critical
49 {
50 double leftmost_x = std::get<0>(input[leftmost]);
51 double leftmost_y = std::get<1>(input[leftmost]);
52
53 if ((local_leftmost_x < leftmost_x) || ((local_leftmost_x == leftmost_x) && (local_leftmost_y < leftmost_y))) {
54 leftmost = local_leftmost;
55 }
56 }
57 }
58 return leftmost;
59 }
60
61 bool KutuzovITestConvexHullOMP::IsBetterPoint(double cross, double epsilon, double current_x, double current_y,
62 double i_x, double i_y, double next_x, double next_y) {
63 if (cross < -epsilon) {
64 return true;
65 }
66
67 if (std::abs(cross) < epsilon) {
68 return DistanceSquared(current_x, current_y, i_x, i_y) > DistanceSquared(current_x, current_y, next_x, next_y);
69 }
70
71 return false;
72 }
73
74 12 bool KutuzovITestConvexHullOMP::ValidationImpl() {
75 12 return true;
76 }
77
78 12 bool KutuzovITestConvexHullOMP::PreProcessingImpl() {
79 12 return true;
80 }
81
82
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 bool KutuzovITestConvexHullOMP::RunImpl() {
83
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if (GetInput().size() < 3) {
84 GetOutput() = GetInput();
85 return true;
86 }
87
88 // Finding left-most point
89 size_t leftmost = FindLeftmostPoint(GetInput());
90
91 // Main loop
92 size_t current = leftmost;
93 12 double current_x = std::get<0>(GetInput()[current]);
94 12 double current_y = std::get<1>(GetInput()[current]);
95
96 const double epsilon = 1e-9;
97
98 while (true) {
99 // Adding current point to the hull
100 GetOutput().push_back(GetInput()[current]);
101
102 // Finding the next point of the hull
103
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 12 times.
36 size_t next = (current + 1) % GetInput().size();
104 36 double next_x = std::get<0>(GetInput()[next]);
105 36 double next_y = std::get<1>(GetInput()[next]);
106
107 36 #pragma omp parallel default(none) shared(current, current_x, current_y, next, next_x, next_y, epsilon)
108 {
109 size_t local_next = (current + 1) % GetInput().size();
110 double local_next_x = std::get<0>(GetInput()[local_next]);
111 double local_next_y = std::get<1>(GetInput()[local_next]);
112
113 #pragma omp for nowait
114 for (size_t i = 0; i < GetInput().size(); ++i) {
115 if (i == current) {
116 continue;
117 }
118
119 double i_x = std::get<0>(GetInput()[i]);
120 double i_y = std::get<1>(GetInput()[i]);
121
122 double cross = CrossProduct(current_x, current_y, local_next_x, local_next_y, i_x, i_y);
123
124 if (IsBetterPoint(cross, epsilon, current_x, current_y, i_x, i_y, local_next_x, local_next_y)) {
125 local_next = i;
126 local_next_x = i_x;
127 local_next_y = i_y;
128 }
129 }
130
131 #pragma omp critical
132 {
133 double cross = CrossProduct(current_x, current_y, next_x, next_y, local_next_x, local_next_y);
134
135 if (IsBetterPoint(cross, epsilon, current_x, current_y, local_next_x, local_next_y, next_x, next_y)) {
136 next = local_next;
137 next_x = local_next_x;
138 next_y = local_next_y;
139 }
140 }
141 }
142
143 current = next;
144 current_x = next_x;
145 current_y = next_y;
146
147 // Loop until we wrap around to the first point
148
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 12 times.
36 if (current == leftmost) {
149 break;
150 }
151 }
152 return true;
153 }
154
155 12 bool KutuzovITestConvexHullOMP::PostProcessingImpl() {
156 12 return true;
157 }
158
159 } // namespace kutuzov_i_convex_hull_jarvis
160