I'm trying to sort an array using Thrust, but it doesn't work if the array is too big. (I have a GTX460 1GB memory)
I'm using cuda with c++ integration on VS2012, Here is my code :
my .cpp
extern "C" void thrust_sort(uint32_t *data, int n);
int main(int argc, char **argv){
int n = 2<<26;
uint32_t * v = new uint32_t[n];
srand(time(NULL));
for (int i = 0; i < n; ++i) {
v[i] = rand()%n;
}
thrust_sort(v, n);
delete [] v;
return 0;
}
my .cu
extern "C"
void thrust_sort(uint32_t *data, int n){
thrust::device_vector<uint32_t> d_data(data, data + n);
thrust::stable_sort(d_data.begin(), d_data.end());
thrust::copy(d_data.begin(), d_data.end(), data);
}
The program stop working at the start of stable_sort().
- How much more memory does stable_sort() need ?
- Is there a way to fix this ? (even if it makes it a bit slower or whatever)
- Is there another sorting algorithm that doesn't require more memory than the original array ?
Thanks for your help :)