next up previous
Next: Up: Previous:

Pseudocode

Fast-Max(A)
$\;\;\;\;\;$n = length(A)
$\;\;\;\;\;$for i = 0 to n-1, in parallel
$\;\;\;\;\;$ $\;\;\;\;\;$m(i) = true
$\;\;\;\;\;$for i = 0 to n-1, j = 0 to n-1, in parallel $\;\;\;\;\;$; n2 processors
$\;\;\;\;\;$ $\;\;\;\;\;$if A[i] < A[j]
$\;\;\;\;\;$ $\;\;\;\;\;$then m(i) = false $\;\;\;\;\;$ $\;\;\;\;\;$ $\;\;\;\;\;$ $\;\;\;\;\;$; CW
$\;\;\;\;\;$for i = 0 to n-1, in parallel
$\;\;\;\;\;$ $\;\;\;\;\;$if m(i) = true
$\;\;\;\;\;$ $\;\;\;\;\;$then max = A[i] $\;\;\;\;\;$ $\;\;\;\;\;$ $\;\;\;\;\;$ $\;\;\;\;\;$; CW
$\;\;\;\;\;$return max

Find Max of array containing 1, 2, 3, 4

Processor     Compares        m            max

   1            1, 1          false         4
   2            1, 2
   3            1, 3
   4            1, 4
   5            2, 1          false
   6            2, 2
   7            2, 3
   8            2, 4
   9            3, 1          false
  10            3, 2
  11            3, 3
  12            3, 4
  13            4, 1          true
  14            4, 2
  15            4, 3
  16            4, 4


next up previous
Next: Up: Previous: