{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

dyn_multi_alg - Introduction to Algorithms Massachusetts...

Info icon This 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
Image of page 1

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

View Full Document Right 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.
Image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern