SlideShare a Scribd company logo
1 of 37
1
MeetingsMERI
Programmation
Parallèle en .NET
Animé par
Sylvain Rescourio – Expert .NET
Olivier Navarre – Directeur Technique
Mardi 27 Mai 2014
2
 Introduction
 What is parallel programming ?
 Why parallel programming ?
 The issues that come with parallel
programming ?
 How to do parallel programming
in C# ?
 Thread
 ThreadPool
 Task
 Parallel
 Async
 PLinq
 How to synchronize in C# ?
 Lock
 Mutex
 SpinLock
 Semaphore
 ReaderWriterLock
 Semaphore Slim
 ReaderWriterLockSlim
 How to signal in C# ?
 Wait / Pulse
 Barrier
 How to store shared items in C# ?
 Wait / Pulse
 Barrier
 Conclusion
Sommaire
3
What is parallel programming ?
Parallel computing is the simultaneous use of multiple compute resources
Problem Result
Compute resource 1
Compute resource 2
Compute resource m
Sub Problem 1
Sub Problem 2
Sub Problem n
4
Why parallel programming ?
Do the same work but in less time
8 sec
4 sec
Work 1 2 * (0,5 * Work 1)
at the same time
Sequential Parallel
Start
5
Why parallel programming ?
Responsive UI
Long Action
Refresh interface
Refresh interface Refresh interface
Sequential Parallel
See example
Click Click Long Action
6
The issues that come with parallel programming
A is a situation in which two or more competing actions are
each waiting for the other to finish, and thus neither ever does.
Waiting for Task 2 to finish
Task 1
Task 2
End
Waiting for Task 1 to finish
7
The issues that come with parallel programming
A is the behavior of a system where the output is
dependent on the sequence or timing of other uncontrollable events.
Task 1
Task 2
Result 1
Task 1
Task 2
Result 2
Race Condition if
Result 1 != Result 2
8
How to do parallel
programming in C# ?
Thread
ThreadPool
Task
Parallel
Async
PLinq
9
Thread
A is the basic unit to which an operating system allocates
processor time to execute a sequence of instruction.
Process
Thread 1
Instruction 1
Instruction 2
Instruction n
Thread k
Instruction 1
Instruction 2
Instruction n
10
Thread
Code
11
Solutions Thread, ThreadPool, Task, Parallel,
Async, Plinq, …
Differents solutions
 ThreadPool : A pool of threads that can be used to execute tasks.
 Task : Represents an asynchronous operation.
 Parallel : Provides support for parallel loops.
 Async : A keyword to specify that a method is asynchronous.
 Plinq : Execute LINQ queries in parallel.
12
ThreadPool
Code
13
Task
Code
14
Parallel
Code
15
Parallel Foreach
Code
16
Async
Code
See example
17
PLinq
Code
18
How to synchronize in C# ?
Lock
Mutex
SpinLock
Semaphore
ReaderWriterLock
Semaphore Slim
ReaderWriterLockSlim
19
Different solutions
 Lock
 Protect a section of code.
 Mutex
 Locking across processes.
 SpinLock
 Locking few instructions (Sum, variable copy, …).
 Semaphore
 Cap the access of a resource to a fixed number of
thread.
 ReaderWriterLock
 Control the access of a resource by multiple thread,
allowing 1 writer or many reader at the same time.
Lock
Locking for a long time
can degrade
performances !
Be aware of deadlock !
20
Lock
Comparison of Different solutions
Reference : http://www.albahari.com/threading/part2.aspx#_Locking
21
Lock
Code
22
SemaphoreSlim
Code
23
ReaderWriterLockSlim
Code
24
How to signal in C# ?
Wait / Pulse
Barrier
25
How to signal in C# ?
Reference : http://www.albahari.com/threading/part2.aspx#_Signaling_with_Event_Wait_Handles
Differents solutions
 Wait / Pulse methods
 Let a thread wait for a signal or send a signal (Pulse).
 Barrier
 Allow threads to wait for each other.
