SlideShare a Scribd company logo
Sankarsan Bose
 11th July 2010
 Concurrency
 Parallel Programming
 Parallel Extensions in .NET 4.0
    Coordination Data Structures
    Task Parallelism
    Parallel Loop /Data Parallelism
    Parallel LINQ
Concurrency
• Perform multiple            Program A Program B
                    computations
  What              in overlapping time         Step 1                T
                    periods                               Step1       I
                                                Step2                 M
                                                                      E
                  • Responsive UI                         Step2
                  • Asynchronous
   Why              Processing
                                                Step3
                                                          Step3
                  • Better performance(??)



Concurrency is almost everywhere…..

OS,Database,Web Servers,GUI programs, File processing….
Program


 Concurrent    Concurrent              Concurrent
Component 1   Component 2             Component N

                        Read/Write




                     Shared Memory


Shared Memory Model of Concurrency
OS Process



  Thread 1      Thread 2                Thread N

                           Read/Write




                        Shared Memory


Operating System View
Managed Program in CLR App Domain


  Managed       Managed                          Managed
  Thread 1      Thread 2                         Thread N

                           Read/Write




                      Shared Memory


.NET Common Language Runtime View
Create ThreadStart delegate
                with the method to be
                executed
                Create instance of Thread
                class with the ThreadStart
                delegate




Start the thread execution
 Synchronization    Issues
   Race Condition
   Deadlock
 Dependency on Memory Model & Hardware Architecture
 Debugging becomes complicated
Demo1
Run

             Suspend
Thread1                 Thread1

          Suspend
Thread2                 Thread2

            Run        Single Core
Program
                        Processor
Run
      Thread1                                                     Thread1

                                                                   Core1

                                       Run
      Thread2                                                     Thread2

                                                                   Core2
      Program
                                                            Multi Core Processor


Concurrency - Perform multiple computations in overlapping     time periods
Parallel - Perform multiple computations   simultaneously
Parallel
Programming
 No more increase in clock
                                                           speed
                                                            Increase in number of
                                                           processors
                                                            Sequential programs
                                                           won’t scale
                                                            Parallel Programming
                                                                To leverage hardware
                                                               advances




Source: PDC 09 Patterns of Parallel Programming Workshop
 Decompose the program into parts e.g. methods,
statements etc.
 Identify the parts which can be executed in parallel
 Assign each part to separate tasks
 Perform the tasks in parallel on different cores
 Each task is likely to perform different actions
 Partition the input data into multiple chunks
 Perform action on each chunk in parallel on different cores
 Merge the output results
 Can be scaled up with more processors as data volume grows
To develop applications for the multicore processors we need

  Design
      Identify parallel parts
      Apply correct design patterns


  Libraries
      Sophisticated synchronization features to avoid deadlocks/race etc.
      Thread safe data structures & containers
      Language/API support for common parallel programming patterns to achieve task/data
     parallelism.

  Tools
      For   debugging parallel applications
      For   profiling parallel applications



   Parallel Extensions in .NET 4.0
Parallel
Extensions in
  .NET 4.0
Integrated                   Programming Models                                                                  Programming Models
   Tooling
                                                 PLINQ
       Parallel                               Task Parallel                                                          Parallel Pattern      Agents
      Debugger                                                                                                           Library           Library
                                                Library
    Toolwindows




                                                                                Data Structures

                                                                                                  Data Structures
                                 Concurrency Runtime                                                                 Concurrency Runtime

                                              ThreadPool
      Profiler                                                                                                                Task Scheduler
    Concurrency                              Task Scheduler
      Analysis
                                            Resource Manager
                                                                                                                             Resource Manager

                                                                 Operating System

                                                                  Threads

                                  Key:         Managed Library        Native Library                                 Tools

Source: PDC 08 Daniel Moth’s Presentation
Thread-safe collections                    Phased Operation
 ConcurrentStack<T>
 ConcurrentQueue<T>
 ConcurrentDictionary<TKey,TValue>
                                            Locks
 Work exchange
 BlockingCollection<T>
 IProducerConsumerCollection<T>


 Initialization
 LazyInit<T>
Source: PDC 08 Daniel Moth’s Presentation
Demo2
Demo3
   APIs provided under System.Threading & Sytem.Threading.Tasks
   Behind the scenes uses CLR Thread Pool
   Uses sophisticated algorithms to assign number of threads to
    maximize performance
   More programmatic control than thread or work item
       Create/Start Tasks
       Return result values from tasks
       Chain Multiple Tasks
       Nested & Child Tasks
       Exception Handling
Constructor - public Task( Action action )
Action delegate - public delegate void Action()


                                                  Lambda Expression without
                                                  input parameter and
                                                  returning nothing

                                                  Create an explicit instance of
                                                  Action delegate and pass it to
                                                  task constructor




Start the Tasks
Class: public class Task<TResult> : Task
Constructor: public Task( Func<TResult> function )
Delegate: public delegate TResult Func<out TResult>()
                                                        Lambda Expression
                                                        without input
                                                        parameter and
                                                        returning int

                                                        Create new instance
                                                        of Func delegate with
                                                        no input parameter
                                                        and returning int

                                                        We have instantiated
                                                        & started two tasks
                                                        which expected to
                                                        return integer value




The property Result stores the return value
Class: public Task ContinueWith( Action<Task> continuationAction )



                                                                           Instantiate a Task
                                                                           with Action delegate

                                                                           Create an Action
                                                                           delegate with a task
                                                                           object as input and
                                                                           returning nothing.
                                                                           Call ContinueWith
                                                                           method and pass the
                                                                           Action delegate
                                                                           created



 Start the Task.
 After this task completes it will Continue With the execution of Action
 a2 automatically
This is a lambda
                                                            expression and Task
                                                            t1 will execute this
                                                            statements
                                                            Task t11 is created
                                                            while Task T1 is
                                                            executing.
                                                            This is a Nested Task




Task t12 is created while Task T1 is executing but with
AttachedToParent option. This is a Child Task.

Child tasks are very closely synchronized with the parent
Demo4
Method : public static void Invoke( params Action[] actions )




                                                           Three Action delegates are
                                                           created



                                                           Three Action delegates will be
                                                           invoked possibly in Parallel
Demo5
Method : public static ParallelLoopResult For( int fromInclusive, int toExclusive,
Action<int> body )



                                                                             Upper & Lower
                                                                             Bounds of the For
                                                                             Loop
                                                                             Loop Counter

                                                                             Statement
                                                                             executed in the
                                                                             loop




When a For() loop has a small body, it might perform more slowly
Slower performance is caused by the overhead involved in partitioning the data and the
cost of invoking a delegate on each loop iteration.
Method : public static ParallelLoopResult ForEach<TSource>( IEnumerable<TSource>
source, Action<TSource> body )

                                                               Int Array with
                                                               values from 0 to
                                                               100000
                                                               Loop iteration
                                                               variable


                                                               Loop Body
Demo6
   Language-Integrated Query (LINQ) was introduced in the .NET
    Framework version 3.0
       Querying on any System.Collections.IEnumerable or
        System.Collections.Generic.IEnumerable data source
   Parallel LINQ (PLINQ) is a parallel implementation of the LINQ
    pattern
   PLINQ tries to make full use of all the processors on the system
   Partitions the data source into segments
   Executes the query on each segment on separate worker threads
    in parallel on multiple processors
Method : public static ParallelQuery<TSource> AsParallel<TSource>( this
IEnumerable<TSource> source )
Method : public static void ForAll<TSource>( this ParallelQuery<TSource> source,
Action<TSource> action )



                                                                          Instructs to execute
                                                                          the LINQ query in
                                                                          Parallel

                                                                          Invokes in parallel the
                                                                          specified action for
                                                                          each element in the
                                                                          source.
Demo7
   PLINQ, the goal is to maximize performance while maintaining
    correctness
   In some cases, correctness requires the order of the source
    sequence to be preserved
   Ordering can be computationally expensive
   PLINQ by default does not preserve the order of the source
    sequence
   To turn on order-preservation the AsOrdered operator is to be
    used on the source sequence
Method : public static ParallelQuery AsOrdered( this ParallelQuery source )




     Instructs to execute the LINQ query in Parallel by
     preserving order
Demo8
Thank You
http://msdn.microsoft.com/en-us/library/dd460693.aspx

  http://channel9.msdn.com/pdc2008/TL26/

   http://www.ademiller.com/blogs/tech/2009/11/pdc-patterns-
of-parallel-programming-workshop/

  Concurrent Programming on Windows by Joe Duffy
Additional
  Slides
This is like a pointer to
                                           function which
                                           accepts nothing and
                                           returns nothing

                                           Accepts delegate D as
                                           input

                                           M2 has no parameter
                                           & return value

                                           An instance of
                                           delegate D or a
                                           pointer to method
                                           M2
                                           Call to M1 with
                                           delegate instance d1
                                           as a parameter.

                                           Call to M1 with
                                           Lambda Expression

Lambda Expression is an anonymous method
(input parameters) => (statement)
Ad

Recommended

Node-REDでプロジェクト管理を始めてみよう!
Node-REDでプロジェクト管理を始めてみよう!
Koji FUNATSU,
 
Complete-NGINX-Cookbook-2019.pdf
Complete-NGINX-Cookbook-2019.pdf
TomaszWojciechowski22
 
Support distributed computing and caching avec hazelcast
Support distributed computing and caching avec hazelcast
ENSET, Université Hassan II Casablanca
 
