| CSE 160, Fall 2006 |
Department of Computer Science and Engineering |
|
Homework #1
Due Tuesday 10/3/2006 in class
[10 points]
forall i = 0 to N do
y[p[i]] = y[i]
end do
After running the code, we discover that some elements
are incorrect. What restriction on p[ ] is
required in order to ensure correctness?
for i = N-1 to 1 by -1 do
for j = 0 to i-1 do
Compare-exchange(a[j] , a[j+1])
end do
end do
where Compare-exchange(x,y) will swap the contents
of x and y if x > y, and
the by -1 construct steps backwards through the array.
To parallelize this sort algorithm, we are tempted to introduce a forall into the inner loop nest.
forall j = 0 to i-1 do
Compare-exchange(a[j] , a[j+1])
end do
forall j = 0 to i-1 by 2 do