26
Wait / Pulse
Code
27
Barrier
Code
28
A quick word about
atomicity in C#
29
A quick word about atomicity in C#
An atomic operation
 An atomic operation cannot be interrupted by other thread.
 Example : Incrementing a variable is not atomic
 Read the variable
 Add 1
 Store the result in the same variable
 What if in the middle, another thread access this variable ?
 Solution
 Interlocked.Add, Interlocked.Increment
 Interlocked.Exchange, Interlocked.CompareExchange
 Interlocked.Read
30
DEMO
31
DEMO - Image crawler
Image crawler :
http://www.hdwallpapers.in
GUI Processing
Get image count
Download pages
Download images
Update GUI
Wait for all images to be downloaded
32
How to store shared items
in C# ?
33
How to store shared items in C# ?
Different Solutions
 Standard Collection + Lock
If you only add elements to the collection
 Standard Collection + ReaderWriterLockSlim
If you modify & read simultaneously the collection
 Native ThreadSafe collections
If you modify & read simultaneously the collection
 For highly concurrent scenario
Native ThreadSafe collections
Concurrent collection Non Concurrent equivalent
ConcurrentStack<T> Stack<T>
ConcurrentQueue<T> Queue<T>
ConcurrentDictionary<TKey,TValue> Dictionary<TKey,TValue>
BlockingCollection<T>
ConcurrentBag<T>
34
Conclusion
35
Parallel programming can help
you to
 Compute faster
 Create responsive application
 Parallel programming has a cost :
 Increase code complexity.
 Too much synchronization can lead to
worse performance than single
threaded application.
Conclusion
Don’t rush into parallel programming, profile your code if necessary
36
Partenaire Microsoft
MERITIS GOLD PARTNER 2015
Répondre aux attentes de nos
clients et de nos collaborateurs
Améliorer notre expertise sur les
solutions Microsoft
Accompagner nos clients sur ces
domaines technologiques
Être innovant autours des
technologies Microsoft
37
Conseil et Ingénierie en Banque, Finance et Assurance
Siège Social : 14, rue Gaillon – Paris 2ème
Tél. : 01 44 56 88 10 / Fax : 01 44 56 88 11
www.meritis.fr
Merci de votre
attention

More Related Content

What's hot (20)

Erlang For Five Nines
Erlang For Five NinesErlang For Five Nines
Erlang For Five Nines
 
ZeroMQ with NodeJS
ZeroMQ with NodeJSZeroMQ with NodeJS
ZeroMQ with NodeJS
 
Open mp directives
Open mp directivesOpen mp directives
Open mp directives
 
Asynchronous programming in C#
Asynchronous programming in C#Asynchronous programming in C#
Asynchronous programming in C#
 
MPI Tutorial
MPI TutorialMPI Tutorial
MPI Tutorial
 
Async and Await on the Server
Async and Await on the ServerAsync and Await on the Server
Async and Await on the Server
 
Asynchronous Programming in .NET
Asynchronous Programming in .NETAsynchronous Programming in .NET
Asynchronous Programming in .NET
 
Multicore
MulticoreMulticore
Multicore
 
Openmp
OpenmpOpenmp
Openmp
 
MPI in TNT for parallel processing
MPI in TNT for parallel processingMPI in TNT for parallel processing
MPI in TNT for parallel processing
 
Tensorflow on Android
Tensorflow on AndroidTensorflow on Android
Tensorflow on Android
 
Introduction to OpenMP
Introduction to OpenMPIntroduction to OpenMP
Introduction to OpenMP
 
ZeroMQ - Sockets on steroids!
ZeroMQ - Sockets on steroids!ZeroMQ - Sockets on steroids!
ZeroMQ - Sockets on steroids!
 
Distributed app development with nodejs and zeromq
Distributed app development with nodejs and zeromqDistributed app development with nodejs and zeromq
Distributed app development with nodejs and zeromq
 
Multiprocessing in python
Multiprocessing in pythonMultiprocessing in python
Multiprocessing in python
 
