Having an array of for instance 4 integers how can one determine it’s non-zero minimum – in the fastest way ?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
There is a parallel solution to this problem, but its probably not worth the effort.
First we define an operation
xchg(m, n)over an array a:This operation sorts two elements ‘m’ and ‘n’ in ascending order if they both contain non-zero values, or swaps them if the value in the ‘m’ element is zero.
Next we execute a set of five such operations as follows:
The paired
xchgoperations can be executed in parallel, reducing the time cost by 40% over a strictly sequential execution. When we’re finished, any non-zero elements in the array will be sorted in ascending order. The smallest-value element will be in a[0]. If that value is zero, there are no non-zero values in the array.This solution takes advantage of the inherent parallelism provided by sorting networks ( http://en.wikipedia.org/wiki/Sorting_network), but a sequential scan of 4 elements also uses no more than three comparison operations, and crucially requires half as many storage writes on average:
sequential scan