19 #ifndef viskores_cont_internal_ParallelRadixSortInterface_h
20 #define viskores_cont_internal_ParallelRadixSortInterface_h
26 #include <type_traits>
37 const size_t MIN_BYTES_FOR_PARALLEL = 400000;
38 const size_t BYTES_FOR_MAX_PARALLELISM = 4000000;
50 struct is_valid_compare_type : std::integral_constant<bool, false>
54 struct is_valid_compare_type<std::less<T>> : std::integral_constant<bool, true>
58 struct is_valid_compare_type<std::greater<T>> : std::integral_constant<bool, true>
62 struct is_valid_compare_type<
viskores::SortLess> : std::integral_constant<bool, true>
66 struct is_valid_compare_type<
viskores::SortGreater> : std::integral_constant<bool, true>
71 template <
typename BComp,
typename T>
72 BComp&& get_std_compare(BComp&& b, T&&)
74 return std::forward<BComp>(b);
79 return std::less<T>{};
84 return std::greater<T>{};
89 template <
typename T,
typename StorageTag,
typename BinaryCompare>
92 using type = PSortTag;
94 template <
typename T,
typename BinaryCompare>
95 struct sort_tag_type<T,
viskores::cont::StorageTagBasic, BinaryCompare>
97 using PrimT = std::is_arithmetic<T>;
98 using LongDT = std::is_same<T, long double>;
99 using BComp = is_valid_compare_type<BinaryCompare>;
100 using type =
typename std::
101 conditional<PrimT::value && BComp::value && !LongDT::value, RadixSortTag, PSortTag>::type;
104 template <
typename KeyType,
106 typename KeyStorageTagType,
107 typename ValueStorageTagType,
109 struct sortbykey_tag_type
111 using type = PSortTag;
113 template <
typename KeyType,
typename ValueType,
class BinaryCompare>
114 struct sortbykey_tag_type<KeyType,
120 using PrimKey = std::is_arithmetic<KeyType>;
121 using PrimValue = std::is_arithmetic<ValueType>;
122 using LongDKey = std::is_same<KeyType, long double>;
123 using BComp = is_valid_compare_type<BinaryCompare>;
124 using type =
typename std::conditional<PrimKey::value && PrimValue::value && BComp::value &&
130 #define VISKORES_INTERNAL_RADIX_SORT_DECLARE(key_type) \
131 VISKORES_CONT_EXPORT void parallel_radix_sort( \
132 key_type* data, size_t num_elems, const std::greater<key_type>& comp); \
133 VISKORES_CONT_EXPORT void parallel_radix_sort( \
134 key_type* data, size_t num_elems, const std::less<key_type>& comp); \
135 VISKORES_CONT_EXPORT void parallel_radix_sort_key_values( \
136 key_type* keys, viskores::Id* vals, size_t num_elems, const std::greater<key_type>& comp); \
137 VISKORES_CONT_EXPORT void parallel_radix_sort_key_values( \
138 key_type* keys, viskores::Id* vals, size_t num_elems, const std::less<key_type>& comp);
141 #define VISKORES_DECLARE_RADIX_SORT() \
142 VISKORES_INTERNAL_RADIX_SORT_DECLARE(short int) \
143 VISKORES_INTERNAL_RADIX_SORT_DECLARE(unsigned short int) \
144 VISKORES_INTERNAL_RADIX_SORT_DECLARE(int) \
145 VISKORES_INTERNAL_RADIX_SORT_DECLARE(unsigned int) \
146 VISKORES_INTERNAL_RADIX_SORT_DECLARE(long int) \
147 VISKORES_INTERNAL_RADIX_SORT_DECLARE(unsigned long int) \
148 VISKORES_INTERNAL_RADIX_SORT_DECLARE(long long int) \
149 VISKORES_INTERNAL_RADIX_SORT_DECLARE(unsigned long long int) \
150 VISKORES_INTERNAL_RADIX_SORT_DECLARE(unsigned char) \
151 VISKORES_INTERNAL_RADIX_SORT_DECLARE(signed char) \
152 VISKORES_INTERNAL_RADIX_SORT_DECLARE(char) \
153 VISKORES_INTERNAL_RADIX_SORT_DECLARE(char16_t) \
154 VISKORES_INTERNAL_RADIX_SORT_DECLARE(char32_t) \
155 VISKORES_INTERNAL_RADIX_SORT_DECLARE(wchar_t) \
156 VISKORES_INTERNAL_RADIX_SORT_DECLARE(float) \
157 VISKORES_INTERNAL_RADIX_SORT_DECLARE(double)
163 #endif // viskores_cont_internal_ParallelRadixSortInterface_h