OpenMP
OpenMPOpenMP
OpenMP
 
Event Driven with LibUV and ZeroMQ
Event Driven with LibUV and ZeroMQEvent Driven with LibUV and ZeroMQ
Event Driven with LibUV and ZeroMQ
 
Introduction to OpenMP
Introduction to OpenMPIntroduction to OpenMP
Introduction to OpenMP
 
An introduction to erlang
An introduction to erlangAn introduction to erlang
An introduction to erlang
 
Introduction to ZeroMQ - eSpace TechTalk
Introduction to ZeroMQ - eSpace TechTalkIntroduction to ZeroMQ - eSpace TechTalk
Introduction to ZeroMQ - eSpace TechTalk
 

Viewers also liked

Outsourceit- At a glance
Outsourceit- At a glanceOutsourceit- At a glance
Outsourceit- At a glanceUma Baeko
 
Project presentation
Project presentationProject presentation
Project presentationdaitoguns
 
Outsourceit_changing the future of employment
Outsourceit_changing the future of employmentOutsourceit_changing the future of employment
Outsourceit_changing the future of employmentUma Baeko
 
MERIMeeting du 21 octobre 2014 - Financial Markets and Instruments overview
MERIMeeting du 21 octobre 2014  - Financial Markets and Instruments overviewMERIMeeting du 21 octobre 2014  - Financial Markets and Instruments overview
MERIMeeting du 21 octobre 2014 - Financial Markets and Instruments overviewOlivier NAVARRE
 
Hvordan lykkes med offshoring (outsourcing til utlandet) 2014
Hvordan lykkes med offshoring (outsourcing til utlandet) 2014Hvordan lykkes med offshoring (outsourcing til utlandet) 2014
Hvordan lykkes med offshoring (outsourcing til utlandet) 2014Uma Baeko
 
Science Thought for the Day
Science Thought for the DayScience Thought for the Day
Science Thought for the Dayannetteblack6
 
Jolly phonics ai words
Jolly phonics ai wordsJolly phonics ai words
Jolly phonics ai wordsannetteblack6
 
Jolly phonics ee digraph
Jolly phonics ee digraphJolly phonics ee digraph
Jolly phonics ee digraphannetteblack6
 
Jolly phonics letter sounds
Jolly phonics letter soundsJolly phonics letter sounds
Jolly phonics letter soundsannetteblack6
 

Viewers also liked (14)

Outsourceit- At a glance
Outsourceit- At a glanceOutsourceit- At a glance
Outsourceit- At a glance
 
Project presentation
Project presentationProject presentation
Project presentation
 
Outsourceit_changing the future of employment
Outsourceit_changing the future of employmentOutsourceit_changing the future of employment
Outsourceit_changing the future of employment
 
MERIMeeting du 21 octobre 2014 - Financial Markets and Instruments overview
MERIMeeting du 21 octobre 2014  - Financial Markets and Instruments overviewMERIMeeting du 21 octobre 2014  - Financial Markets and Instruments overview
MERIMeeting du 21 octobre 2014 - Financial Markets and Instruments overview
 
Hvordan lykkes med offshoring (outsourcing til utlandet) 2014
Hvordan lykkes med offshoring (outsourcing til utlandet) 2014Hvordan lykkes med offshoring (outsourcing til utlandet) 2014
Hvordan lykkes med offshoring (outsourcing til utlandet) 2014
 
Science Thought for the Day
Science Thought for the DayScience Thought for the Day
Science Thought for the Day
 
Present verb to be
Present  verb to bePresent  verb to be
Present verb to be
 
Metodo di Dimagrimento "GLIODIME"
Metodo di Dimagrimento "GLIODIME"Metodo di Dimagrimento "GLIODIME"
Metodo di Dimagrimento "GLIODIME"
 
LA GLICAZIONE
LA GLICAZIONELA GLICAZIONE
LA GLICAZIONE
 
