I have a bool array "a flag array stored as char*" I want to efficiently sort it using radix sort, what I understand is that radix sort complexity is O(#bits N) which will be O(8N) for char* and O(N) for a bool* (if it exists)
I've tried thrust::stable_sort_by_key, on my device sorting 2^21 char pointer takes 1.7 ms another test was by using a compare function for the first bit only:
struct OBCmp {
__host__ __device__
bool operator()(const char& o1, const char& o2) {
return (o1 & 1) < (o2 & 1);
}
};
the result time using thrust::stable_sort_by_key(d_vec.begin(), d_vec.end(), d_vec_values.begin(), OBCmp ()); was 9 ms
but I'm almost sure that it has used another algorithm "not radix sort", and my guess is that if I can make radix sort to use only the first bit, the time should be around 0.3 ms
any hint how to do this? "even manually without thrust"
trues. If you really need it sorted, I would go with a variation of quick sort. It will only need one pass and, therefore, isO(n). But you should implement it yourself because your requirements are quite special. General sorting algorithms won't get max performance.thrust::partitionandthrust::sortboth have to move data.thrust::countandthrust::filldon't do any data movement.