Docsity

Dynamic Multithreading and Matrix Multiplication using Cilk, Slides of Assembly Language Programming

Partial preview of the text

Download Dynamic Multithreading and Matrix Multiplication using Cilk and more Slides Assembly Language Programming in PDF only on Docsity!

Dr. Bradley Kuszmaul, MIT.

6.189 IAP 2007 MIT

6.189 IAP 2007

Lecture 15

Cilk

Design and Analysis of

Dynamic Multithreaded

Algorithms

Bradley C. Kuszmaul MIT Computer Science and Artificial Intelligence Laboratory

A C language for dynamic multithreading with a provably good runtime system.

Cilk

Platforms

  • Sun UltraSPARC Enterprise
  • SGI Origin 2000
  • Compaq/Digital Alphaserver
  • Intel Pentium SMP’s

Applications

  • virus shell assembly
  • graphics rendering
  • n body simulation Socrates and Cilkchess Cilk automatically manages low level aspects of parallel execution, including protocols, load balancing, and scheduling.

Fibonacci int fib (int n) {if (n<2) return (n); else {int x,y; x = fib(n-1);y = fib(n-2); } return (x+y); } C elision

cilk int fib (int n) { cilkif (n<2) return (n); else {int x,y; x =y = spawn fib(n-1);spawn fib(n-2);spawnspawn sync;return (x+y);sync; } }

Cilk code

Cilk is a faithfulfaithful extension of C. A Cilk program’s serial elision serial elision is always a legal implementation of Cilk semantics. Cilk provides nono new data types.

Cactus Stack

B

A

C

D E

A A

B

A

C

A

C

D

A

C

E

Views of stack

A B C D E

Cilk supports C’s rule for pointers: A pointer to stack space can be passed from parent to child, but not from child to parent. (Cilk also supports malloc .)

Cilk’s cactus stack supports several views in parallel.

Advanced Features

  • Returned values can be incorporated into the parent frame using a delayed internal function called an

inlet:

  • Within an inlet, the other children of the parent frame to be terminated.^ abort^ keyword causes all
  • The sync^ SYNCHED would succeed.^ pseudovariable tests whether a
  • A Cilk library provides^ mutex locks^ for atomicity.

int y;inlet void foo (int x) { } if (x > y) y = x; …spawn foo(bar(z));

Outline

  • Theory and

Practice•A Chess

Lesson•Fun with Algorithms

  • Work Stealing
  • Opinion &

Conclusion

Algorithmic Complexity TP = execution time on Measures P processors

Algorithmic Complexity TP = execution time on Measures P processors

T 1 = workwork T∞ = critical pathcritical path

Algorithmic Complexity TP = execution time on Measures P processors

• TP ≥^ T 1 /P

• TP ≥^ T∞

Lower Bounds

T 1 = workwork T∞ = critical pathcritical path

Greedy Scheduling

Theorem [Graham & Brent]: There exists an execution with TP ≤ T 1 /P + T∞.

Greedy Scheduling

Theorem [Graham & Brent]: There exists an execution with TP ≤ T 1 /P + T∞. Proof. At each time step, …

P = 3

Greedy Scheduling

Theorem [Graham & Brent]: There exists an execution with TP ≤ T 1 /P + T∞. Proof. At each time step, if at least P tasks are ready, execute P of them.

P = 3

Greedy Scheduling

Theorem [Graham & Brent]: There exists an execution with TP ≤ T 1 /P + T∞.

If fewer than P tasks are ready, …

Proof. At each time step, if at least P tasks are ready, execute P of them.

P = 3