Q:

thrust::sort_by_key with device_ptr errors

I have a problem with sorting by key using device ptr (thrust::device_ptr< int>). This:
thrust::sort_by_key(dev_ptr_key,dev_ptr_key+noOfSelectedRows,dev_ptr_val,dev_ptr_val+noOfSelectedRows);

gives error:
Error   48  error : call of an object of a class type without appropriate operator() or conversion functions to pointer-to-function type    

this error is from merging_sort.h and stable_merge_sort.incl.
Using begin():
thrust::sort_by_key(dev_ptr_key->begin(),dev_ptr_key->begin()+noOfSelectedRows,dev_ptr_val->begin(),dev_ptr_val->begin()+noOfSelectedRows);

gives error:
Error   28  error : loop in sequence of "operator->" functions starting at class "thrust::device_ptr<int>"

Anyone have idea how to make it working?
Thanks in advance

A:

There is no version of sort_by_key which matches your parameter list:
thrust::sort_by_key(dev_ptr_key,dev_ptr_key+noOfSelectedRows,dev_ptr_val,dev_ptr_val+noOfSelectedRows);

You are passing  the beginning of the key range, the end of the key range, the beginning of the value range, and the end of the value range.  But there is no need to pass the end of the value range (and no version of sort_by_key supports passing the end of the value range), because it is implicit in the length of the key range.
Try this instead:
thrust::sort_by_key(dev_ptr_key,dev_ptr_key+noOfSelectedRows,dev_ptr_val);

