33
Shallow Dive: Parallel Fx Alex Moore Software Developer, TDCI

Shallow Dive PFX

Embed Size (px)

DESCRIPTION

This is my 10 minute introduction to The Parallel Extensions to the .Net Framework that I presented at the Central Ohio .Net User Group lightning talk meeting. If you have any questions just DM me at twitter.

Citation preview

Page 1: Shallow Dive PFX

Shallow Dive: Parallel Fx

Alex MooreSoftware Developer, TDCI

Page 2: Shallow Dive PFX

No More Free Lunch

Processors not getting much faster

Page 3: Shallow Dive PFX

No More Free Lunch

transistors++

Page 4: Shallow Dive PFX

No More Free Lunch

transistors++ speed++

Page 5: Shallow Dive PFX

No More Free Lunch

transistors++ speed++

Page 6: Shallow Dive PFX

No More Free Lunch

transistors++ speed++

cores++

Page 7: Shallow Dive PFX

Elephant in the Room

Page 8: Shallow Dive PFX

Elephant in the Room

Parallel / Concurrent Programming is about to reach it’s boiling point

Page 9: Shallow Dive PFX

Elephant in the Room

Can’t ignore it much longer

Page 10: Shallow Dive PFX

Elephant in the Room

There will be language, library, and tool support for this soon.

There will be language, library, tool, and hardware support for this soon.Concurrency is one of the main themes for C# 4.0, the PFX will probably be part of .Net 4.0, Visual Studio 2010 will have tools to help better debug concurrent programs, and Intel’s next Core processor, the i7, will have a whole slew of improvements to help run concurrent and threaded applications better.

Page 11: Shallow Dive PFX

Parallel Extensions to the .Net Framework

PLINQ

Task Parallel Library

Scheduler

System.Threading

CDS

Page 12: Shallow Dive PFX

How to Express Parallelism

Page 13: Shallow Dive PFX

How to Express Parallelism

Threading sucks

Page 14: Shallow Dive PFX

How to Express Parallelism

Declarative data parallelism - PLINQ

Page 15: Shallow Dive PFX

How to Express Parallelism

Declarative data parallelism - PLINQ

Imperative data parallelism - Parallel.For

Page 16: Shallow Dive PFX

How to Express Parallelism

Declarative data parallelism - PLINQ

Imperative data parallelism - Parallel.For

Imperative task parallelism - Tasks, Futures

Page 17: Shallow Dive PFX

PLINQ

from x in setwhere x == somevalueselect expensiveFunction(x);

Page 18: Shallow Dive PFX

PLINQ

from x in setwhere x == somevalueselect expensiveFunction(x);

from x in set.AsParallel()where x == somevalueselect expensiveFunction(x);

Page 19: Shallow Dive PFX

Parallel.For

for( int i = 0; i < 10; i++ ){ ... }

Page 20: Shallow Dive PFX

Parallel.For

for( int i = 0; i < 10; i++ ){ ... }

Parallel.For( 0, 10, i => { ... } );

Page 21: Shallow Dive PFX

Parallel.ForEach

foreach( var x in set ) { ... }

Page 22: Shallow Dive PFX

Parallel.ForEach

foreach( var x in set ) { ... }

Parallel.ForEach( set, x => {...});

Page 23: Shallow Dive PFX

Tasks

A();B();C();

Do_Something();

Page 24: Shallow Dive PFX

Tasks

Task t1 = Task.Create( ()=> A(); );Task t2 = Task.Create( ()=> B(); );Task t3 = Task.Create( ()=> C(); );

Task.WaitAll(t1, t2, t3);

Do_Something();

Page 25: Shallow Dive PFX

Futures

var a = A();var b = B();var c = C();

Do_Something(a,b,c);

Page 26: Shallow Dive PFX

Futures

var a = Future.Create( ()=> A(); );var b = Future.Create( ()=> B(); );var c = Future.Create( ()=> C(); );

Do_Something(a,b,c);

Page 27: Shallow Dive PFX

Demos

Page 28: Shallow Dive PFX

Box of Sharp Knives

PFX is a big box of sharp knives. Yes they are shiny and you want to grab them but be careful.

Page 29: Shallow Dive PFX

Box of Sharp Knives

★Not a silver bullet for performance

This should not be your first choice for improving performance. Clean “responsible” design will go a long way when optimizing code, and will help when deciding where to apply concurrency.

Page 30: Shallow Dive PFX

Box of Sharp Knives

★Not a silver bullet for performance

✓Get the CTP

✓Read, Do, and Learn

This should not be your first choice for improving performance. Clean “responsible” design will go a long way when optimizing code, and will help when deciding where to apply concurrency.

Page 31: Shallow Dive PFX

Questions?Comments ?

Are there any questions ? Comments ?

Page 33: Shallow Dive PFX

Thanks!

Alex Moore

Blog: geekswithblogs.net/alexmoore

Twitter: @alexmoore