GCC Code Coverage Report


Directory: ./
File: tasks/trofimov_n_hoar_sort_batcher/omp/src/ops_omp.cpp
Date: 2026-04-02 17:12:27
Exec Total Coverage
Lines: 19 33 57.6%
Functions: 6 7 85.7%
Branches: 8 20 40.0%

Line Branch Exec Source
1 #include "trofimov_n_hoar_sort_batcher/omp/include/ops_omp.hpp"
2
3 #include <algorithm>
4 #include <vector>
5
6 #include "trofimov_n_hoar_sort_batcher/common/include/common.hpp"
7
8 namespace trofimov_n_hoar_sort_batcher {
9
10 namespace {
11
12 int HoarePartition(std::vector<int> &arr, int left, int right) {
13 const int pivot = arr[left + ((right - left) / 2)];
14 int i = left - 1;
15 int j = right + 1;
16
17 while (true) {
18 while (arr[++i] < pivot) {
19 }
20
21 while (arr[--j] > pivot) {
22 }
23
24 if (i >= j) {
25 return j;
26 }
27
28 std::swap(arr[i], arr[j]);
29 }
30 }
31
32 42 void QuickSortOmpTask(std::vector<int> &arr, int left, int right, int depth_limit) {
33
1/2
✓ Branch 0 taken 42 times.
✗ Branch 1 not taken.
42 if (left >= right) {
34 return;
35 }
36
37 constexpr int kSequentialThreshold = 1024;
38
39
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 42 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
42 if ((right - left) < kSequentialThreshold || depth_limit <= 0) {
40 42 std::sort(arr.begin() + left, arr.begin() + right + 1);
41 42 return;
42 }
43
44 const int split = HoarePartition(arr, left, right);
45
46 #pragma omp task default(none) shared(arr) \
47 firstprivate(left, split, depth_limit) if ((split - left) > kSequentialThreshold)
48 QuickSortOmpTask(arr, left, split, depth_limit - 1);
49
50 #pragma omp task default(none) shared(arr) \
51 firstprivate(split, right, depth_limit) if ((right - (split + 1)) > kSequentialThreshold)
52 QuickSortOmpTask(arr, split + 1, right, depth_limit - 1);
53
54 #pragma omp taskwait
55 }
56
57 } // namespace
58
59
1/2
✓ Branch 1 taken 50 times.
✗ Branch 2 not taken.
50 TrofimovNHoarSortBatcherOMP::TrofimovNHoarSortBatcherOMP(const InType &in) {
60 SetTypeOfTask(GetStaticTypeOfTask());
61
1/2
✓ Branch 1 taken 50 times.
✗ Branch 2 not taken.
50 GetInput() = in;
62 50 }
63
64 50 bool TrofimovNHoarSortBatcherOMP::ValidationImpl() {
65 50 return true;
66 }
67
68 50 bool TrofimovNHoarSortBatcherOMP::PreProcessingImpl() {
69 50 GetOutput() = GetInput();
70 50 return true;
71 }
72
73
2/2
✓ Branch 0 taken 42 times.
✓ Branch 1 taken 8 times.
50 bool TrofimovNHoarSortBatcherOMP::RunImpl() {
74 auto &data = GetOutput();
75
76
2/2
✓ Branch 0 taken 42 times.
✓ Branch 1 taken 8 times.
50 if (data.size() <= 1) {
77 return true;
78 }
79
80 42 #pragma omp parallel default(none) shared(data)
81 {
82 #pragma omp single nowait
83 {
84 QuickSortOmpTask(data, 0, static_cast<int>(data.size()) - 1, 4);
85 }
86 }
87
88 42 return true;
89 }
90
91 50 bool TrofimovNHoarSortBatcherOMP::PostProcessingImpl() {
92 50 return true;
93 }
94
95 } // namespace trofimov_n_hoar_sort_batcher
96