11 #ifndef vtk_m_cont_tbb_internal_ParallelSort_h
12 #define vtk_m_cont_tbb_internal_ParallelSort_h
21 #include <vtkm/cont/tbb/internal/ParallelSortTBB.hxx>
23 #include <type_traits>
40 template <
typename T,
typename Container,
class BinaryCompare>
42 template <
typename T,
typename StorageT,
typename U,
typename StorageU,
class BinaryCompare>
48 template <
typename HandleType,
class BinaryCompare>
50 BinaryCompare binary_compare,
51 vtkm::cont::internal::radix::PSortTag)
54 auto arrayPortal = values.PrepareForInPlace(vtkm::cont::DeviceAdapterTagTBB(), token);
57 IteratorsType iterators(arrayPortal);
59 internal::WrappedBinaryOperator<bool, BinaryCompare> wrappedCompare(binary_compare);
64 template <
typename T,
typename StorageT,
class BinaryCompare>
66 BinaryCompare binary_compare,
67 vtkm::cont::internal::radix::RadixSortTag)
69 using namespace vtkm::cont::internal::radix;
70 auto c = get_std_compare(binary_compare, T{});
72 auto valuesPortal = values.
PrepareForInPlace(vtkm::cont::DeviceAdapterTagTBB{}, token);
74 valuesPortal.GetIteratorBegin(),
static_cast<std::size_t
>(values.
GetNumberOfValues()), c);
78 template <
typename T,
typename Container,
class BinaryCompare>
81 using namespace vtkm::cont::internal::radix;
82 using SortAlgorithmTag =
typename sort_tag_type<T, Container, BinaryCompare>::type;
88 template <
typename T,
typename StorageT,
typename U,
typename StorageU,
class BinaryCompare>
91 BinaryCompare binary_compare,
92 vtkm::cont::internal::radix::PSortTag)
94 using namespace vtkm::cont::internal::radix;
96 constexpr
bool larger_than_64bits =
sizeof(U) >
sizeof(vtkm::Int64);
97 if (larger_than_64bits)
106 IndexType indexArray;
107 ValueType valuesScattered;
113 auto inputPortal = handle.PrepareForInput(DeviceAdapterTagTBB(), token);
115 indexArray.PrepareForOutput(keys.
GetNumberOfValues(), DeviceAdapterTagTBB(), token);
121 vtkm::cont::internal::KeyCompare<T, vtkm::Id, BinaryCompare>(binary_compare),
128 indexArray.PrepareForInput(vtkm::cont::DeviceAdapterTagTBB(), token),
129 valuesScattered.PrepareForOutput(size, vtkm::cont::DeviceAdapterTagTBB(), token));
134 auto inputPortal = valuesScattered.PrepareForInput(DeviceAdapterTagTBB(), token);
136 values.
PrepareForOutput(valuesScattered.GetNumberOfValues(), DeviceAdapterTagTBB(), token);
137 tbb::CopyPortals(inputPortal, outputPortal, 0, 0, valuesScattered.GetNumberOfValues());
147 zipHandle, vtkm::cont::internal::KeyCompare<T, U, BinaryCompare>(binary_compare), PSortTag{});
152 template <
typename T,
typename StorageT,
typename StorageU,
class BinaryCompare>
155 BinaryCompare binary_compare,
156 vtkm::cont::internal::radix::RadixSortTag)
158 using namespace vtkm::cont::internal::radix;
159 auto c = get_std_compare(binary_compare, T{});
161 auto keysPortal = keys.
PrepareForInPlace(vtkm::cont::DeviceAdapterTagTBB{}, token);
162 auto valuesPortal = values.
PrepareForInPlace(vtkm::cont::DeviceAdapterTagTBB{}, token);
163 parallel_radix_sort_key_values(keysPortal.GetIteratorBegin(),
164 valuesPortal.GetIteratorBegin(),
170 template <
typename T,
typename StorageT,
typename U,
typename StorageU,
class BinaryCompare>
173 BinaryCompare binary_compare,
174 vtkm::cont::internal::radix::RadixSortTag)
181 IndexType indexArray;
182 ValueType valuesScattered;
188 auto inputPortal = handle.PrepareForInput(DeviceAdapterTagTBB(), token);
190 indexArray.PrepareForOutput(keys.
GetNumberOfValues(), DeviceAdapterTagTBB(), token);
202 vtkm::cont::internal::KeyCompare<T, vtkm::Id, BinaryCompare>(binary_compare),
203 vtkm::cont::internal::radix::PSortTag{});
210 indexArray.PrepareForInput(vtkm::cont::DeviceAdapterTagTBB(), token),
211 valuesScattered.PrepareForOutput(size, vtkm::cont::DeviceAdapterTagTBB(), token));
216 auto inputPortal = valuesScattered.PrepareForInput(DeviceAdapterTagTBB(), token);
218 values.
PrepareForOutput(valuesScattered.GetNumberOfValues(), DeviceAdapterTagTBB(), token);
219 tbb::CopyPortals(inputPortal, outputPortal, 0, 0, valuesScattered.GetNumberOfValues());
224 template <
typename T,
typename StorageT,
typename U,
typename StorageU,
class BinaryCompare>
227 BinaryCompare binary_compare)
229 using namespace vtkm::cont::internal::radix;
230 using SortAlgorithmTag =
231 typename sortbykey_tag_type<T, U, StorageT, StorageU, BinaryCompare>::type;
239 #endif // vtk_m_cont_tbb_internal_ParallelSort_h