10 #ifndef TPETRA_DETAILS_RADIXSORT_HPP
11 #define TPETRA_DETAILS_RADIXSORT_HPP
13 #include "TpetraCore_config.h"
14 #include "Kokkos_Macros.hpp"
30 template <
typename KeyType,
typename ValueType,
typename IndexType>
31 KOKKOS_INLINE_FUNCTION
void
32 radixSortKeysAndValues(KeyType* keys, KeyType* keysAux, ValueType* values, ValueType* valuesAux, IndexType n, IndexType upperBound) {
38 IndexType maskPos = 0;
40 IndexType sortBits = 0;
45 for (IndexType s = 0; s < (sortBits + 3) / 4; s++) {
47 IndexType count[16] = {0};
48 IndexType offset[17] = {0};
50 for (IndexType i = 0; i < n; i++) {
51 count[(keys[i] & mask) >> maskPos]++;
54 for (IndexType i = 0; i < n; i++) {
55 count[(keysAux[i] & mask) >> maskPos]++;
59 for (IndexType i = 0; i < 16; i++) {
60 offset[i + 1] = offset[i] + count[i];
66 for (IndexType i = 0; i < n; i++) {
67 IndexType bucket = (keys[i] & mask) >> maskPos;
68 keysAux[offset[bucket + 1] - count[bucket]] = keys[i];
69 valuesAux[offset[bucket + 1] - count[bucket]] = values[i];
74 for (IndexType i = 0; i < n; i++) {
75 IndexType bucket = (keysAux[i] & mask) >> maskPos;
76 keys[offset[bucket + 1] - count[bucket]] = keysAux[i];
77 values[offset[bucket + 1] - count[bucket]] = valuesAux[i];
87 for (IndexType i = 0; i < n; i++) {
89 values[i] = valuesAux[i];
97 #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.