dyn_multi_alg - Introduction to Algorithms Massachusetts...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Introduction to Algorithms December 5, 2005 Massachusetts Institute of Technology 6.046J/18.410J Professors Erik D. Demaine and Charles E. Leiserson Handout 29 A Minicourse on Dynamic Multithreaded Algorithms Charles E. Leiserson MIT Computer Science and Artificial Intelligence Laboratory Cambridge, Massachusetts 02139, USA December 5, 2005 Abstract This tutorial teaches dynamic multithreaded algorithms using a Cilk-like [11, 8, 10] model. The material was taught in the MIT undergraduate class 6.046 Introduction to Algorithms as two 80-minute lectures. The style of the lecture notes follows that of the textbook by Cormen, Leiserson, Rivest, and Stein [7], but the pseudocode from that textbook has been “Cilkified” to allow it to describe multithreaded algorithms. The first lecture teaches the basics behind multithreading, including defining the measures of work and critical-path length. It culminates in the greedy scheduling theorem due to Graham and Brent [9, 6]. The second lecture shows how parallel applications, including matrix multiplication and sorting, can be analyzed using divide-and-conquer recurrences. 1 Dynamic multithreaded programming As multiprocessor systems have become increasingly available, interest has grown in parallel pro- gramming. Multithreaded programming is a programming paradigm in which a single program is broken into multiple threads of control which interact to solve a single problem. These notes provide an introduction to the analysis of “dynamic” multithreaded algorithms, where threads can be created and destroyed as easily as an ordinary subroutine can be called and return. 1.1 Model Our model of dynamic multithreaded computation is based on the procedure abstraction found in virtually any programming language. As an example, the procedure F IB gives a multithreaded algorithm for computing the Fibonacci numbers: 1 Support was provided in part by the Defense Advanced Research Projects Agency (DARPA) under Grant F30602- 97-1-0270, by the National Science Foundation under Grants EIA-9975036 and ACI-0324974, and by the Singapore- MIT Alliance. 1 This algorithm is a terrible way to compute Fibonacci numbers, since it runs in exponential time when logarithmic methods are known [7, pp. 902–903], but it serves as a good didactic example. 2
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Handout 29: Dynamic Multithreaded Algorithms 3 F IB ( n ) 1 if n < 2 2 then return n 3 x spawn F IB ( n 1) 4 y spawn F IB ( n 2) 5 sync 6 return ( x + y ) A spawn is the parallel analog of an ordinary subroutine call. The keyword spawn before the subroutine call in line 3 indicates that the subprocedure F IB ( n 1) can execute in parallel with the procedure F IB ( n ) itself. Unlike an ordinary function call, however, where the parent is not resumed until after its child returns, in the case of a spawn, the parent can continue to execute in parallel with the child. In this case, the parent goes on to spawn F IB ( n 2) . In general, the parent can continue to spawn off children, producing a high degree of parallelism.
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 04/12/2011 for the course MATH 6.046J taught by Professor Demaine during the Fall '10 term at MIT.

Page1 / 13

dyn_multi_alg - Introduction to Algorithms Massachusetts...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online