Parallel extensions
This presentation is the property of its rightful owner.
Sponsored Links
1 / 14

Parallel Extensions PowerPoint PPT Presentation


  • 68 Views
  • Uploaded on
  • Presentation posted in: General

Parallel Extensions. A glimpse into the parallel universe. By Eric De Carufel Microsoft .NET Solution Architect at Orckestra [email protected] [email protected] http://blog.decarufel.net. Who am’I ?. Eric De Carufel is solution architect at Orckestra

Download Presentation

Parallel Extensions

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript


Parallel extensions

Parallel Extensions

A glimpse into the parallel universe

By Eric De Carufel

Microsoft .NET Solution Architect atOrckestra

[email protected]

[email protected]

http://blog.decarufel.net


Who am i

Whoam’I?

  • Eric De Carufel is solution architect at Orckestra

  • Over 15 years experience in software development

    • Bell Canada, Centre de Rechercehd’emploi St-Denis, Fédération Québécoise de Karaté, AXA Canada Tech, Provigo (5 projects), Metro-Richelieu (2 projects), Imagina, [email protected], Unipage, APLC, Viasystems, Montreal Jewish Hospital, AGTI, CCQ, Ogilvy Renault, Ivanhoé Cambridge, Microcell (Fido), Cirque du Soleil, TELUS, PSP Investment, CGI, Deutsche Bank, Orckestra, Sobeys, Jean-Coutu, Xtranormal

  • Started with an ADAM computer by Coleco

  • Working with .NET since version 1.0

  • My coworkers call me .NET Jedi


Agenda

Agenda

  • Introduction

  • Overview

  • Library Core

  • TPL (Task Parallel Library)

  • Parallel Linq (PLINQ)

  • Parallel Data Structures

  • Questions


Introduction

Introduction

  • Why do we have to bother?

    • Moore’s law is over, no more free lunch

    • Multi cores systems will be more and more available

  • Type of Parallelism

    • Asynchronous operation (better user experience)

    • Data parallelism

    • Task parallelism

  • Options

    • Manual treading

      • Thread, ThreadPool, BackgroundWorkerThread

    • Asynchronous calls

    • Event driven

  • Problems

    • Resource sharing

    • Locking

    • Non-deterministic sequence of execution

    • Hard to debug


Overview

Overview


Task parallel library tpl

TaskParallel Library (TPL)

  • Lightweight task framework (Task)

    • Create(Action<T>) factorymethod

    • Wait, WaitAll, WaitAny to catch exception

    • ContinueWith to chainTaskstogether

  • Lazy function call

    • Future<T>

  • Task scheduler and manager

    • TaskManager


Parallel api

Parallel API

  • Parallel Loops

    • Parallel.For

    • Parallel.ForEach

  • Lazy Initialisation

    • LazyInit<T>

  • Locking

    • SpinWait

    • SpinLock

  • CountdownEvent


Parallel api1

Parallel API

  • Standard for loop

    • for (inti = 0; i < N; i++){ a[i] = Compute(i);}

  • Parallel for loop

    • Parallel.For(0, N, i=>{ a[i] = Compute(i);});


Parallel linq plinq

Parallel Linq (PLINQ)

  • Parallel Query

    • AsParallel()

  • Return to sequential execution

    • AsSequential()

  • Preserve order

    • AsOrdered()

  • Order doesn’t matter

    • AsUnordered()


Parallel linq plinq1

Parallel Linq (PLINQ)

  • var query = from c in Customers where c.Name = “Smith” select c;

  • var query = from c in Customers.AsParallel() where c.Name = “Smith” select c;


Parallel data structures

Parallel Data Structures

  • IConcurrentCollection

    • Add(T item)

    • Remove(out T item)

  • ConcurrentStack

    • Push(T item)

    • TryPop(out T item)

  • ConcurrentQueue

    • Enqueue(T item)

    • TryDequeue(out T item)

  • BlockingCollection

    • Add(T item),

    • Remove(out T item)

    • TryAdd(T item),

    • TryRemove(out T item)


User mode scheduler for tasks

User Mode Scheduler For Tasks

CLR Thread Pool: Work-Stealing

Local

Queue

Local

Queue

Global

Queue

Worker Thread 1

Worker Thread p

Task 6

Task 3

Task 4

Task 1

Program Thread

Task 5

Task 2


Demo time

Demo Time


What s next

What’snext

  • Visual Studio 2010

  • .NET Framework 4.0

  • New multi cores computer (4, 16, 32, 64, …)

  • Think parallel!

    • Thread safety will save your life


  • Login