Download presentation
Presentation is loading. Please wait.
Published byAmice Gaines Modified over 9 years ago
1
1 Cilk Chao Huang CS498LVK
2
2 Introduction A multithreaded parallel programming language Effective for exploiting dynamic, asynchronous parallelism (Chess games) Developed by the Supercomputing Technologies Group under Prof. Charles E. Leiserson at MIT
3
3 Cilk Keywords spawn : indicates the procedure can operate in parallel with other code; the scheduler decides whether to execute it on a new thread or not sync : indicates that the current procedure cannot proceed until all previous spawned procedures have completed and returned C elision of a Cilk program is a valid C program
4
4 Example (1) cilk int fib (int n) { if (n < 2) return n; else { int x, y; x = spawn fib (n-1); y = spawn fib (n-2); sync; return (x+y); }
5
5 Cilk Keywords inlet : identifies a function inside the procedure as an inlet An inlet is a C function internal to a Cilk procedure which handles the returned results of a spawned procedure call Allows more complex way of handling return value in the parent’s frame
6
6 Example (2) cilk int fib (int n) { int x = 0; inlet void sum (int result) { x += result; return; } if (n<2) return n; else { sum(spawn fib (n-1)); sum(spawn fib (n-2)); sync; return (x); }
7
7 Example (3) cilk int fib (int n) { int x = 0; if (n<2) return n; else { /* implicit inlets */ x += spawn fib (n-1); x += spawn fib (n-2); sync; return (x); }
8
8 Cilk Keywords abort : indicates that other procedures that have been spawned off by the parent procedure can be safely aborted Useful in speculative work such as space searching
9
9 Cilk Keywords cilk void baz(int n); cilk void foo(int n) { inlet void bar() { abort; } bar(spawn baz(17)); spawn baz(28); sync; }
10
10 Implementation Scheduling scheme: work-stealing Ready procedures are put on a double-ended queue The processor restores suspended procedures from the end of the deque they have been stored Underloaded processors steal work from other processors’ queues at the other end of the deque
11
11 Important Applications Parallel chess programs Cilkchess *Socrates Parallel gomoku
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.