Overview and system design CX documentation and sample code Publications People How to contact us
[CX tutorial]
Step 0: Overview - defining the problem
Let's assume that we want to make a program that would evaluate the Fibonacci function, which is defined as follows:

Fib(x)=Fib(x-1)+Fib(x-2), if x>1
Fib(x)=x, if x=0,1

What makes this problem a good candidate for our purposes, is that the decomposition of the problem into smaller problems, as well as the composition of the intermediate results, is quite clear. Let's say for instance that we want to evaluate Fib(3). This would give the following graph of decomposition and composition steps:

                          

Figure 1 - the task graph for fib(3)


Since Fib(3)=Fib(2)+Fib(1), in order to evaluate Fib(3) we will need:
a) To evaluate Fib(2), Fib(1)
b) To combine their results (in our case, we simply add them)

If we think in tasks, this implies that the Fib(3) will create (or spawn) three new tasks:
a) Fib(2), which again will spawn three new tasks (Fib(1),Fib(0) and Combine(1,0) which basically means "combine the results of fib(1) and fib(2)")
b) Fib(1), which will not create new tasks, since 1 is no further decomposed according to the definition of Fibonacci function.
c) Combine(results of Fib(2),results of Fib(1)), which will perform a simple addition of those results. In other cases, this task of "compose" type may involve more sophisticated operations.

Now, let's look  more closely on each of these two tasks.

The decompose task
Fib(num) has always a single input argument, the number for which the Fibonacci function we want to evaluate. The output of this task can be either three news tasks (similar to those that we described above) when num>1, or a single output argument that will either the final result, or an intermediate results that must be forwarded to the proper compose task (for instance, that output of Fib(0) should be forwarder to Combine(1,0) task)

The compose task
After decomposing one task to many others of smaller size, most of the times it makes sense to compose their results in a meaningful way. This is responsibility of the composition task, which in our case, takes two input arguments (fib(num-1) and fib(num-2)) and gives as an output argument the addition of those two results (since fib(num)=fib(num-1)+fib(num-2)). This result can be final (so it must be forwarded to the consumer), or intermediate (so it must be forwarded to another compose task)

From implementation point of view, theses tasks use the same API and extend the same superclass. Their distinction is only based on their functionality. In the following steps, we discuss how one can implement them using the CX API.



For questions and comments about CX project:cappelo@cs.ucsb.edu 
For questions and comments about this site:mourlouk@cs.ucsb.com
site last updated: 01/09/2000.