MCNT Dr Salvatore Di Meglio
MCNT Dr Salvatore Di MeglioMCNT Dr Salvatore Di Meglio
MCNT Dr Salvatore Di Meglio
 
Disbiosi intestinale e DIETA GIFT
Disbiosi intestinale e DIETA GIFTDisbiosi intestinale e DIETA GIFT
Disbiosi intestinale e DIETA GIFT
 
Jolly phonics ai words
Jolly phonics ai wordsJolly phonics ai words
Jolly phonics ai words
 
Jolly phonics ee digraph
Jolly phonics ee digraphJolly phonics ee digraph
Jolly phonics ee digraph
 
Jolly phonics letter sounds
Jolly phonics letter soundsJolly phonics letter sounds
Jolly phonics letter sounds
 

Similar to MERIMeeting du 27 mai 2014 - Parallel Programming

Peyton jones-2011-parallel haskell-the_future
Peyton jones-2011-parallel haskell-the_futurePeyton jones-2011-parallel haskell-the_future
Peyton jones-2011-parallel haskell-the_futureTakayuki Muranushi
 
Simon Peyton Jones: Managing parallelism
Simon Peyton Jones: Managing parallelismSimon Peyton Jones: Managing parallelism
Simon Peyton Jones: Managing parallelismSkills Matter
 
C# Parallel programming
C# Parallel programmingC# Parallel programming
C# Parallel programmingUmeshwaran V
 
6-9-2017-slides-vFinal.pptx
6-9-2017-slides-vFinal.pptx6-9-2017-slides-vFinal.pptx
6-9-2017-slides-vFinal.pptxSimRelokasi2
 
Asynchronous Python A Gentle Introduction
Asynchronous Python A Gentle IntroductionAsynchronous Python A Gentle Introduction
Asynchronous Python A Gentle IntroductionPyData
 
Declare Your Language: What is a Compiler?
Declare Your Language: What is a Compiler?Declare Your Language: What is a Compiler?
Declare Your Language: What is a Compiler?Eelco Visser
 
C# 5 deep drive into asynchronous programming
C# 5 deep drive into asynchronous programmingC# 5 deep drive into asynchronous programming
C# 5 deep drive into asynchronous programmingPraveen Prajapati
 
Need for Async: Hot pursuit for scalable applications
Need for Async: Hot pursuit for scalable applicationsNeed for Async: Hot pursuit for scalable applications
Need for Async: Hot pursuit for scalable applicationsKonrad Malawski
 
CS4200 2019 Lecture 1: Introduction
CS4200 2019 Lecture 1: IntroductionCS4200 2019 Lecture 1: Introduction
CS4200 2019 Lecture 1: IntroductionEelco Visser
 
Concurrent Programming with Ruby and Tuple Spaces
Concurrent Programming with Ruby and Tuple SpacesConcurrent Programming with Ruby and Tuple Spaces
Concurrent Programming with Ruby and Tuple Spacesluccastera
 
Os Worthington
Os WorthingtonOs Worthington
Os Worthingtonoscon2007
 
Evolution of JDK Tools for Multithreaded Programming
Evolution of JDK Tools for Multithreaded ProgrammingEvolution of JDK Tools for Multithreaded Programming
Evolution of JDK Tools for Multithreaded ProgrammingGlobalLogic Ukraine
 
Node.js: A Guided Tour
Node.js: A Guided TourNode.js: A Guided Tour
Node.js: A Guided Tourcacois
 
Distributed locks in Ruby - Correctness vs Efficiency - Knapsack Pro case stu...
Distributed locks in Ruby - Correctness vs Efficiency - Knapsack Pro case stu...Distributed locks in Ruby - Correctness vs Efficiency - Knapsack Pro case stu...
Distributed locks in Ruby - Correctness vs Efficiency - Knapsack Pro case stu...Artur Trzop
 
Here comes the Loom - Ya!vaConf.pdf
Here comes the Loom - Ya!vaConf.pdfHere comes the Loom - Ya!vaConf.pdf
Here comes the Loom - Ya!vaConf.pdfKrystian Zybała
 