オンプレミス回帰の動きに備えよ ~クラウドの手法をオンプレミスでも実現するには~(CloudNative Days Fukuoka 2023 発表資料)
オンプレミス回帰の動きに備えよ ~クラウドの手法をオンプレミスでも実現するには~(CloudNative Days Fukuoka 2023 発表資料)
NTT DATA Technology & Innovation
 
Support NodeJS avec TypeScript Express MongoDB
Support NodeJS avec TypeScript Express MongoDB
ENSET, Université Hassan II Casablanca
 
Spring introduction
Spring introduction
Manav Prasad
 
モダンフロントエンド開発者に求められるスキルとは
モダンフロントエンド開発者に求められるスキルとは
Takuya Tejima
 
Développement d'un site web jee de e commerce basé sur spring (m.youssfi)
Développement d'un site web jee de e commerce basé sur spring (m.youssfi)
ENSET, Université Hassan II Casablanca
 
PFE MASTER en Développement d’une Application E-commerce avec la Technologie ...
PFE MASTER en Développement d’une Application E-commerce avec la Technologie ...
ayoub_anbara96
 
Rapport Projet ERP - Plateforme Odoo 16 (PFE Licence)
Rapport Projet ERP - Plateforme Odoo 16 (PFE Licence)
Chadi Kammoun
 
Final field semantics
Final field semantics
Vladimir Sitnikov
 
Spring Interview Questions and Answers | Spring Tutorial | Spring Framework T...
Spring Interview Questions and Answers | Spring Tutorial | Spring Framework T...
Edureka!
 
Introduction to Spring Cloud
Introduction to Spring Cloud
VMware Tanzu
 
Workshop spring session 2 - La persistance au sein des applications Java
Workshop spring session 2 - La persistance au sein des applications Java
Antoine Rey
 
Spring bootでweb ユニットテスト編
Spring bootでweb ユニットテスト編
なべ
 
SharePoint 2013 の検索結果をチューニングする
SharePoint 2013 の検索結果をチューニングする
Hiroaki Oikawa
 
Spring Boot × Vue.jsでSPAを作る
Spring Boot × Vue.jsでSPAを作る
Go Miyasaka
 
Node-REDのworldmapの活用
Node-REDのworldmapの活用
OSgeo Japan
 
What's new in Spring Boot 2.6 ?
What's new in Spring Boot 2.6 ?
土岐 孝平
 
Support Java Avancé Troisième Partie
Support Java Avancé Troisième Partie
ENSET, Université Hassan II Casablanca
 
Worldwide Scalable and Resilient Messaging Services by CQRS and Event Sourcin...
Worldwide Scalable and Resilient Messaging Services by CQRS and Event Sourcin...
DataWorks Summit
 
Introduction to Spring Boot!
Introduction to Spring Boot!
Jakub Kubrynski
 
CSS Styling for Eclipse RCP 3.x and 4.x
CSS Styling for Eclipse RCP 3.x and 4.x
Kai Tödter
 
Introduction à Angular
Introduction à Angular
Jean-Baptiste Vigneron
 
Perl 6 for Concurrency and Parallel Computing
Perl 6 for Concurrency and Parallel Computing
Andrew Shitov
 
Basic Concepts in Wireless LAN
Basic Concepts in Wireless LAN
Dr Shashikant Athawale
 
Effective java - concurrency
Effective java - concurrency
feng lee
 
Concurrency: Best Practices
Concurrency: Best Practices
IndicThreads
 
Windows programming
Windows programming
Bapan Maity
 
079 Network Programming
079 Network Programming
Dr Fereidoun Dejahang
 

More Related Content

What's hot (16)

PFE MASTER en Développement d’une Application E-commerce avec la Technologie ...
PFE MASTER en Développement d’une Application E-commerce avec la Technologie ...
ayoub_anbara96
 
Rapport Projet ERP - Plateforme Odoo 16 (PFE Licence)
Rapport Projet ERP - Plateforme Odoo 16 (PFE Licence)
Chadi Kammoun
 
Final field semantics
Final field semantics
Vladimir Sitnikov
 
Spring Interview Questions and Answers | Spring Tutorial | Spring Framework T...
Spring Interview Questions and Answers | Spring Tutorial | Spring Framework T...
Edureka!
 
Introduction to Spring Cloud
Introduction to Spring Cloud
VMware Tanzu
 
Workshop spring session 2 - La persistance au sein des applications Java
Workshop spring session 2 - La persistance au sein des applications Java
Antoine Rey
 
Spring bootでweb ユニットテスト編
Spring bootでweb ユニットテスト編
なべ
 
SharePoint 2013 の検索結果をチューニングする
SharePoint 2013 の検索結果をチューニングする
Hiroaki Oikawa
 
Spring Boot × Vue.jsでSPAを作る
Spring Boot × Vue.jsでSPAを作る
Go Miyasaka
 
Node-REDのworldmapの活用
Node-REDのworldmapの活用
OSgeo Japan
 
What's new in Spring Boot 2.6 ?
What's new in Spring Boot 2.6 ?
土岐 孝平
 
