11 #ifndef vtk_m_cont_internal_ParallelRadixSortInterface_h
12 #define vtk_m_cont_internal_ParallelRadixSortInterface_h
18 #include <type_traits>
29 const size_t MIN_BYTES_FOR_PARALLEL = 400000;
30 const size_t BYTES_FOR_MAX_PARALLELISM = 4000000;
42 struct is_valid_compare_type : std::integral_constant<bool, false>
46 struct is_valid_compare_type<std::less<T>> : std::integral_constant<bool, true>
50 struct is_valid_compare_type<std::greater<T>> : std::integral_constant<bool, true>
54 struct is_valid_compare_type<
vtkm::SortLess> : std::integral_constant<bool, true>
58 struct is_valid_compare_type<
vtkm::SortGreater> : std::integral_constant<bool, true>
63 template <
typename BComp,
typename T>
64 BComp&& get_std_compare(BComp&& b, T&&)
66 return std::forward<BComp>(b);
71 return std::less<T>{};
76 return std::greater<T>{};
81 template <
typename T,
typename StorageTag,
typename BinaryCompare>
84 using type = PSortTag;
86 template <
typename T,
typename BinaryCompare>
87 struct sort_tag_type<T,
vtkm::cont::StorageTagBasic, BinaryCompare>
89 using PrimT = std::is_arithmetic<T>;
90 using LongDT = std::is_same<T, long double>;
91 using BComp = is_valid_compare_type<BinaryCompare>;
92 using type =
typename std::
93 conditional<PrimT::value && BComp::value && !LongDT::value, RadixSortTag, PSortTag>::type;
96 template <
typename KeyType,
98 typename KeyStorageTagType,
99 typename ValueStorageTagType,
101 struct sortbykey_tag_type
103 using type = PSortTag;
105 template <
typename KeyType,
typename ValueType,
class BinaryCompare>
106 struct sortbykey_tag_type<KeyType,
108 vtkm::cont::StorageTagBasic,
112 using PrimKey = std::is_arithmetic<KeyType>;
113 using PrimValue = std::is_arithmetic<ValueType>;
114 using LongDKey = std::is_same<KeyType, long double>;
115 using BComp = is_valid_compare_type<BinaryCompare>;
116 using type =
typename std::conditional<PrimKey::value && PrimValue::value && BComp::value &&
122 #define VTKM_INTERNAL_RADIX_SORT_DECLARE(key_type) \
123 VTKM_CONT_EXPORT void parallel_radix_sort( \
124 key_type* data, size_t num_elems, const std::greater<key_type>& comp); \
125 VTKM_CONT_EXPORT void parallel_radix_sort( \
126 key_type* data, size_t num_elems, const std::less<key_type>& comp); \
127 VTKM_CONT_EXPORT void parallel_radix_sort_key_values( \
128 key_type* keys, vtkm::Id* vals, size_t num_elems, const std::greater<key_type>& comp); \
129 VTKM_CONT_EXPORT void parallel_radix_sort_key_values( \
130 key_type* keys, vtkm::Id* vals, size_t num_elems, const std::less<key_type>& comp);
133 #define VTKM_DECLARE_RADIX_SORT() \
134 VTKM_INTERNAL_RADIX_SORT_DECLARE(short int) \
135 VTKM_INTERNAL_RADIX_SORT_DECLARE(unsigned short int) \
136 VTKM_INTERNAL_RADIX_SORT_DECLARE(int) \
137 VTKM_INTERNAL_RADIX_SORT_DECLARE(unsigned int) \
138 VTKM_INTERNAL_RADIX_SORT_DECLARE(long int) \
139 VTKM_INTERNAL_RADIX_SORT_DECLARE(unsigned long int) \
140 VTKM_INTERNAL_RADIX_SORT_DECLARE(long long int) \
141 VTKM_INTERNAL_RADIX_SORT_DECLARE(unsigned long long int) \
142 VTKM_INTERNAL_RADIX_SORT_DECLARE(unsigned char) \
143 VTKM_INTERNAL_RADIX_SORT_DECLARE(signed char) \
144 VTKM_INTERNAL_RADIX_SORT_DECLARE(char) \
145 VTKM_INTERNAL_RADIX_SORT_DECLARE(char16_t) \
146 VTKM_INTERNAL_RADIX_SORT_DECLARE(char32_t) \
147 VTKM_INTERNAL_RADIX_SORT_DECLARE(wchar_t) \
148 VTKM_INTERNAL_RADIX_SORT_DECLARE(float) \
149 VTKM_INTERNAL_RADIX_SORT_DECLARE(double)
155 #endif // vtk_m_cont_internal_ParallelRadixSortInterface_h