Computing a Fibonacci numberThis tutorial shows you how to create a distributed version of the classic doubly recursive Fibonacci number computation using Jicos. Although this computation is not inherently interesting, it is an extremely light-weight example of a recursive computation that can be done in parallel usng Jicos. Due to its small computational load, this computation stresses any asynchronous parallel computing system because of the large amount of synchronization it requires: It is a computation that is essentially all overhead. Most importantly, it is a simple computation, allowing us to focus on the Jicos API.
Before we dive into the Jicos aspects of the problem, let's review this simple computation. We can define the nth Fibonacci number recursively as follows:
To render the task dag as a parallel program in Jicos, we first identify the tasks that we want done in parallel. In this example, we identify each node of the dag above with a task. Any 2 tasks that do not lie on the same directed path can, in principle, be done in parallel. We could create 3 kinds of tasks: a decompose task, a base computation task, and a compose task. In this example, we use only 2 task types: F and AddInteger. The F task incorporates both the decompose and base tasks. Looking at the task graph above, we see that the F task takes 1 input, input, and either creates 3 subtasks xor computes 1 output (only if it is a base computation). AddInteger returns the sum of its inputs.
The ClassesNow, let's look at actual Java classes. An explanation of the class definition follows.
ApplicationAfter registration is complete, the application:
AddIntegerThis is a Task that is part of the jicos.services.tasks package that is included in the Jicos download. Its execute method simply returns the sum of its inputs. In this application, there always are 2 inputs.
These 3 classes, Application, F, and AddInteger are all that we need.
The output should look like this:
F( 5 ) = 8
where 5 is an example of what you specified as args, and 8 is its Fibonacci number.