130 likes | 370 Views
Cilk. Chao Huang CS498LVK. 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. Cilk Keywords.
E N D
Cilk Chao Huang CS498LVK
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
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
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); } }
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
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); } }
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); } }
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
Cilk Keywords cilk void baz(int n); cilk void foo(int n) { inlet void bar() { abort; } bar(spawn baz(17)); spawn baz(28); sync; }
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
Important Applications • Parallel chess programs • Cilkchess • *Socrates • Parallel gomoku