How do I get not only the value but also the position of the maximum (minimum) element (res.val and res.pos)?
thrust::host_vector<float> h_vec(100);
thrust::generate(h_vec.begin(), h_vec.end(), rand);
thrust::device_vector<float> d_vec = h_vec;
T res = -1;
res = thrust::reduce(d_vec.begin(), d_vec.end(), res, thrust::maximum<T>());
Don’t use
thrust::reduce. Usethrust::max_element(thrust::min_element) inthrust/extrema.h:Be careful when passing an empty range to
max_element— you won’t be able to safely dereference the result.