Programming in Java: Getting Started
Programming in Java: Getting StartedProgramming in Java: Getting Started
Programming in Java: Getting StartedMartin Chapman
 
Java Core | Modern Java Concurrency | Martijn Verburg & Ben Evans
Java Core | Modern Java Concurrency | Martijn Verburg & Ben EvansJava Core | Modern Java Concurrency | Martijn Verburg & Ben Evans
Java Core | Modern Java Concurrency | Martijn Verburg & Ben EvansJAX London
 

Similar to MERIMeeting du 27 mai 2014 - Parallel Programming (20)

Concurrency in c#
Concurrency in c#Concurrency in c#
Concurrency in c#
 
Java multi thread programming on cmp system
Java multi thread programming on cmp systemJava multi thread programming on cmp system
Java multi thread programming on cmp system
 
Peyton jones-2011-parallel haskell-the_future
Peyton jones-2011-parallel haskell-the_futurePeyton jones-2011-parallel haskell-the_future
Peyton jones-2011-parallel haskell-the_future
 
Simon Peyton Jones: Managing parallelism
Simon Peyton Jones: Managing parallelismSimon Peyton Jones: Managing parallelism
Simon Peyton Jones: Managing parallelism
 
C# Parallel programming
C# Parallel programmingC# Parallel programming
C# Parallel programming
 
6-9-2017-slides-vFinal.pptx
6-9-2017-slides-vFinal.pptx6-9-2017-slides-vFinal.pptx
6-9-2017-slides-vFinal.pptx
 
Os Lamothe
Os LamotheOs Lamothe
Os Lamothe
 
Asynchronous Python A Gentle Introduction
Asynchronous Python A Gentle IntroductionAsynchronous Python A Gentle Introduction
Asynchronous Python A Gentle Introduction
 
Declare Your Language: What is a Compiler?
Declare Your Language: What is a Compiler?Declare Your Language: What is a Compiler?
Declare Your Language: What is a Compiler?
 
C# 5 deep drive into asynchronous programming
C# 5 deep drive into asynchronous programmingC# 5 deep drive into asynchronous programming
C# 5 deep drive into asynchronous programming
 
Need for Async: Hot pursuit for scalable applications
Need for Async: Hot pursuit for scalable applicationsNeed for Async: Hot pursuit for scalable applications
Need for Async: Hot pursuit for scalable applications
 
CS4200 2019 Lecture 1: Introduction
CS4200 2019 Lecture 1: IntroductionCS4200 2019 Lecture 1: Introduction
CS4200 2019 Lecture 1: Introduction
 
Concurrent Programming with Ruby and Tuple Spaces
Concurrent Programming with Ruby and Tuple SpacesConcurrent Programming with Ruby and Tuple Spaces
Concurrent Programming with Ruby and Tuple Spaces
 
Os Worthington
Os WorthingtonOs Worthington
Os Worthington
 
Evolution of JDK Tools for Multithreaded Programming
Evolution of JDK Tools for Multithreaded ProgrammingEvolution of JDK Tools for Multithreaded Programming
Evolution of JDK Tools for Multithreaded Programming
 
Node.js: A Guided Tour
Node.js: A Guided TourNode.js: A Guided Tour
Node.js: A Guided Tour
 
Distributed locks in Ruby - Correctness vs Efficiency - Knapsack Pro case stu...
Distributed locks in Ruby - Correctness vs Efficiency - Knapsack Pro case stu...Distributed locks in Ruby - Correctness vs Efficiency - Knapsack Pro case stu...
Distributed locks in Ruby - Correctness vs Efficiency - Knapsack Pro case stu...
 
Here comes the Loom - Ya!vaConf.pdf
Here comes the Loom - Ya!vaConf.pdfHere comes the Loom - Ya!vaConf.pdf
Here comes the Loom - Ya!vaConf.pdf
 