Support Java Avancé Troisième Partie
Support Java Avancé Troisième Partie
ENSET, Université Hassan II Casablanca
 
Worldwide Scalable and Resilient Messaging Services by CQRS and Event Sourcin...
Worldwide Scalable and Resilient Messaging Services by CQRS and Event Sourcin...
DataWorks Summit
 
Introduction to Spring Boot!
Introduction to Spring Boot!
Jakub Kubrynski
 
CSS Styling for Eclipse RCP 3.x and 4.x
CSS Styling for Eclipse RCP 3.x and 4.x
Kai Tödter
 
Introduction à Angular
Introduction à Angular
Jean-Baptiste Vigneron
 
PFE MASTER en Développement d’une Application E-commerce avec la Technologie ...
PFE MASTER en Développement d’une Application E-commerce avec la Technologie ...
ayoub_anbara96
 
Rapport Projet ERP - Plateforme Odoo 16 (PFE Licence)
Rapport Projet ERP - Plateforme Odoo 16 (PFE Licence)
Chadi Kammoun
 
Spring Interview Questions and Answers | Spring Tutorial | Spring Framework T...
Spring Interview Questions and Answers | Spring Tutorial | Spring Framework T...
Edureka!
 
Introduction to Spring Cloud
Introduction to Spring Cloud
VMware Tanzu
 
Workshop spring session 2 - La persistance au sein des applications Java
Workshop spring session 2 - La persistance au sein des applications Java
Antoine Rey
 
Spring bootでweb ユニットテスト編
Spring bootでweb ユニットテスト編
なべ
 
SharePoint 2013 の検索結果をチューニングする
SharePoint 2013 の検索結果をチューニングする
Hiroaki Oikawa
 
Spring Boot × Vue.jsでSPAを作る
Spring Boot × Vue.jsでSPAを作る
Go Miyasaka
 
Node-REDのworldmapの活用
Node-REDのworldmapの活用
OSgeo Japan
 
What's new in Spring Boot 2.6 ?
What's new in Spring Boot 2.6 ?
土岐 孝平
 
Worldwide Scalable and Resilient Messaging Services by CQRS and Event Sourcin...
Worldwide Scalable and Resilient Messaging Services by CQRS and Event Sourcin...
DataWorks Summit
 
Introduction to Spring Boot!
Introduction to Spring Boot!
Jakub Kubrynski
 
CSS Styling for Eclipse RCP 3.x and 4.x
CSS Styling for Eclipse RCP 3.x and 4.x
Kai Tödter
 

Viewers also liked (20)

Perl 6 for Concurrency and Parallel Computing
Perl 6 for Concurrency and Parallel Computing
Andrew Shitov
 
Basic Concepts in Wireless LAN
Basic Concepts in Wireless LAN
Dr Shashikant Athawale
 
Effective java - concurrency
Effective java - concurrency
feng lee
 
Concurrency: Best Practices
Concurrency: Best Practices
IndicThreads
 
Windows programming
Windows programming
Bapan Maity
 
079 Network Programming
079 Network Programming
Dr Fereidoun Dejahang
 
Concurrency & Parallel Programming
Concurrency & Parallel Programming
Ramazan AYYILDIZ
 
Network programming in java - PPT
Network programming in java - PPT
kamal kotecha
 
Microprocessor Week 10: Applications
Microprocessor Week 10: Applications
Arkhom Jodtang
 
Enterprise Management with Microsoft Technologies
Enterprise Management with Microsoft Technologies
Amit Gatenyo
 
Microsoft Dynamics NAV 2009 R2
Microsoft Dynamics NAV 2009 R2
Softera Baltic
 
LeverX - A Comprehensive Guide to SAP PLM 7.01
LeverX - A Comprehensive Guide to SAP PLM 7.01
LeverX
 
Cheap HPC
Cheap HPC
Alex Moore
 
Introduction to-microprocessors
Introduction to-microprocessors
mudulin
 
Microsoft dynamics navision 2009 r2
Microsoft dynamics navision 2009 r2
nikhil patel
 
Microprocessors-based systems (under graduate course) Lecture 1 of 9
Microprocessors-based systems (under graduate course) Lecture 1 of 9
Randa Elanwar
 
Microprocessor Systems
Microprocessor Systems
Quaid-e-Awam University of Engineering Science and Technology Nawabshah Sindh Pakistan
 
ECESLU Microprocessors lecture 2
ECESLU Microprocessors lecture 2
Jeffrey Des Binwag
 
ECESLU Microprocessors Lecture 3
ECESLU Microprocessors Lecture 3
Jeffrey Des Binwag
 
SharePoint PerformancePoint 101
SharePoint PerformancePoint 101
Matthew Carter
 
Perl 6 for Concurrency and Parallel Computing
Perl 6 for Concurrency and Parallel Computing
Andrew Shitov
 
