10 #ifndef TPETRA_DETAILS_RADIXSORT_HPP
11 #define TPETRA_DETAILS_RADIXSORT_HPP
13 #include "TpetraCore_config.h"
14 #include "Kokkos_Macros.hpp"
32 template<
typename KeyType,
typename ValueType,
typename IndexType>
33 KOKKOS_INLINE_FUNCTION
void
34 radixSortKeysAndValues(KeyType* keys, KeyType* keysAux, ValueType* values, ValueType* valuesAux, IndexType n, IndexType upperBound)
41 IndexType maskPos = 0;
43 IndexType sortBits = 0;
49 for(IndexType s = 0; s < (sortBits + 3) / 4; s++)
52 IndexType count[16] = {0};
53 IndexType offset[17] = {0};
56 for(IndexType i = 0; i < n; i++)
58 count[(keys[i] & mask) >> maskPos]++;
63 for(IndexType i = 0; i < n; i++)
65 count[(keysAux[i] & mask) >> maskPos]++;
69 for(IndexType i = 0; i < 16; i++)
71 offset[i + 1] = offset[i] + count[i];
78 for(IndexType i = 0; i < n; i++)
80 IndexType bucket = (keys[i] & mask) >> maskPos;
81 keysAux[offset[bucket + 1] - count[bucket]] = keys[i];
82 valuesAux[offset[bucket + 1] - count[bucket]] = values[i];
89 for(IndexType i = 0; i < n; i++)
91 IndexType bucket = (keysAux[i] & mask) >> maskPos;
92 keys[offset[bucket + 1] - count[bucket]] = keysAux[i];
93 values[offset[bucket + 1] - count[bucket]] = valuesAux[i];
104 for(IndexType i = 0; i < n; i++)
106 keys[i] = keysAux[i];
107 values[i] = valuesAux[i];
115 #endif //include guard
KOKKOS_INLINE_FUNCTION void radixSortKeysAndValues(KeyType *keys, KeyType *keysAux, ValueType *values, ValueType *valuesAux, IndexType n, IndexType upperBound)
Radix sort the input array keys, and permute values identically to the keys.