Programming in Java: Getting Started
Programming in Java: Getting StartedProgramming in Java: Getting Started
Programming in Java: Getting Started
 
Java Core | Modern Java Concurrency | Martijn Verburg & Ben Evans
Java Core | Modern Java Concurrency | Martijn Verburg & Ben EvansJava Core | Modern Java Concurrency | Martijn Verburg & Ben Evans
Java Core | Modern Java Concurrency | Martijn Verburg & Ben Evans
 

Recently uploaded

Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...Call Girls in Nagpur High Profile
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxupamatechverse
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptxBSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptxfenichawla
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...Call Girls in Nagpur High Profile
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Dr.Costas Sachpazis
 
University management System project report..pdf
University management System project report..pdfUniversity management System project report..pdf
University management System project report..pdfKamal Acharya
 
UNIT-III FMM. DIMENSIONAL ANALYSIS
UNIT-III FMM.        DIMENSIONAL ANALYSISUNIT-III FMM.        DIMENSIONAL ANALYSIS
UNIT-III FMM. DIMENSIONAL ANALYSISrknatarajan
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordAsst.prof M.Gokilavani
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Call Girls in Nagpur High Profile
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSSIVASHANKAR N
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...ranjana rawat
 
Online banking management system project.pdf
Online banking management system project.pdfOnline banking management system project.pdf
Online banking management system project.pdfKamal Acharya
 
UNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular ConduitsUNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular Conduitsrknatarajan
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingrakeshbaidya232001
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINESIVASHANKAR N
 

Recently uploaded (20)

Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
 
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptx
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
 
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptxBSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
 
University management System project report..pdf
University management System project report..pdfUniversity management System project report..pdf
University management System project report..pdf
 
UNIT-III FMM. DIMENSIONAL ANALYSIS
UNIT-III FMM.        DIMENSIONAL ANALYSISUNIT-III FMM.        DIMENSIONAL ANALYSIS
UNIT-III FMM. DIMENSIONAL ANALYSIS
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
 
Online banking management system project.pdf
Online banking management system project.pdfOnline banking management system project.pdf
Online banking management system project.pdf
 
UNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular ConduitsUNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular Conduits
 
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writing
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
 