Effective java - concurrency
Effective java - concurrency
feng lee
 
Concurrency: Best Practices
Concurrency: Best Practices
IndicThreads
 
Windows programming
Windows programming
Bapan Maity
 
Concurrency & Parallel Programming
Concurrency & Parallel Programming
Ramazan AYYILDIZ
 
Network programming in java - PPT
Network programming in java - PPT
kamal kotecha
 
Microprocessor Week 10: Applications
Microprocessor Week 10: Applications
Arkhom Jodtang
 
Enterprise Management with Microsoft Technologies
Enterprise Management with Microsoft Technologies
Amit Gatenyo
 
Microsoft Dynamics NAV 2009 R2
Microsoft Dynamics NAV 2009 R2
Softera Baltic
 
LeverX - A Comprehensive Guide to SAP PLM 7.01
LeverX - A Comprehensive Guide to SAP PLM 7.01
LeverX
 
Introduction to-microprocessors
Introduction to-microprocessors
mudulin
 
Microsoft dynamics navision 2009 r2
Microsoft dynamics navision 2009 r2
nikhil patel
 
Microprocessors-based systems (under graduate course) Lecture 1 of 9
Microprocessors-based systems (under graduate course) Lecture 1 of 9
Randa Elanwar
 
ECESLU Microprocessors lecture 2
ECESLU Microprocessors lecture 2
Jeffrey Des Binwag
 
ECESLU Microprocessors Lecture 3
ECESLU Microprocessors Lecture 3
Jeffrey Des Binwag
 
SharePoint PerformancePoint 101
SharePoint PerformancePoint 101
Matthew Carter
 
Ad

Similar to Parallel Programming in .NET (20)

Thinking in parallel ab tuladev
Thinking in parallel ab tuladev
Pavel Tsukanov
 
Tim - FSharp
Tim - FSharp
d0nn9n
 
Arc 300-3 ade miller-en
Arc 300-3 ade miller-en
lonegunman
 
Multi-core Parallelization in Clojure - a Case Study
Multi-core Parallelization in Clojure - a Case Study
elliando dias
 
EEDC Programming Models
EEDC Programming Models
Roger Rafanell Mas
 
Multicore programmingandtpl
Multicore programmingandtpl
Yan Drugalya
 
Multicore programmingandtpl(.net day)
Multicore programmingandtpl(.net day)
Yan Drugalya
 
Patterns of parallel programming
Patterns of parallel programming
Alex Tumanoff
 
Tech Ed09 India Ver M New
Tech Ed09 India Ver M New
rsnarayanan
 
Multi core programming 1
Multi core programming 1
Robin Aggarwal
 
Concept of thread
Concept of thread
Munmun Das Bhowmik
 
Retargeting Embedded Software Stack for Many-Core Systems
Retargeting Embedded Software Stack for Many-Core Systems
Sumant Tambe
 
Overview Of Parallel Development - Ericnel
Overview Of Parallel Development - Ericnel
ukdpe
 
Vol1
Vol1
ashish kumar
 
Parallel architecture
Parallel architecture
Mr SMAK
 
Peyton jones-2011-parallel haskell-the_future
Peyton jones-2011-parallel haskell-the_future
Takayuki Muranushi
 
Simon Peyton Jones: Managing parallelism
Simon Peyton Jones: Managing parallelism
Skills Matter
 
Google: Cluster computing and MapReduce: Introduction to Distributed System D...
Google: Cluster computing and MapReduce: Introduction to Distributed System D...
tugrulh
 
Parallel architecture &programming
Parallel architecture &programming
Ismail El Gayar
 
Chapter_1.ppt Peter S Pacheco, Matthew Malensek – An Introduction to Parallel...
Chapter_1.ppt Peter S Pacheco, Matthew Malensek – An Introduction to Parallel...
JagadeeshSaiD
 
Thinking in parallel ab tuladev
Thinking in parallel ab tuladev
Pavel Tsukanov
 
Tim - FSharp
Tim - FSharp
d0nn9n
 
Arc 300-3 ade miller-en
Arc 300-3 ade miller-en
lonegunman
 
Multi-core Parallelization in Clojure - a Case Study
Multi-core Parallelization in Clojure - a Case Study
elliando dias
 
Multicore programmingandtpl
Multicore programmingandtpl
Yan Drugalya
 
Multicore programmingandtpl(.net day)
Multicore programmingandtpl(.net day)
Yan Drugalya
 
Patterns of parallel programming
Patterns of parallel programming
Alex Tumanoff
 
Tech Ed09 India Ver M New
Tech Ed09 India Ver M New
rsnarayanan
 
Multi core programming 1
Multi core programming 1
Robin Aggarwal
 
Retargeting Embedded Software Stack for Many-Core Systems
Retargeting Embedded Software Stack for Many-Core Systems
Sumant Tambe
 
Overview Of Parallel Development - Ericnel
Overview Of Parallel Development - Ericnel
ukdpe
 
