| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "votincev_d_radixmerge_sort/omp/include/ops_omp.hpp" | ||
| 2 | |||
| 3 | #include <omp.h> | ||
| 4 | |||
| 5 | #include <algorithm> | ||
| 6 | #include <cstddef> | ||
| 7 | #include <cstdint> | ||
| 8 | #include <vector> | ||
| 9 | |||
| 10 | #include "votincev_d_radixmerge_sort/common/include/common.hpp" | ||
| 11 | |||
| 12 | namespace votincev_d_radixmerge_sort { | ||
| 13 | |||
| 14 |
1/2✓ Branch 1 taken 40 times.
✗ Branch 2 not taken.
|
40 | VotincevDRadixMergeSortOMP::VotincevDRadixMergeSortOMP(const InType &in) { |
| 15 | SetTypeOfTask(GetStaticTypeOfTask()); | ||
| 16 |
1/2✓ Branch 1 taken 40 times.
✗ Branch 2 not taken.
|
40 | GetInput() = in; |
| 17 | 40 | } | |
| 18 | |||
| 19 | 40 | bool VotincevDRadixMergeSortOMP::ValidationImpl() { | |
| 20 | 40 | return !GetInput().empty(); | |
| 21 | } | ||
| 22 | |||
| 23 | 40 | bool VotincevDRadixMergeSortOMP::PreProcessingImpl() { | |
| 24 | 40 | return true; | |
| 25 | } | ||
| 26 | |||
| 27 | 84 | void VotincevDRadixMergeSortOMP::SortByDigit(std::vector<int32_t> &array, int32_t exp) { | |
| 28 | 84 | std::vector<std::vector<int32_t>> buckets(10); | |
| 29 | |||
| 30 |
2/2✓ Branch 0 taken 52000 times.
✓ Branch 1 taken 84 times.
|
52084 | for (const auto &num : array) { |
| 31 | 52000 | int32_t digit = (num / exp) % 10; | |
| 32 |
2/2✓ Branch 0 taken 47768 times.
✓ Branch 1 taken 4232 times.
|
52000 | buckets[digit].push_back(num); |
| 33 | } | ||
| 34 | |||
| 35 | size_t index = 0; | ||
| 36 |
2/2✓ Branch 0 taken 840 times.
✓ Branch 1 taken 84 times.
|
924 | for (int i = 0; i < 10; ++i) { |
| 37 |
2/2✓ Branch 0 taken 52000 times.
✓ Branch 1 taken 840 times.
|
52840 | for (const auto &val : buckets[i]) { |
| 38 | 52000 | array[index++] = val; | |
| 39 | } | ||
| 40 | buckets[i].clear(); | ||
| 41 | } | ||
| 42 | 84 | } | |
| 43 | |||
| 44 |
1/2✓ Branch 0 taken 40 times.
✗ Branch 1 not taken.
|
40 | bool VotincevDRadixMergeSortOMP::RunImpl() { |
| 45 |
1/2✓ Branch 0 taken 40 times.
✗ Branch 1 not taken.
|
40 | if (GetInput().empty()) { |
| 46 | return false; | ||
| 47 | } | ||
| 48 | |||
| 49 | 40 | std::vector<int32_t> working_array = GetInput(); | |
| 50 | 40 | auto n = static_cast<int32_t>(working_array.size()); | |
| 51 | |||
| 52 | 40 | int32_t min_val = working_array[0]; | |
| 53 | 40 | #pragma omp parallel for reduction(min : min_val) default(none) shared(working_array, n) | |
| 54 | for (int32_t i = 0; i < n; ++i) { | ||
| 55 | min_val = std::min(min_val, working_array[i]); | ||
| 56 | } | ||
| 57 | |||
| 58 |
2/2✓ Branch 0 taken 20 times.
✓ Branch 1 taken 20 times.
|
40 | if (min_val < 0) { |
| 59 | 20 | #pragma omp parallel for default(none) shared(working_array, n, min_val) | |
| 60 | for (int32_t i = 0; i < n; ++i) { | ||
| 61 | working_array[i] -= min_val; | ||
| 62 | } | ||
| 63 | } | ||
| 64 | |||
| 65 | 40 | int32_t max_val = working_array[0]; | |
| 66 | 40 | #pragma omp parallel for reduction(max : max_val) default(none) shared(working_array, n) | |
| 67 | for (int32_t i = 0; i < n; ++i) { | ||
| 68 | max_val = std::max(max_val, working_array[i]); | ||
| 69 | } | ||
| 70 | |||
| 71 |
2/2✓ Branch 0 taken 84 times.
✓ Branch 1 taken 40 times.
|
124 | for (int32_t exp = 1; max_val / exp > 0; exp *= 10) { |
| 72 |
1/2✓ Branch 1 taken 84 times.
✗ Branch 2 not taken.
|
84 | SortByDigit(working_array, exp); |
| 73 | } | ||
| 74 | |||
| 75 |
2/2✓ Branch 0 taken 20 times.
✓ Branch 1 taken 20 times.
|
40 | if (min_val < 0) { |
| 76 | 20 | #pragma omp parallel for default(none) shared(working_array, n, min_val) | |
| 77 | for (int32_t i = 0; i < n; ++i) { | ||
| 78 | working_array[i] += min_val; | ||
| 79 | } | ||
| 80 | } | ||
| 81 | |||
| 82 |
1/2✓ Branch 1 taken 40 times.
✗ Branch 2 not taken.
|
40 | GetOutput() = working_array; |
| 83 | |||
| 84 | return true; | ||
| 85 | } | ||
| 86 | |||
| 87 | 40 | bool VotincevDRadixMergeSortOMP::PostProcessingImpl() { | |
| 88 | 40 | return true; | |
| 89 | } | ||
| 90 | |||
| 91 | } // namespace votincev_d_radixmerge_sort | ||
| 92 |