Hey there,

I have an array of 119.046 integers. I want the minimum value and its index. How could I find these a fast way?

At this moment I do it on CPU by iterating over all values but thats slow as hell.

Many thanks in advance!

Hey there,

I have an array of 119.046 integers. I want the minimum value and its index. How could I find these a fast way?

At this moment I do it on CPU by iterating over all values but thats slow as hell.

Many thanks in advance!

CUDA won’t help you here… the CPU can do the search faster than the time it takes to send the data to the GPU.

If the data were already on the GPU, then a standard reduction is fast and efficient… see the SDK reduction example.

I think you can use radix sort in CUDA SDK sample code. As you just need the minum value. Wish it will help you!

Indeed the array is already stored on GPU. I’ll have a look for that reduction. Thanks SPWorley

I found this link on another forum and have found it hugely useful… http://developer.download.nvidia.com/compu…c/reduction.pdf

It’s basically a guide to optimising a reduction (summing the values of a vector) going through several version of code and showing you how to make it quicker. It would be simple to adjust this to find the min and index.

Another useful link is the thrust library, there is a command in there to find the min of a vector and it’s damn quick however I don’t know if it will give you the index too.

thrust… http://code.google.com/p/thrust/wiki/Tutorial

Hope this helps

Hi anthony,

that is what I found too. Nice explanations and a pretty insight into how much optimization options there are in parallel computing. Thanks anyway. The second one (Thrust) will be the second choice if the first one fails :D.

Thanks alltogether!

Ok Fu-chang I’ll keep that in mind. But it seems to me, that a sorting algorithm might be too much for only getting one value. I’ll have to check that. Thanks

CUBLAS provides min and max functions for both float and double arrays (so you’d have to cast if you want to use it). See cublasIsamax(), cublasIsamin(), cublasIdamax(), and cublasIdamin().