Parallel architecture
Parallel architecture
Mr SMAK
 
Peyton jones-2011-parallel haskell-the_future
Peyton jones-2011-parallel haskell-the_future
Takayuki Muranushi
 
Simon Peyton Jones: Managing parallelism
Simon Peyton Jones: Managing parallelism
Skills Matter
 
Google: Cluster computing and MapReduce: Introduction to Distributed System D...
Google: Cluster computing and MapReduce: Introduction to Distributed System D...
tugrulh
 
Parallel architecture &programming
Parallel architecture &programming
Ismail El Gayar
 
Chapter_1.ppt Peter S Pacheco, Matthew Malensek – An Introduction to Parallel...
Chapter_1.ppt Peter S Pacheco, Matthew Malensek – An Introduction to Parallel...
JagadeeshSaiD
 
Ad

Recently uploaded (20)

Security Tips for Enterprise Azure Solutions
Security Tips for Enterprise Azure Solutions
Michele Leroux Bustamante
 
"Scaling in space and time with Temporal", Andriy Lupa.pdf
"Scaling in space and time with Temporal", Andriy Lupa.pdf
Fwdays
 
Cyber Defense Matrix Workshop - RSA Conference
Cyber Defense Matrix Workshop - RSA Conference
Priyanka Aash
 
"Database isolation: how we deal with hundreds of direct connections to the d...
"Database isolation: how we deal with hundreds of direct connections to the d...
Fwdays
 
You are not excused! How to avoid security blind spots on the way to production
You are not excused! How to avoid security blind spots on the way to production
Michele Leroux Bustamante
 
Connecting Data and Intelligence: The Role of FME in Machine Learning
Connecting Data and Intelligence: The Role of FME in Machine Learning
Safe Software
 
Quantum AI: Where Impossible Becomes Probable
Quantum AI: Where Impossible Becomes Probable
Saikat Basu
 
10 Key Challenges for AI within the EU Data Protection Framework.pdf
10 Key Challenges for AI within the EU Data Protection Framework.pdf
Priyanka Aash
 
GenAI Opportunities and Challenges - Where 370 Enterprises Are Focusing Now.pdf
GenAI Opportunities and Challenges - Where 370 Enterprises Are Focusing Now.pdf
Priyanka Aash
 
Techniques for Automatic Device Identification and Network Assignment.pdf
Techniques for Automatic Device Identification and Network Assignment.pdf
Priyanka Aash
 
AI vs Human Writing: Can You Tell the Difference?
AI vs Human Writing: Can You Tell the Difference?
Shashi Sathyanarayana, Ph.D
 
CapCut Pro Crack For PC Latest Version {Fully Unlocked} 2025
CapCut Pro Crack For PC Latest Version {Fully Unlocked} 2025
pcprocore
 
2025_06_18 - OpenMetadata Community Meeting.pdf
2025_06_18 - OpenMetadata Community Meeting.pdf
OpenMetadata
 
The Future of Technology: 2025-2125 by Saikat Basu.pdf
The Future of Technology: 2025-2125 by Saikat Basu.pdf
Saikat Basu
 
Curietech AI in action - Accelerate MuleSoft development
Curietech AI in action - Accelerate MuleSoft development
shyamraj55
 
OpenPOWER Foundation & Open-Source Core Innovations
OpenPOWER Foundation & Open-Source Core Innovations
IBM
 
EIS-Webinar-Engineering-Retail-Infrastructure-06-16-2025.pdf
EIS-Webinar-Engineering-Retail-Infrastructure-06-16-2025.pdf
Earley Information Science
 
Coordinated Disclosure for ML - What's Different and What's the Same.pdf
Coordinated Disclosure for ML - What's Different and What's the Same.pdf
Priyanka Aash
 
Mastering AI Workflows with FME by Mark Döring
Mastering AI Workflows with FME by Mark Döring
Safe Software
 
Securing AI - There Is No Try, Only Do!.pdf
Securing AI - There Is No Try, Only Do!.pdf
Priyanka Aash
 
Security Tips for Enterprise Azure Solutions
Security Tips for Enterprise Azure Solutions
Michele Leroux Bustamante
 
"Scaling in space and time with Temporal", Andriy Lupa.pdf
"Scaling in space and time with Temporal", Andriy Lupa.pdf
Fwdays
 
Cyber Defense Matrix Workshop - RSA Conference
Cyber Defense Matrix Workshop - RSA Conference
Priyanka Aash
 
"Database isolation: how we deal with hundreds of direct connections to the d...
"Database isolation: how we deal with hundreds of direct connections to the d...
Fwdays
 
You are not excused! How to avoid security blind spots on the way to production
You are not excused! How to avoid security blind spots on the way to production
Michele Leroux Bustamante
 
Connecting Data and Intelligence: The Role of FME in Machine Learning
Connecting Data and Intelligence: The Role of FME in Machine Learning
Safe Software
 
Quantum AI: Where Impossible Becomes Probable
Quantum AI: Where Impossible Becomes Probable
Saikat Basu
 
10 Key Challenges for AI within the EU Data Protection Framework.pdf
10 Key Challenges for AI within the EU Data Protection Framework.pdf
Priyanka Aash
 
GenAI Opportunities and Challenges - Where 370 Enterprises Are Focusing Now.pdf
GenAI Opportunities and Challenges - Where 370 Enterprises Are Focusing Now.pdf
Priyanka Aash
 
Techniques for Automatic Device Identification and Network Assignment.pdf
Techniques for Automatic Device Identification and Network Assignment.pdf
Priyanka Aash
 
AI vs Human Writing: Can You Tell the Difference?
AI vs Human Writing: Can You Tell the Difference?
Shashi Sathyanarayana, Ph.D
 
CapCut Pro Crack For PC Latest Version {Fully Unlocked} 2025
CapCut Pro Crack For PC Latest Version {Fully Unlocked} 2025
pcprocore
 
2025_06_18 - OpenMetadata Community Meeting.pdf
2025_06_18 - OpenMetadata Community Meeting.pdf
OpenMetadata
 
The Future of Technology: 2025-2125 by Saikat Basu.pdf
The Future of Technology: 2025-2125 by Saikat Basu.pdf
Saikat Basu
 
Curietech AI in action - Accelerate MuleSoft development
Curietech AI in action - Accelerate MuleSoft development
shyamraj55
 
OpenPOWER Foundation & Open-Source Core Innovations
OpenPOWER Foundation & Open-Source Core Innovations
IBM
 
EIS-Webinar-Engineering-Retail-Infrastructure-06-16-2025.pdf
EIS-Webinar-Engineering-Retail-Infrastructure-06-16-2025.pdf
Earley Information Science
 
Coordinated Disclosure for ML - What's Different and What's the Same.pdf
Coordinated Disclosure for ML - What's Different and What's the Same.pdf
Priyanka Aash
 
Mastering AI Workflows with FME by Mark Döring
Mastering AI Workflows with FME by Mark Döring
Safe Software
 
Securing AI - There Is No Try, Only Do!.pdf
Securing AI - There Is No Try, Only Do!.pdf
Priyanka Aash
 

