Reverse

A baby example of Parallel Divide and Conquer

On Mou
on Divide and Conquer

Let's watch reverse unroll in a Divacon computation/communication graph:

Reverse the input array
\(PDC(d_{lr},c_{lr},id,!other: \# ! corr, atom?, id)\)

Input   0     1     2     3     4     5     6     7   preadjust=id so keep dividing
\(d_{lr}\) 3x 0 1 2 3 4 5 6 7 stopped at atom?=true
# ! corr 0.1 1.0 2.3 3.2 4.5 5.4 6.7 7.6 communicated to+fro the corresponding element
! other 1 0 3 2 5 4 7 6 each picked "other"
next is \(c_{lr}\)
\(c_{lr}\)(#1) 1 0 3 2 5 4 7 6 next is (id,other) : # corr
send fwd to corr
# ! corr 1.3 0.2 3.1 2.0 5.7 4.6 7.5 6.4 sent each over to its corr
then drop self, keep other
! other 3 2 1 0 7 6 5 4 ready for \(c_{lr}\)
now \(c_{lr}\#2\) 3 2 1 0 7 6 5 4 now it's 4-arrays. Next
! other : # ! corr
# ! corr 3.7 2.6 1.5 0.4 7.3 6.2 5.1 4.0 n'th sent to, got from n'th
next is ! other
other(a,b)=b 7 6 5 4 3 2 1 0 next: \(c_{lr}\#3\)
\(c_{lr}\) (#3) yields an 8-array 7 6 5 4 3 2 1 0 all done

By this method, reverse takes log-N steps (here, three steps), each with a division, a combination, and a full set of parallel exchange-and-select-other operations between corresponding elements between pairs of 1-arrays, 2 arrays, and 4 arrays.

Notice that from each position there is a communication once in each of log-N directions. The remarkable characteristic of this communication pattern, expressed in the term "lockstep", is that an entire half of the set of all positions communicates with a second entire half of the set, all in one timestep. The whole marching band takes one step in one direction at once.

Conveniently you can cut the whole set into halves 3 different orthogonal ways, like into 8 1-arrays, 4 2-arrays, and 2 4-arrays.

Talk between halves that are cut up this way, then that way, then the other way, you're done. Is that a miracle?

I think it's a miracle. I can't see it at all, then it seems perfectly obvious, then I can't see it again. At all. So go through the steps of the unrolled computation graph, and see if any part isn't perfectly obvious. Then have a cup of tea, and begin to accept it, and soon, very soon, try some more examples, and maybe some exercises, and try to do some for yourself.

Your thoughts?
(will not be shared or abused)
Comment:
                                          Feedback is welcome.
Copyright © 2025 Thomas C. Veatch. All rights reserved.
Created: May 4, 2025