Cilk: an Efficient Multithreaded Runtime System

Cilk: an Efficient Multithreaded Runtime System

Cilk: An Ef®cient Multithreaded Runtime System Robert D. Blumofe Christopher F. Joerg Bradley C. Kuszmaul Charles E. Leiserson Keith H. Randall Yuli Zhou MIT Laboratory for Computer Science 545 Technology Square Cambridge, MA 02139 Abstract level 0 Cilk (pronounced ªsilkº) is a C-based runtime system for multi- threaded parallel programming. In this paper, we document the ef®- level 1 ciency of the Cilk work-stealing scheduler, both empirically and ana- lytically. We show that on real and synthetic applications, the ªworkº and ªcritical pathº of a Cilk computation can be used to accurately level 2 model performance. Consequently, a Cilk programmer can focus on reducing the work and critical path of his computation, insulated from load balancing and other runtime scheduling issues. We also prove level 3 that for the class of ªfully strictº (well-structured) programs, the Cilk scheduler achieves space, time, and communication bounds all within Figure : The Cilk model of multithreaded computation. Threads are a constant factor of optimal. shown as circles, which are grouped into procedures. Each downward edge The Cilk runtime system currently runs on the Connection Ma- corresponds to a spawn of a child, each horizontal edge corresponds to a spawn chine CM5 MPP, the Intel Paragon MPP, the Silicon Graphics Power of a successor, and each upward, curved edge corresponds to a data dependency. Challenge SMP, and the MIT Phish network of workstations. Ap- The numbers in the ®gure indicate the levels of procedures in the spawn tree. plications written in Cilk include protein folding, graphic rendering, backtrack search, and the Socrates chess program, which won third prize in the 1994 ACM International Computer Chess Championship. procedures, each of which is broken into a sequence of threads, which form the vertices of the dag. Each thread is a nonblocking C func- tion, which means that it can run to completion without waiting or Intro duction suspending once it has been invoked. As one of the threads from a Cilk procedure runs, it can spawn a child thread which begins a new Multithreading has become an increasingly popular way to implement child procedure. In the ®gure, downward edges connect threads and dynamic, highly asynchronous, concurrent programs [1, 8, 9, 10, 11, their procedures with the children they have spawned. A spawn is 12, 15, 19, 21, 22, 24, 25, 28, 33, 34, 36, 39, 40]. A multithreaded sys- like a subroutine call, except that the calling thread may execute con- tem provides the programmer with a means to create, synchronize, and currently with its child, possibly spawning additional children. Since schedule threads. Although the schedulers in many of these runtime threads cannot block in the Cilk model, a thread cannot spawn chil- systems seem to perform well in practice, none provide users with a dren and then wait for values to be returned. Rather, the thread must guarantee of application performance. Cilk is a runtime system whose additionally spawn a successor thread to receive the children's return work-stealing scheduler is ef®cient in theory as well as in practice. values when they are produced. A thread and its successors are con- Moreover, it gives the user an algorithmic model of application per- sidered to be parts of the same Cilk procedure. In the ®gure, sequences formance based on the measures of ªworkº and ªcritical pathº which of successor threads that form Cilk procedures are connected by hori- can be used to predict the runtime of a Cilk program accurately. zontal edges. Return values, and other values sent from one thread to A Cilk multithreaded computation can be viewed as a directed another, induce data dependencies among the threads, where a thread acyclic graph (dag) that unfolds dynamically, as is shown schemat- receiving a value cannot begin until another thread sends the value. ically in Figure 1. A Cilk program consists of a collection of Cilk Data dependencies are shown as upward, curved edges in the ®gure. This researchwas supported in part by the Advanced Research Projects Agency under Thus, a Cilk computation unfolds as a spawn tree composed of proce- Grants N00014-94-1-0985 and N00014-92-J-1310. Robert Blumofe is supported in part by dures and the spawn edges that connect them to their children, but the an ARPA High-Performance Computing Graduate Fellowship. Keith Randall is supported execution is constrained to follow the precedence relation determined in part by a Department of Defense NDSEG Fellowship. To appear in the Proceedings of the Fifth ACM SIGPLAN Symposium on Prin- by the dag of threads. ciples and Practice of Parallel Programming (PPoPP '95), Santa Barbara Califor- The execution time of any Cilk program on a parallel computer ftp://ftp.lcs.mit.edu nia, July 19±21, 1995. Also available on the web as with P processors is constrained by two parameters of the computa- /pub/cilk/PPoPP95.ps.Z. T tion: the work and the critical path. The work, denoted 1 , is the time used by a one-processor execution of the program, which cor- responds to the sum of the execution times of all the threads. The T critical path length, denoted 1 , is the total amount of time required by an in®nite-processor execution, which corresponds to the largest sum of thread execution times along any path. With P processors, the T P T 1 execution time cannot be less than 1 or less than . The Cilk waiting closure code scheduler uses ªwork stealingº [3, 7, 13, 14, 15, 19, 27, 28, 29, 34, 40] to achieve execution time very near to the sum of these two measures. x: T1 Off-line techniques for computing such ef®cient schedules have been 1 known for a long time [5, 16, 17], but this ef®ciency has been dif®cult 17 to achieve on-line in a distributed environment while simultaneously join using small amounts of space and communication. counters We demonstrate the ef®ciency of the Cilk scheduler both empir- 6 arguments ically and analytically. Empirically, we have been able to document that Cilk works well for dynamic, asynchronous, tree-like, MIMD- style computations. To date, the applications we have programmed y: T2 include protein folding, graphic rendering, backtrack search, and the 0 Socrates chess program, which won third prize in the 1994 ACM International Computer Chess Championship. Many of these applica- 42 tions pose problems for more traditional parallel environments, such x:1 as message passing [38] and data parallel [2, 20], because of the unpre- dictability of the dynamic workloads on processors. Analytically, we ready closure prove that for ªfully strictº (well-structured) programs, Cilk's work- stealing scheduler achieves execution space, time, and communication Figure : The closure data structure. bounds all within a constant factor of optimal. To date, all of the ap- plications that we have coded are fully strict. The Cilk language is an extension to C that provides an abstraction is essentially a global reference to an empty argument slot of a closure, of threads in explicit continuation-passing style. A Cilk program is implemented as a compound data structure containing a pointer to a preprocessed to C and then linked with a runtime library to run on the closure and an offset that designates one of the closure's argument Connection Machine CM5 MPP, the Intel Paragon MPP, the Silicon slots. Continuations can be created and passed among threads, which Graphics Power Challenge SMP, or the MIT Phish [4] network of enables threads to communicate and synchronize with each other. workstations. In this paper, we focus on the Connection Machine Continuations are typed with the C data type of the slot in the closure. CM5 implementation of Cilk. The Cilk scheduler on the CM5 is At runtime, a thread can spawn a child thread by creating a closure written in about 30 pages of C, and it performs communication among for the child. Spawning is speci®ed in the Cilk language as follows: processors using the Strata [6] active-message library. The remainder of this paper is organized as follows. Section 2 spawn T (args ) describes Cilk's runtime data structures and the C language extensions This statement creates a child closure, ®lls in all available arguments, that are used for programming. Section 3 describes the work-stealing and initializes the join counter to the number of missing arguments. scheduler. Section 4 documents the performance of several Cilk ap- Available arguments are speci®ed as in C. To specify a missing argu- plications. Section 5 shows how the work and critical path of a Cilk ment, the user speci®es a continuation variable (type cont) preceded computation can be used to model performance. Section 6 shows ana- by a question mark. For example, if the second argument is ?k, then lytically that the scheduler works well. Finally, Section 7 offers some Cilk sets the variable k to a continuation that refers to the second argu- concluding remarks and describes our plans for the future. ment slot of the created closure. If the closure is ready, that is, it has no missing arguments, then spawn causes the closure to be immediately The Cilk programming environment and implementa posted to the scheduler for execution. In typical applications, child tion closures are usually created with no missing arguments. To create a successor thread, a thread executes the following state- In this section we describe a C language extension that we have de- ment: veloped to ease the task of coding Cilk programs. We also explain the basic runtime data structures that Cilk uses. spawn next T (args ) In the Cilk language, a thread T is de®ned in a manner similar to a C function de®nition: This statement is semantically identical to spawn, but it informs the scheduler that the new closure should be treated as a successor, f g thread T (arg-decls ) stmts as opposed to a child.

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    11 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us