Parallel Programming in .NET

  • 2.  Concurrency  Parallel Programming  Parallel Extensions in .NET 4.0  Coordination Data Structures  Task Parallelism  Parallel Loop /Data Parallelism  Parallel LINQ
  • 4. • Perform multiple Program A Program B computations What in overlapping time Step 1 T periods Step1 I Step2 M E • Responsive UI Step2 • Asynchronous Why Processing Step3 Step3 • Better performance(??) Concurrency is almost everywhere….. OS,Database,Web Servers,GUI programs, File processing….
  • 5. Program Concurrent Concurrent Concurrent Component 1 Component 2 Component N Read/Write Shared Memory Shared Memory Model of Concurrency
  • 6. OS Process Thread 1 Thread 2 Thread N Read/Write Shared Memory Operating System View
  • 7. Managed Program in CLR App Domain Managed Managed Managed Thread 1 Thread 2 Thread N Read/Write Shared Memory .NET Common Language Runtime View
  • 8. Create ThreadStart delegate with the method to be executed Create instance of Thread class with the ThreadStart delegate Start the thread execution
  • 9.  Synchronization Issues  Race Condition  Deadlock  Dependency on Memory Model & Hardware Architecture  Debugging becomes complicated
  • 10. Demo1
  • 11. Run Suspend Thread1 Thread1 Suspend Thread2 Thread2 Run Single Core Program Processor
  • 12. Run Thread1 Thread1 Core1 Run Thread2 Thread2 Core2 Program Multi Core Processor Concurrency - Perform multiple computations in overlapping time periods Parallel - Perform multiple computations simultaneously
  • 14.  No more increase in clock speed  Increase in number of processors  Sequential programs won’t scale  Parallel Programming  To leverage hardware advances Source: PDC 09 Patterns of Parallel Programming Workshop
  • 15.  Decompose the program into parts e.g. methods, statements etc.  Identify the parts which can be executed in parallel  Assign each part to separate tasks  Perform the tasks in parallel on different cores  Each task is likely to perform different actions
  • 16.  Partition the input data into multiple chunks  Perform action on each chunk in parallel on different cores  Merge the output results  Can be scaled up with more processors as data volume grows
  • 17. To develop applications for the multicore processors we need  Design  Identify parallel parts  Apply correct design patterns  Libraries  Sophisticated synchronization features to avoid deadlocks/race etc.  Thread safe data structures & containers  Language/API support for common parallel programming patterns to achieve task/data parallelism.  Tools  For debugging parallel applications  For profiling parallel applications Parallel Extensions in .NET 4.0
  • 19. Integrated Programming Models Programming Models Tooling PLINQ Parallel Task Parallel Parallel Pattern Agents Debugger Library Library Library Toolwindows Data Structures Data Structures Concurrency Runtime Concurrency Runtime ThreadPool Profiler Task Scheduler Concurrency Task Scheduler Analysis Resource Manager Resource Manager Operating System Threads Key: Managed Library Native Library Tools Source: PDC 08 Daniel Moth’s Presentation
  • 20. Thread-safe collections Phased Operation ConcurrentStack<T> ConcurrentQueue<T> ConcurrentDictionary<TKey,TValue> Locks Work exchange BlockingCollection<T> IProducerConsumerCollection<T> Initialization LazyInit<T> Source: PDC 08 Daniel Moth’s Presentation
  • 21. Demo2
  • 22. Demo3
  • 23. APIs provided under System.Threading & Sytem.Threading.Tasks  Behind the scenes uses CLR Thread Pool  Uses sophisticated algorithms to assign number of threads to maximize performance  More programmatic control than thread or work item  Create/Start Tasks  Return result values from tasks  Chain Multiple Tasks  Nested & Child Tasks  Exception Handling
  • 24. Constructor - public Task( Action action ) Action delegate - public delegate void Action() Lambda Expression without input parameter and returning nothing Create an explicit instance of Action delegate and pass it to task constructor Start the Tasks
  • 25. Class: public class Task<TResult> : Task Constructor: public Task( Func<TResult> function ) Delegate: public delegate TResult Func<out TResult>() Lambda Expression without input parameter and returning int Create new instance of Func delegate with no input parameter and returning int We have instantiated & started two tasks which expected to return integer value The property Result stores the return value
  • 26. Class: public Task ContinueWith( Action<Task> continuationAction ) Instantiate a Task with Action delegate Create an Action delegate with a task object as input and returning nothing. Call ContinueWith method and pass the Action delegate created Start the Task. After this task completes it will Continue With the execution of Action a2 automatically
  • 27. This is a lambda expression and Task t1 will execute this statements Task t11 is created while Task T1 is executing. This is a Nested Task Task t12 is created while Task T1 is executing but with AttachedToParent option. This is a Child Task. Child tasks are very closely synchronized with the parent
  • 28. Demo4
  • 29. Method : public static void Invoke( params Action[] actions ) Three Action delegates are created Three Action delegates will be invoked possibly in Parallel
  • 30. Demo5
  • 31. Method : public static ParallelLoopResult For( int fromInclusive, int toExclusive, Action<int> body ) Upper & Lower Bounds of the For Loop Loop Counter Statement executed in the loop When a For() loop has a small body, it might perform more slowly Slower performance is caused by the overhead involved in partitioning the data and the cost of invoking a delegate on each loop iteration.
  • 32. Method : public static ParallelLoopResult ForEach<TSource>( IEnumerable<TSource> source, Action<TSource> body ) Int Array with values from 0 to 100000 Loop iteration variable Loop Body
  • 33. Demo6
  • 34. Language-Integrated Query (LINQ) was introduced in the .NET Framework version 3.0  Querying on any System.Collections.IEnumerable or System.Collections.Generic.IEnumerable data source  Parallel LINQ (PLINQ) is a parallel implementation of the LINQ pattern  PLINQ tries to make full use of all the processors on the system  Partitions the data source into segments  Executes the query on each segment on separate worker threads in parallel on multiple processors
  • 35. Method : public static ParallelQuery<TSource> AsParallel<TSource>( this IEnumerable<TSource> source ) Method : public static void ForAll<TSource>( this ParallelQuery<TSource> source, Action<TSource> action ) Instructs to execute the LINQ query in Parallel Invokes in parallel the specified action for each element in the source.
  • 36. Demo7
  • 37. PLINQ, the goal is to maximize performance while maintaining correctness  In some cases, correctness requires the order of the source sequence to be preserved  Ordering can be computationally expensive  PLINQ by default does not preserve the order of the source sequence  To turn on order-preservation the AsOrdered operator is to be used on the source sequence
  • 38. Method : public static ParallelQuery AsOrdered( this ParallelQuery source ) Instructs to execute the LINQ query in Parallel by preserving order
  • 39. Demo8
  • 41. http://msdn.microsoft.com/en-us/library/dd460693.aspx http://channel9.msdn.com/pdc2008/TL26/ http://www.ademiller.com/blogs/tech/2009/11/pdc-patterns- of-parallel-programming-workshop/ Concurrent Programming on Windows by Joe Duffy
  • 43. This is like a pointer to function which accepts nothing and returns nothing Accepts delegate D as input M2 has no parameter & return value An instance of delegate D or a pointer to method M2 Call to M1 with delegate instance d1 as a parameter. Call to M1 with Lambda Expression Lambda Expression is an anonymous method (input parameters) => (statement)