task parallel library data flows

15
Developer Conference 2011 MICROSOFT USER GROUP KOLKATA

Upload: sankarsan-bose

Post on 03-Jul-2015

2.450 views

Category:

Technology


2 download

TRANSCRIPT

Page 1: Task Parallel Library Data Flows

Developer Conference 2011MICROSOFT USER GROUP KOLKATA

Page 2: Task Parallel Library Data Flows

TPL

Task Parallel Library^– Data Flow

Tasks Sankarsan Bose

12th November , 2011

Page 3: Task Parallel Library Data Flows

Parallel Programming in .NET 4.0

Threads

Data Flow Tasks

Coordination Data Structure

Task Parallel Library

Till .NET 3.5 to takeCare of concurrencyrequirements

.NET 4.5 Preview 1

Parallel Programming As It Evolves

- Earlier DevLabs

- CTP

- Higher level constructs to handle pipeline scenarios

Page 4: Task Parallel Library Data Flows

Pipelines And Data Flow Networks

- A linear series of producer/consumer stages

- Output of one stage -> Input of another

- Stages of pipeline are supposed to process input in

specified order

- Data Flow networks are more general form of

pipelines

Stage1 Stage 2 Stage NInput Output

Page 5: Task Parallel Library Data Flows

Image Pipeline – An Example

Load Image

Scale Image

Filter Image

Display Image

Input Image

Original Image s

Filtered ImagesThumbnails

This is sequential… How it makes sense in Parallel

World???

Page 6: Task Parallel Library Data Flows

Image Pipeline – An Example (Contd..)

Load

Scale

Filter

Image1

Display

Image1

Image1

Image1

Image2

Image2

Image2

Image2

Image3 Image4

t0 t1 t2 t3 t4 t5 t6 t7

Image3

Image3

Image3

Image4

Image4

Image4

Image5

Image5

Image5

Image5

Page 7: Task Parallel Library Data Flows

What type of tasks Stages Can Do?

- Receive an input and process it.

- Receive an input, buffer it and send it to another

stage

- Receive an input, transform the input and send the

output to another stage

- Receive input from multiple stages and join/combine

the inputs to produce the output

Page 8: Task Parallel Library Data Flows

TPL DataFlow Blocks

- Stages should be able

- Handle input

- Produce output

- Buffer data

- Perform Processing

- Stages are modeled as Data Flow Blocks

- Data Flow Blocks can be

- Source Block – Generate data

- Target Block - Accept data

IDataFlowBlock

ISourceBlock ITargetBlock

Page 9: Task Parallel Library Data Flows

TPL DataFlow Blocks(Contd..)

- Built-In Data Flow Blocks

- Buffering Blocks

- BufferedBlock- BroadCastBlock

- Executor Blocks

- ActionBlock- TransformBlock- TransformManyBlock

- Join Blocks

- JoinBlock- BatchBlock

Let’s Go To The Code….

Page 10: Task Parallel Library Data Flows

Built In Data Flow Blocks

ActionBlock

Task

Input

BufferBlock

TaskInput Original

BroadcastBlock

TaskInput

Copy

Copy

Copy

TransformBlock

Task

InputOutput

JoinBlock

Task

Input

1Input

2

Output

Page 11: Task Parallel Library Data Flows

Image Processing Program

Image Processing Program…Let’s Build a

Skeletal Code

Page 12: Task Parallel Library Data Flows

References

- Parallel Programming with Microsoft Visual C++ by

Colin Campbell and Ade Miller

- Patterns Of Parallel Programming by Stephen Toub

- Introduction To TPL DataFlow by Stepehen Toub

- Samples in http://parallelpatterns.codeplex.com/

Page 13: Task Parallel Library Data Flows

Thanks Everybody, For Your

Time.Happy Coding…..Enjoy Learning..

Page 14: Task Parallel Library Data Flows

Speaker Details/Contact

- http://twitter.com/sankarsan

- http://sankarsan.wordpress.com

- http://codingndesign.com

- http://sankarsanbose.com