Thrust question

Hi,

I have two questions regarding Thrust.

  1. Why is there no sub group for Thrust?? :)

  2. If I want to sort a “float *” array inplace using thrust::sort, how do I do this?

Currently I do something like this:

thrust::host_vector<float> h_vec1(50);

float *fData = new float[ 50 ];

thrust::device_vector<float> d_x( &(fData[0]), &(fData[0]) + 50);

thrust::sort(d_x.begin(), d_x.end());

thrust::copy(d_x.begin(), d_x.end(), h_vec.begin());

thrust::copy(h_vec1.begin(), h_vec1.end(), std::ostream_iterator<float>(std::cout, "\n"));

This code uses a temporary host_vector (h_vec1). How do I remove the need for it and copy the sorted

result right back from the device to the original fData array?

thanks

eyal

does

thrust::copy(d_x.begin(), d_x.end(), fData);

not work?

Also regarding 1), the thrust “forum” is here: http://groups.google.com/group/thrust-users

There’s no subforum for Thrust, but there is a dedicated mailing list (thrust-users).

To eliminate the h_vec1 temporary, just use fData directly. Note that fData is a valid “iterator” (just like .begin() and .end()) so you can use fData and fData + 50 to define the beginning and end of the host array. Thrust will assume that a “raw pointer” like fData lives on the host.

float *fData = new float[ 50 ];

thrust::device_vector<float> d_x(fData, fData + 50);

thrust::sort(d_x.begin(), d_x.end());

thrust::copy(d_x.begin(), d_x.end(), fData);

thrust::copy(fData, fData + 50, std::ostream_iterator<float>(std::cout, "\n"));

Very elegant :) works like a charm…

Thanks

eyal