



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




ECE497MF Multithreaded Computer Architecture March 08, 2004
Lecturer: Matt Frank Scribe: Joseph Grzywacz
The main topic for this lecture is trying to bring together two topics weāve previ- ously been talking about: 1) Functional Programming, and 2) Lots of Concurrency. We begin by looking at two models of dataflow: Static Dataflow Model: Here we look at how people build concurrent circuits, and look at the mapping these techniques to programming. Dynamic Dataflow Model: This is a way of thinking about simultaneous com- putation, and then building a machine to realize it. These notions were introduced by Jack Dennis, a functional language aficionado for two main reasons: 1) Abstract features (hashes, sets, trees, etc...) were included in the functional languages before most other languages, and 2) It is typically eas- ier to design a large program where there is no need to worry about side-effects. These ideas follow from standard circuit design practice as well. As we see in these āstandardā figures comparing combinational and sequential design circuits, sequential logic has a transition function that helps the machine state progress to the next state in addition to the base combinational logic required to produce the circuitās outputs. While at first glance this appears more complicated, in reality, this separation of the logic generating the circuitās outputs and the circuitry com- puting future state makes designing the sequential circuit conceptually simpler.
input CombinationalLogic output input TransitionFunction
State
sā
output
s
Figure 1 : Combinational and Sequential Logic
This is similar to functional programming, where the programmer can write code and not have to worry about any side-effects (or āstate-changesā) that may result from the current task being performed. Ideally, this means faster program- ming with less bugs. Parallel programming would also benefit from this design philosophy. As we saw in previous lectures, changing a program into a parallel
one required many careful steps to ensure that all changes respected any side- effects that a sequence of code may have had. If instead no state was changing, these transformations would be much easier to perform.
map a; for i = 1 to n a = a.insert( key[i], data[i] );
For the above code sequence, we cannot immediately determine if this code can be parallelized, even though at first glance it seems it can. For instance, if two keys in the key array are the same, then they must be inserted such that the second in- sertion overwrites the first one. However, depending on the map implementation we may still be able to find concurrency in situations similar to this one. Below we present two ways to implement a map (but weāll only show the in- sert() and lookup() functionality here.)
insert( key, data ) h = hash( key ); hashTable[ h ] = < key, data >;
lookup( key ) h = hash( key ); return hashTable[ h ];
For this case, we see that insertions into the table will modify that table, so we have output dependencies that require us to do insertions in the correct order. Not terribly much can be done here, so we move on to the next data structure format.
insert( map, key, data )
Now, the insert function will accept a map to insert into, as well as return a new map with the new <key, data> pair inserted into it. Clearly only a small portion of the tree will be changed by the insertion, so we must optimize our implementation to be more intelligent than simply copying the entire tree (wasting both time and space.) What we end up doing is never modifying the original map, and simply mak- ing copies of the portions that must be āchangedā such that the new map we are creating is still correct. This requires a logarithmic amount of copying for this par- ticular data structure. Essentially we are simply doing renaming on portions of the tree. For the above example, the original tree structure is pointed to by root1. When we wish to insert 16 into this tree, we declare a new root called root2. This
The big win here is the idea that āIā can give away my map to someone else and continue using my map. Whomever I handed my map to can do whatever they like with it and I cannot be affected by their changes. If I would like to be affected by their changes, then I would simply ask for some type of return value from them after they have finished their work and before I continue on with mine. And since nothing is ever being modified, all this can go on in parallel.
Since a functional program can be represented as a tree, the result of a functional program can be thought of as doing succesive transformations on that tree. Given a set of concrete rules for operating on a node in a tree, work may proceed on any portion of that tree given it obeys the concrete rules. For example, given the equation (( 8 + 7 ) ā ( 6 ā 5 ))/(( 4 ā 3 ) + ( 2 + 1 )), we have the following parse tree:
/
8 7 6 5 4 3 2 1
Figure 4 : Parse Tree for ((8+7)-(65))/((43)+(2+1))
The tree may be evaluated in any order, as long as the rules are followed. Here, the only rule is the if a nodeās two children have already been calculated, then that node may calculate its result (and collapse the tree). This follows naturally from our intuition; clearly the subexpression 8 + 7 can be calculated at the onset, but not the ā/ā²^ because its two children have not yet been evaluated. Now, letās add the if-then-else construct to the arithmetic tree. We first repre- sent the IfThenElse construct in a functional programming manner as IfThenElse (test, expr1, expr2). The rule for evaluating this node is: If test is true, return evaluation(expr1), else return evaluation(expr2). An example parse tree is shown below.
Figure 5 : Parse Tree Including an If-Then-Else Statement
Recursion can be handled as well, be simply unfolding the tree as you go. This is best described with an example.
int myFunc(int a, int b) return ifthenelse((a <= 0), b, myFunc(a-1, b*b));
Given the above function declaration, a sample tree expansion is shown below for an initial call to myFunc() where a = 2 and b = 3 :
myFunc(2, 3) ifthenelse(2 <= 0, 2, myFunc(2-1, 33)) ifthenelse(false, 2, myFunc(2-1, 33)) myFunc(2-1, 33) ifthenelse(2-1 <= 0, 3 * 3, myFunc((2-1)-1, (33)(33))) ifthenelse(1 <= 0, 9, myFunc(0, 81)) ...
In the last shown step, we finally evaluate small portions of the tree, making it