44 #ifndef TPETRA_DETAILS_RADIXSORT_HPP
45 #define TPETRA_DETAILS_RADIXSORT_HPP
47 #include "TpetraCore_config.h"
48 #include "Kokkos_Macros.hpp"
66 template<
typename KeyType,
typename ValueType,
typename IndexType>
67 KOKKOS_INLINE_FUNCTION
void
68 radixSortKeysAndValues(KeyType* keys, KeyType* keysAux, ValueType* values, ValueType* valuesAux, IndexType n, IndexType upperBound)
75 IndexType maskPos = 0;
77 IndexType sortBits = 0;
83 for(IndexType s = 0; s < (sortBits + 3) / 4; s++)
86 IndexType count[16] = {0};
87 IndexType offset[17] = {0};
90 for(IndexType i = 0; i < n; i++)
92 count[(keys[i] & mask) >> maskPos]++;
97 for(IndexType i = 0; i < n; i++)
99 count[(keysAux[i] & mask) >> maskPos]++;
103 for(IndexType i = 0; i < 16; i++)
105 offset[i + 1] = offset[i] + count[i];
112 for(IndexType i = 0; i < n; i++)
114 IndexType bucket = (keys[i] & mask) >> maskPos;
115 keysAux[offset[bucket + 1] - count[bucket]] = keys[i];
116 valuesAux[offset[bucket + 1] - count[bucket]] = values[i];
123 for(IndexType i = 0; i < n; i++)
125 IndexType bucket = (keysAux[i] & mask) >> maskPos;
126 keys[offset[bucket + 1] - count[bucket]] = keysAux[i];
127 values[offset[bucket + 1] - count[bucket]] = valuesAux[i];
138 for(IndexType i = 0; i < n; i++)
140 keys[i] = keysAux[i];
141 values[i] = valuesAux[i];
149 #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.