find the index of best value in a device array

I have an array in device memory. My task is to find the minimum value in this array and record its index number. Please note it is not necessary to sort the array. What is the best to accompolish this task?

Thank you,

What you’re asking for is called a “reduction”. It’s a common tool used over and over in many areas. It’s often done warp-wide, block wide, or sometimes kernel wide.

Take a look at the SDK demo projects for an example and docs.

Thank you for the reply. I saw the reduction example. It implemented sum. Is there an implementation for min or max? All I want to know is the index of the element with the minimum value. The original values should not be changed after the searching process. Thanks again,

Certainly, reduction works with any transitive function. The 4 most common ones are add, mult, minimum, and maximum. Just use min(a,B) instead of a+b in each of the accumulation steps.