MERIMeeting du 27 mai 2014 - Parallel Programming

  • 1. 1 MeetingsMERI Programmation Parallèle en .NET Animé par Sylvain Rescourio – Expert .NET Olivier Navarre – Directeur Technique Mardi 27 Mai 2014
  • 2. 2  Introduction  What is parallel programming ?  Why parallel programming ?  The issues that come with parallel programming ?  How to do parallel programming in C# ?  Thread  ThreadPool  Task  Parallel  Async  PLinq  How to synchronize in C# ?  Lock  Mutex  SpinLock  Semaphore  ReaderWriterLock  Semaphore Slim  ReaderWriterLockSlim  How to signal in C# ?  Wait / Pulse  Barrier  How to store shared items in C# ?  Wait / Pulse  Barrier  Conclusion Sommaire
  • 3. 3 What is parallel programming ? Parallel computing is the simultaneous use of multiple compute resources Problem Result Compute resource 1 Compute resource 2 Compute resource m Sub Problem 1 Sub Problem 2 Sub Problem n
  • 4. 4 Why parallel programming ? Do the same work but in less time 8 sec 4 sec Work 1 2 * (0,5 * Work 1) at the same time Sequential Parallel Start
  • 5. 5 Why parallel programming ? Responsive UI Long Action Refresh interface Refresh interface Refresh interface Sequential Parallel See example Click Click Long Action
  • 6. 6 The issues that come with parallel programming A is a situation in which two or more competing actions are each waiting for the other to finish, and thus neither ever does. Waiting for Task 2 to finish Task 1 Task 2 End Waiting for Task 1 to finish
  • 7. 7 The issues that come with parallel programming A is the behavior of a system where the output is dependent on the sequence or timing of other uncontrollable events. Task 1 Task 2 Result 1 Task 1 Task 2 Result 2 Race Condition if Result 1 != Result 2
  • 8. 8 How to do parallel programming in C# ? Thread ThreadPool Task Parallel Async PLinq
  • 9. 9 Thread A is the basic unit to which an operating system allocates processor time to execute a sequence of instruction. Process Thread 1 Instruction 1 Instruction 2 Instruction n Thread k Instruction 1 Instruction 2 Instruction n
  • 11. 11 Solutions Thread, ThreadPool, Task, Parallel, Async, Plinq, … Differents solutions  ThreadPool : A pool of threads that can be used to execute tasks.  Task : Represents an asynchronous operation.  Parallel : Provides support for parallel loops.  Async : A keyword to specify that a method is asynchronous.  Plinq : Execute LINQ queries in parallel.
  • 18. 18 How to synchronize in C# ? Lock Mutex SpinLock Semaphore ReaderWriterLock Semaphore Slim ReaderWriterLockSlim
  • 19. 19 Different solutions  Lock  Protect a section of code.  Mutex  Locking across processes.  SpinLock  Locking few instructions (Sum, variable copy, …).  Semaphore  Cap the access of a resource to a fixed number of thread.  ReaderWriterLock  Control the access of a resource by multiple thread, allowing 1 writer or many reader at the same time. Lock Locking for a long time can degrade performances ! Be aware of deadlock !
  • 20. 20 Lock Comparison of Different solutions Reference : http://www.albahari.com/threading/part2.aspx#_Locking
  • 24. 24 How to signal in C# ? Wait / Pulse Barrier
  • 25. 25 How to signal in C# ? Reference : http://www.albahari.com/threading/part2.aspx#_Signaling_with_Event_Wait_Handles Differents solutions  Wait / Pulse methods  Let a thread wait for a signal or send a signal (Pulse).  Barrier  Allow threads to wait for each other.
  • 28. 28 A quick word about atomicity in C#
  • 29. 29 A quick word about atomicity in C# An atomic operation  An atomic operation cannot be interrupted by other thread.  Example : Incrementing a variable is not atomic  Read the variable  Add 1  Store the result in the same variable  What if in the middle, another thread access this variable ?  Solution  Interlocked.Add, Interlocked.Increment  Interlocked.Exchange, Interlocked.CompareExchange  Interlocked.Read
  • 31. 31 DEMO - Image crawler Image crawler : http://www.hdwallpapers.in GUI Processing Get image count Download pages Download images Update GUI Wait for all images to be downloaded
  • 32. 32 How to store shared items in C# ?
  • 33. 33 How to store shared items in C# ? Different Solutions  Standard Collection + Lock If you only add elements to the collection  Standard Collection + ReaderWriterLockSlim If you modify & read simultaneously the collection  Native ThreadSafe collections If you modify & read simultaneously the collection  For highly concurrent scenario Native ThreadSafe collections Concurrent collection Non Concurrent equivalent ConcurrentStack<T> Stack<T> ConcurrentQueue<T> Queue<T> ConcurrentDictionary<TKey,TValue> Dictionary<TKey,TValue> BlockingCollection<T> ConcurrentBag<T>
  • 35. 35 Parallel programming can help you to  Compute faster  Create responsive application  Parallel programming has a cost :  Increase code complexity.  Too much synchronization can lead to worse performance than single threaded application. Conclusion Don’t rush into parallel programming, profile your code if necessary
  • 36. 36 Partenaire Microsoft MERITIS GOLD PARTNER 2015 Répondre aux attentes de nos clients et de nos collaborateurs Améliorer notre expertise sur les solutions Microsoft Accompagner nos clients sur ces domaines technologiques Être innovant autours des technologies Microsoft
  • 37. 37 Conseil et Ingénierie en Banque, Finance et Assurance Siège Social : 14, rue Gaillon – Paris 2ème Tél. : 01 44 56 88 10 / Fax : 01 44 56 88 11 www.meritis.fr Merci de votre attention