Parallel Fx Library for .NET

coleslawokraSoftware and s/w Development

Dec 1, 2013 (3 years and 11 months ago)

124 views


1

/ 19 March 2008

Parallel Fx Library for .NET
3.5 & Multi
-
Core
Programming


Victor Stachura


2

/ 19 March 2008

Multi
-
Core Programming

The Man, The Myth, The Legend

Warning
!


3

/ 19 March 2008

Multi
-
Core Programming

A New Programming Model is Needed

Single Core

Multi
-
Core

Time

Performance


4

/ 19 March 2008

Multi
-
Core Programming

Inside a Multi
-
Core Processor

One
Processor

With multiple
execution Cores


5

/ 19 March 2008

Sequential


app

Task 1

Task 2

Task 3

Task 4

Execution Time

Sequential

app with

threads

Task 1

Task 1

Task 2

Core #2

Task 3

Core #1

Task 4

Core #1

Task 5

Core #2

Task 2

Task 3

Task 4

Parallel

programming

with 2 cores

Degree of Parallel Programming

Parallel Programming Makes a Difference


6

/ 19 March 2008

Multi
-
Core Programming

How is Microsoft Addressing this Problem?

PA

Parallel

Programming

101

16

1

Parallel Computing Initiative

The Manycore Shift Whitepaper


7

/ 19 March 2008

Multi
-
Core Programming

The Elements of Parallel Programming

PA

Parallel

Programming

101

16

1

Software you need:

Parallel Fx Library

(Dec 07 CTP)


Parallel Fx Concepts:

Declarative Data Parallelism

Imperative Data Parallelism*

Imperative Task Parallelism


Namespaces:

System.Linq

System.Linq.Parallel

System.Threading

System.Threading.Tasks


.NET Framework 3.5

VS 2008

General Concepts:

Problem Identification**


Threads

Thread Safety

Locking

Synchronization

Race Conditions

Deadlock



8

/ 19 March 2008

Multi
-
Core Programming

Project Sybil

PA

Parallel

Programming

101

16

1

So, does all this stuff work?


9

/ 19 March 2008

Multi
-
Core Programming

Code Sample: Parallel.For()

PA

Parallel

Programming

101

16

1

for (int i = 0; i < 10000000; i++)


DataArray[i] = Rand.Next();



stopWatch.Start();



for (int i = 0; i < 10000000; i++)


{


DataArray[i] = DataArray[i] / 3;


DataArray[i] = DataArray[i] * 6;


DataArray[i] = DataArray[i] / 3;


DataArray[i] = DataArray[i] * 5;


DataArray[i] = DataArray[i] / 3;


DataArray[i] *= DataArray[i];


DataArray[i] = DataArray[i] / 3;


DataArray[i] = DataArray[i] * 6;


DataArray[i] = DataArray[i] / 3;


DataArray[i] = DataArray[i] * 5;


DataArray[i] = DataArray[i] / 3;


DataArray[i] *= DataArray[i];


}



stopWatch.Stop();

for (int i = 0; i < 10000000; i++)


DataArray[i] = Rand.Next();



stopWatch.Start();




Parallel.For(0, 10000000, delegate(int i) {




DataArray[i] = DataArray[i] / 3;


DataArray[i] = DataArray[i] * 6;


DataArray[i] = DataArray[i] / 3;


DataArray[i] = DataArray[i] * 5;


DataArray[i] = DataArray[i] / 3;


DataArray[i] *= DataArray[i];


DataArray[i] = DataArray[i] / 3;


DataArray[i] = DataArray[i] * 6;


DataArray[i] = DataArray[i] / 3;


DataArray[i] = DataArray[i] * 5;


DataArray[i] = DataArray[i] / 3;


DataArray[i] *= DataArray[i];


});



stopWatch.Stop();


10

/ 19 March 2008

Multi
-
Core Programming

Shift Happens

PA

Parallel

Programming

101

16

1

Most applications running slow


Hardware unused


Applications must change


You must learn


You are responsible


11

/ 19 March 2008

Multi
-
Core Programming

Resources

PA

Parallel

Programming

101

16

1

MS Parallel Development Center


Manycore Whitepaper


Book:

"Multi
-
core programming
-

Increasing
Performance Through Software Multithreading"



Intel ‘Go Videos’


MSDN Article
: Optimized managed code for
multicore machines




12

/ 19 March 2008

The End