Unformatted text preview: ci number in serial execution as it will be more efficient considering the parallel execution overhead. The run method recursively decompose the task by creating new tasks and execute them in parallel by invoking the fork method on each created task. The fork method is defined in Task class shown in Figure 11 and note that it is a part of the distributed queue package shown in Figure 12. The package is a much simplified version of the FJTask package , which uses ideas from . The fork method put the caller task into the task queue of its associated thread. Thread‐
pool has been created in main before Fibonacci number computation is executed (Figure 7). A thread goes over the loop shown in Figure 9 until it receives an ending signal (poison task). In the loop, the thread takes a task from its own task queue and, if it is empty it tries to steal one from the other thread’s task queue. The steal method of a TaskRunner class which extends class Thread is shown in Figure 10. Figure 7. A program that computes Fibonacci number Figure 8. Fib ojbect recursively decomposes the task and forks the sub‐tasks Figure 9. A threads' main loop execut...
View Full Document
- Fall '12