| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "frolova_s_radix_sort_double/tbb/include/ops_tbb.hpp" | ||
| 2 | |||
| 3 | #include <oneapi/tbb/parallel_for.h> | ||
| 4 | |||
| 5 | #include <algorithm> | ||
| 6 | #include <array> | ||
| 7 | #include <atomic> | ||
| 8 | #include <bit> | ||
| 9 | #include <cstddef> | ||
| 10 | #include <cstdint> | ||
| 11 | #include <utility> | ||
| 12 | #include <vector> | ||
| 13 | |||
| 14 | #include "frolova_s_radix_sort_double/common/include/common.hpp" | ||
| 15 | |||
| 16 | namespace frolova_s_radix_sort_double { | ||
| 17 | |||
| 18 |
1/2✓ Branch 1 taken 40 times.
✗ Branch 2 not taken.
|
40 | FrolovaSRadixSortDoubleTBB::FrolovaSRadixSortDoubleTBB(const InType &in) { |
| 19 | SetTypeOfTask(GetStaticTypeOfTask()); | ||
| 20 |
1/2✓ Branch 1 taken 40 times.
✗ Branch 2 not taken.
|
40 | GetInput() = in; |
| 21 | 40 | } | |
| 22 | |||
| 23 | 40 | bool FrolovaSRadixSortDoubleTBB::ValidationImpl() { | |
| 24 | 40 | return !GetInput().empty(); | |
| 25 | } | ||
| 26 | |||
| 27 | 40 | bool FrolovaSRadixSortDoubleTBB::PreProcessingImpl() { | |
| 28 | 40 | return true; | |
| 29 | } | ||
| 30 | |||
| 31 |
1/2✓ Branch 0 taken 40 times.
✗ Branch 1 not taken.
|
40 | bool FrolovaSRadixSortDoubleTBB::RunImpl() { |
| 32 | const std::vector<double> &input = GetInput(); | ||
| 33 |
1/2✓ Branch 0 taken 40 times.
✗ Branch 1 not taken.
|
40 | if (input.empty()) { |
| 34 | return false; | ||
| 35 | } | ||
| 36 | |||
| 37 | 40 | std::vector<double> working = input; | |
| 38 | const std::size_t n = working.size(); | ||
| 39 | |||
| 40 | constexpr int kRadix = 256; | ||
| 41 | constexpr int kNumBits = 8; | ||
| 42 | constexpr int kNumPasses = sizeof(std::uint64_t); | ||
| 43 | |||
| 44 |
1/4✓ Branch 1 taken 40 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
40 | std::vector<double> temp(n); |
| 45 | |||
| 46 |
2/2✓ Branch 0 taken 320 times.
✓ Branch 1 taken 40 times.
|
360 | for (int pass = 0; pass < kNumPasses; ++pass) { |
| 47 | 320 | std::array<std::atomic<int>, kRadix> count{}; | |
| 48 |
1/4✓ Branch 1 taken 320 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
320 | tbb::parallel_for(std::size_t{0}, n, [&](std::size_t i) { |
| 49 | 133120 | auto bits = std::bit_cast<std::uint64_t>(working[i]); | |
| 50 | 133120 | int byte = static_cast<int>((bits >> (pass * kNumBits)) & 0xFF); | |
| 51 | 133120 | count.at(byte).fetch_add(1, std::memory_order_relaxed); | |
| 52 | 133120 | }); | |
| 53 | |||
| 54 | 320 | std::array<int, kRadix> offset{}; | |
| 55 | int total = 0; | ||
| 56 |
2/2✓ Branch 0 taken 81920 times.
✓ Branch 1 taken 320 times.
|
82240 | for (int i = 0; i < kRadix; ++i) { |
| 57 | 81920 | offset.at(i) = total; | |
| 58 | 81920 | total += count.at(i).load(); | |
| 59 | } | ||
| 60 | |||
| 61 |
3/4✗ Branch 0 not taken.
✓ Branch 1 taken 133120 times.
✓ Branch 2 taken 133120 times.
✓ Branch 3 taken 320 times.
|
133440 | for (double val : working) { |
| 62 | auto bits = std::bit_cast<std::uint64_t>(val); | ||
| 63 | 133120 | int byte = static_cast<int>((bits >> (pass * kNumBits)) & 0xFF); | |
| 64 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 133120 times.
|
133120 | temp.at(offset.at(byte)++) = val; |
| 65 | } | ||
| 66 | |||
| 67 | working.swap(temp); | ||
| 68 | } | ||
| 69 | |||
| 70 | 40 | std::vector<double> negative; | |
| 71 | 40 | std::vector<double> positive; | |
| 72 |
1/2✓ Branch 1 taken 40 times.
✗ Branch 2 not taken.
|
40 | negative.reserve(n); |
| 73 |
1/2✓ Branch 1 taken 40 times.
✗ Branch 2 not taken.
|
40 | positive.reserve(n); |
| 74 | |||
| 75 |
2/2✓ Branch 0 taken 16640 times.
✓ Branch 1 taken 40 times.
|
16680 | for (double val : working) { |
| 76 |
2/2✓ Branch 0 taken 3964 times.
✓ Branch 1 taken 12676 times.
|
16640 | if (val < 0.0) { |
| 77 | negative.push_back(val); | ||
| 78 | } else { | ||
| 79 | positive.push_back(val); | ||
| 80 | } | ||
| 81 | } | ||
| 82 | std::ranges::reverse(negative); | ||
| 83 | |||
| 84 | working.clear(); | ||
| 85 |
1/2✓ Branch 1 taken 40 times.
✗ Branch 2 not taken.
|
40 | working.insert(working.end(), negative.begin(), negative.end()); |
| 86 | 40 | working.insert(working.end(), positive.begin(), positive.end()); | |
| 87 | |||
| 88 | GetOutput() = std::move(working); | ||
| 89 | return true; | ||
| 90 | } | ||
| 91 | |||
| 92 | 40 | bool FrolovaSRadixSortDoubleTBB::PostProcessingImpl() { | |
| 93 | 40 | return true; | |
| 94 | } | ||
| 95 | |||
| 96 | } // namespace frolova_s_radix_sort_double | ||
| 97 |