I'm trying to find the minimum number in a array using Thrust and CUDA.
The following device example returns with 0 :
thrust::device_vector<float4>::iterator it = thrust::min_element(IntsOnDev.begin(),IntsOnDev.end(),equalOperator()); int pos = it - IntsOnDev.begin(); However, this host version works perfectly:
thrust::host_vector<float4>arr = IntsOnDev; thrust::host_vector<float4>::iterator it2 = thrust::min_element(arr.begin(),arr.end(),equalOperator()); int pos2 = it2 - arr.begin(); the comperator type :
struct equalOperator { __host__ __device__ bool operator()(const float4 x,const float4 y) const { return ( x.w < y.w ); } }; I just wanted to add that thrust::sort works with the same predicate.
my_float4, i.e.struct my_float4 { float x,y,z,w; };?