SlideShare a Scribd company logo
DOT NET PARALLELISM & MULTICORE COMPUTING
BY
ARAVINDHAN G
OMNIEXTRACT TEAM
GENESIS GROUP
Why parallelism?
What is parallelism?
Types of parallelism in C#
Data Parallelism
Parallel Loops
Task Parallelism
2
AGENDA
3
Why Parallelism?
 Don’t expect your sequential program to run faster on new
processors.
 Still, processor technology advances
 BUT the focus now is on multiple cores per chip
 Today’s desktops typically have 4 cores
 The multi-core revolution puts pressure on software developers
to use parallelism if they want to benefit from future hardware
improvements
4
The Free Lunch is over
 Parallelism means that a programming task can be split into
parts that can be run on several networked processors or
computers.
 Parallel computing is a form of computation in which many
calculations are carried out simultaneously, operating on the
principle that large problems can often be divided into smaller
ones, which are then solved concurrently ("in parallel").
5
What is parallelism?
C# supports two main models of parallelism:
• Data parallelism: where an operation is applied to each
element in a collection.
• Task parallelism: where independent computations are
executed in parallel.
6
Types of Parallelism in C#
A sequential for loop in C#:
int n = ...
for (int i = 0; i<=n; i++)
{
// ...
}
A parallel for loop in C#:
int n = ...
Parallel.For(0, n, i =>
{
// ...
});
7
Parallel Loops in C#
 The language construct for is translated into a
(higher-order) function Parallel.For.
 The argument to Parallel.For is an anonymous method,
specifying the code to be performed in each loop
iteration.
 The arguments to this anonymous method are the start
value, the end value and the iteration variable.
8
Parallel Loops in C#
We can limit the degree of parallelism like this:
var options = new ParallelOptions() {
MaxDegreeOfParallelism = 2 };
Parallel.For(0, n, options, i =>
{
fibs[i] = Fib(i);
});
9
A Simple Example
 Parallel loops have two ways to break or stop a loop
instead of just one.
 Parallel break, loopState.Break(), allows all steps with
indices lower than the break index to run before
terminating the loop.
 Parallel stop, loopState.Stop(), terminates the loop
without allowing any new steps to begin.
10
Terminating a Parallel Loop
 The parallel aggregate pattern combines data
parallelism over a collection, with the aggregation of the
result values to an overall result.
 It is parameterized both over the operation on each
element as well as the combination (aggregation) of the
partial results to an overall results.
An Example of Parallel Aggregates:
var options = new ParallelOptions() {
MaxDegreeOfParallelism = k};
Parallel.ForEach(seq /* sequence */, options,
() => 0, // The local initial partial result
// The loop body
});
11
Parallel Aggregates
 When independent computations are started in different
tasks, we use a model of task parallelism.
 This model is more general than data parallelism, but
requires more detailed control of synchronization and
communication.
 The most basic construct for task parallelism is:
Parallel.Invoke(DoLeft, DoRight);
 It executes the methods DoLeft and DoRight in parallel,
and waits for both of them to finish.
12
Task Parallelism in C#
The following code sorts 2 lists in parallel, providing a
comparison operation as an argument:
Parallel.Invoke( // generate two parallel threads
() => ic1.Sort(cmp_int_lt),
() => ic2.Sort(cmp_int_gt));
13
Example of Task Parallelism
 The implementation of Invoke uses the more basic
constructs
StartNew, for starting a computation;
Wait, WaitAll, WaitAny, for synchronising several
computations.
 Any shared data structure needs to be protected with
locks, semaphores or such.
 Programming on this level is similar to explicitly
managing threads:
it can be more efficient
it is error-prone.
14
Implementation of Task Parallelism
static void SequentialQuickSort(int[] array, int from, int to)
{
if (to - from <= Threshold)
{
InsertionSort(array, from, to);
}
else
{
int pivot = from + (to - from) / 2;
pivot = Partition(array, from, to, pivot);
SequentialQuickSort(array, from, pivot - 1);
SequentialQuickSort(array, pivot + 1, to);
}
}
15
Example: Sequential Code
static void ParallelQuickSort(int[] array, int from, int to, int depthRemaining)
{
if (to - from <= Threshold)
{
InsertionSort(array, from, to);
}
else
{
int pivot = from + (to - from) / 2;
pivot = Partition(array, from, to, pivot);
if (depthRemaining > 0)
{
Parallel.Invoke(
() => ParallelQuickSort(array, from, pivot - 1,
depthRemaining - 1),
() => ParallelQuickSort(array, pivot + 1, to,
depthRemaining - 1));
}
else
{
ParallelQuickSort(array, from, pivot - 1, 0);
ParallelQuickSort(array, pivot + 1, to, 0);
}
}
}
16
Example: Parallel Code
 The preferred, high-level way of coding parallel
computation in C# is through parallel patterns, an
instance of design patterns.
 Parallel patterns capture common patterns of parallel
computation.
 Two main classes of parallelism exist:
Data parallelism, which is implemented through parallel
For/Foreach loops.
Task parallelism, which is implemented through parallel
method invocation.
 Tuning the parallel performance often requires code
restructuring.
17
Summary
Any queries?
Thank You

More Related Content

What's hot (20)

PDF
Lesson 21. Pattern 13. Data alignment
PVS-Studio
 
PPTX
Dynamic memory Allocation in c language
kiran Patel
 
PPTX
Introduction to MATLAB
Ravikiran A
 
PPT
Dynamic Memory Allocation
vaani pathak
 
PPTX
16 dynamic-memory-allocation
Rohit Shrivastava
 
PPTX
Matlab for Electrical Engineers
Manish Joshi
 
PPTX
C dynamic ppt
RJ Mehul Gadhiya
 
DOCX
Parallel programming Comparisions
Muhammad Bilal Khan
 
PPT
MATLAB/SIMULINK for engineering applications: day 3
reddyprasad reddyvari
 
PPTX
Java 8 streams
Srinivasan Raghvan
 
PPTX
Ppt presentation of queues
Buxoo Abdullah
 
PPTX
Dynamic Memory Allocation(DMA)
Kamal Acharya
 
PPSX
Data structure stack&queue basics
Selvin Josy Bai Somu
 
PPTX
Java.util.concurrent.concurrent hashmap
Srinivasan Raghvan
 
PPTX
Matlab HTI summer training course Lecture3
Mohamed Awni
 
PPTX
Matlab introduction
Ameen San
 
PPTX
Stack & heap
Shajahan T S Shah
 
PPS
PRAM algorithms from deepika
guest1f4fb3
 
Lesson 21. Pattern 13. Data alignment
PVS-Studio
 
Dynamic memory Allocation in c language
kiran Patel
 
Introduction to MATLAB
Ravikiran A
 
Dynamic Memory Allocation
vaani pathak
 
16 dynamic-memory-allocation
Rohit Shrivastava
 
Matlab for Electrical Engineers
Manish Joshi
 
C dynamic ppt
RJ Mehul Gadhiya
 
Parallel programming Comparisions
Muhammad Bilal Khan
 
MATLAB/SIMULINK for engineering applications: day 3
reddyprasad reddyvari
 
Java 8 streams
Srinivasan Raghvan
 
Ppt presentation of queues
Buxoo Abdullah
 
Dynamic Memory Allocation(DMA)
Kamal Acharya
 
Data structure stack&queue basics
Selvin Josy Bai Somu
 
Java.util.concurrent.concurrent hashmap
Srinivasan Raghvan
 
Matlab HTI summer training course Lecture3
Mohamed Awni
 
Matlab introduction
Ameen San
 
Stack & heap
Shajahan T S Shah
 
PRAM algorithms from deepika
guest1f4fb3
 

Viewers also liked (20)

PDF
My englishfriends cas
rafaeljoseaguayo
 
ODP
Sant jordi
jbenaigesv
 
PDF
Start-up Battlefield in the Middle East
Youngberry, Youth Marketing Agency
 
PPTX
Technology[1]
rloudermilk3
 
PPS
Arany kezek(36) ani (nx power lite)
VarganeAnny
 
PPS
心肌梗塞急救法
chengchunhao
 
PPTX
EME2040 Project VI, Part III
John Hayes
 
PDF
List Growth In the Shadow of CASL (Canada Anti-Spam Law)
Care2Team
 
PPT
Parenting U: Toddler Behavior
Providence Health & Services Southwest Washington
 
PDF
Ipad Usability 2nd Edition
jamiewaltz
 
PPTX
Tour Ancient Mexico!
LibraryLeroy
 
PDF
ICE President Apprentices 2006-07
katfyt
 
PDF
Conductedwork
Prashant Sharma
 
PPS
Minden, ami szép(5) (nx power lite)+ani
VarganeAnny
 
PPTX
How to provide 24/7 support in a 9-5 work day: the benefit of e-mental health...
ReachOut Pro
 
PPT
Protests past and present
vanessaftok
 
PDF
17 dsp dunia muzik tahun 3 5 feb 2013
OwesomePure Collection
 
PDF
Catalog dental-general
MIGUEL CHAVEZ
 
PDF
Parenting U: Child Nutrition - Recipes
Providence Health & Services Southwest Washington
 
PPS
差異是祝福
chengchunhao
 
My englishfriends cas
rafaeljoseaguayo
 
Sant jordi
jbenaigesv
 
Start-up Battlefield in the Middle East
Youngberry, Youth Marketing Agency
 
Technology[1]
rloudermilk3
 
Arany kezek(36) ani (nx power lite)
VarganeAnny
 
心肌梗塞急救法
chengchunhao
 
EME2040 Project VI, Part III
John Hayes
 
List Growth In the Shadow of CASL (Canada Anti-Spam Law)
Care2Team
 
Ipad Usability 2nd Edition
jamiewaltz
 
Tour Ancient Mexico!
LibraryLeroy
 
ICE President Apprentices 2006-07
katfyt
 
Conductedwork
Prashant Sharma
 
Minden, ami szép(5) (nx power lite)+ani
VarganeAnny
 
How to provide 24/7 support in a 9-5 work day: the benefit of e-mental health...
ReachOut Pro
 
Protests past and present
vanessaftok
 
17 dsp dunia muzik tahun 3 5 feb 2013
OwesomePure Collection
 
Catalog dental-general
MIGUEL CHAVEZ
 
Parenting U: Child Nutrition - Recipes
Providence Health & Services Southwest Washington
 
差異是祝福
chengchunhao
 
Ad

Similar to Dot net parallelism and multicore computing (20)

PPT
Migration To Multi Core - Parallel Programming Models
Zvi Avraham
 
PPTX
C# Parallel programming
Umeshwaran V
 
PDF
IRJET- Latin Square Computation of Order-3 using Open CL
IRJET Journal
 
DOCX
Parallel Programming With Dot Net
Neeraj Kaushik
 
PPT
Code Tuning
guest4df97e3d
 
PDF
Operating Systems 3rd Edition Nutt Solutions Manual
bardhdinci22
 
PPTX
Parallel computing and its applications
Burhan Ahmed
 
PPTX
Modern processors
gowrivageesan87
 
PDF
Parallel Programming
Roman Okolovich
 
PPT
Parallel Computing
Ameya Waghmare
 
PPTX
Complier design
shreeuva
 
PPTX
Matlab ppt
Dhammpal Ramtake
 
PDF
Operating Systems 3rd Edition Nutt Solutions Manual
izreenczek
 
PPT
Lecture18-19 (1).ppt
ssuserf67e3a
 
PDF
Operating Systems 3rd Edition Nutt Solutions Manual
zabikqrazvi2h
 
PDF
Performance Analysis of Parallel Algorithms on Multi-core System using OpenMP
IJCSEIT Journal
 
PPT
Lect 3-4 Zaheer Abbas
Information Technology Center
 
PPTX
Concurrency and Parallelism, Asynchronous Programming, Network Programming
Prabu U
 
PDF
Unit2-Part2-MultithreadAlgos.pptx.pdf
Vinayak247538
 
PPT
parellel computing
katakdound
 
Migration To Multi Core - Parallel Programming Models
Zvi Avraham
 
C# Parallel programming
Umeshwaran V
 
IRJET- Latin Square Computation of Order-3 using Open CL
IRJET Journal
 
Parallel Programming With Dot Net
Neeraj Kaushik
 
Code Tuning
guest4df97e3d
 
Operating Systems 3rd Edition Nutt Solutions Manual
bardhdinci22
 
Parallel computing and its applications
Burhan Ahmed
 
Modern processors
gowrivageesan87
 
Parallel Programming
Roman Okolovich
 
Parallel Computing
Ameya Waghmare
 
Complier design
shreeuva
 
Matlab ppt
Dhammpal Ramtake
 
Operating Systems 3rd Edition Nutt Solutions Manual
izreenczek
 
Lecture18-19 (1).ppt
ssuserf67e3a
 
Operating Systems 3rd Edition Nutt Solutions Manual
zabikqrazvi2h
 
Performance Analysis of Parallel Algorithms on Multi-core System using OpenMP
IJCSEIT Journal
 
Lect 3-4 Zaheer Abbas
Information Technology Center
 
Concurrency and Parallelism, Asynchronous Programming, Network Programming
Prabu U
 
Unit2-Part2-MultithreadAlgos.pptx.pdf
Vinayak247538
 
parellel computing
katakdound
 
Ad

Recently uploaded (20)

PDF
The Future of Product Management in AI ERA.pdf
Alyona Owens
 
PDF
Why aren't you using FME Flow's CPU Time?
Safe Software
 
PPTX
MARTSIA: A Tool for Confidential Data Exchange via Public Blockchain - Poster...
Michele Kryston
 
PPTX
MARTSIA: A Tool for Confidential Data Exchange via Public Blockchain - Pitch ...
Michele Kryston
 
PDF
Kubernetes - Architecture & Components.pdf
geethak285
 
PDF
Redefining Work in the Age of AI - What to expect? How to prepare? Why it mat...
Malinda Kapuruge
 
PPTX
Simplifica la seguridad en la nube y la detección de amenazas con FortiCNAPP
Cristian Garcia G.
 
PDF
2025_06_18 - OpenMetadata Community Meeting.pdf
OpenMetadata
 
PDF
From Chatbot to Destroyer of Endpoints - Can ChatGPT Automate EDR Bypasses (1...
Priyanka Aash
 
PDF
Hello I'm "AI" Your New _________________
Dr. Tathagat Varma
 
PDF
Enhancing Environmental Monitoring with Real-Time Data Integration: Leveragin...
Safe Software
 
PDF
5 Things to Consider When Deploying AI in Your Enterprise
Safe Software
 
PDF
Automating the Geo-Referencing of Historic Aerial Photography in Flanders
Safe Software
 
PDF
ArcGIS Utility Network Migration - The Hunter Water Story
Safe Software
 
PDF
Salesforce Summer '25 Release Frenchgathering.pptx.pdf
yosra Saidani
 
PDF
Optimizing the trajectory of a wheel loader working in short loading cycles
Reno Filla
 
PPTX
Curietech AI in action - Accelerate MuleSoft development
shyamraj55
 
PPTX
Smarter Governance with AI: What Every Board Needs to Know
OnBoard
 
PPTX
01_Approach Cyber- DORA Incident Management.pptx
FinTech Belgium
 
PDF
LLM Search Readiness Audit - Dentsu x SEO Square - June 2025.pdf
Nick Samuel
 
The Future of Product Management in AI ERA.pdf
Alyona Owens
 
Why aren't you using FME Flow's CPU Time?
Safe Software
 
MARTSIA: A Tool for Confidential Data Exchange via Public Blockchain - Poster...
Michele Kryston
 
MARTSIA: A Tool for Confidential Data Exchange via Public Blockchain - Pitch ...
Michele Kryston
 
Kubernetes - Architecture & Components.pdf
geethak285
 
Redefining Work in the Age of AI - What to expect? How to prepare? Why it mat...
Malinda Kapuruge
 
Simplifica la seguridad en la nube y la detección de amenazas con FortiCNAPP
Cristian Garcia G.
 
2025_06_18 - OpenMetadata Community Meeting.pdf
OpenMetadata
 
From Chatbot to Destroyer of Endpoints - Can ChatGPT Automate EDR Bypasses (1...
Priyanka Aash
 
Hello I'm "AI" Your New _________________
Dr. Tathagat Varma
 
Enhancing Environmental Monitoring with Real-Time Data Integration: Leveragin...
Safe Software
 
5 Things to Consider When Deploying AI in Your Enterprise
Safe Software
 
Automating the Geo-Referencing of Historic Aerial Photography in Flanders
Safe Software
 
ArcGIS Utility Network Migration - The Hunter Water Story
Safe Software
 
Salesforce Summer '25 Release Frenchgathering.pptx.pdf
yosra Saidani
 
Optimizing the trajectory of a wheel loader working in short loading cycles
Reno Filla
 
Curietech AI in action - Accelerate MuleSoft development
shyamraj55
 
Smarter Governance with AI: What Every Board Needs to Know
OnBoard
 
01_Approach Cyber- DORA Incident Management.pptx
FinTech Belgium
 
LLM Search Readiness Audit - Dentsu x SEO Square - June 2025.pdf
Nick Samuel
 

Dot net parallelism and multicore computing

  • 1. DOT NET PARALLELISM & MULTICORE COMPUTING BY ARAVINDHAN G OMNIEXTRACT TEAM GENESIS GROUP
  • 2. Why parallelism? What is parallelism? Types of parallelism in C# Data Parallelism Parallel Loops Task Parallelism 2 AGENDA
  • 4.  Don’t expect your sequential program to run faster on new processors.  Still, processor technology advances  BUT the focus now is on multiple cores per chip  Today’s desktops typically have 4 cores  The multi-core revolution puts pressure on software developers to use parallelism if they want to benefit from future hardware improvements 4 The Free Lunch is over
  • 5.  Parallelism means that a programming task can be split into parts that can be run on several networked processors or computers.  Parallel computing is a form of computation in which many calculations are carried out simultaneously, operating on the principle that large problems can often be divided into smaller ones, which are then solved concurrently ("in parallel"). 5 What is parallelism?
  • 6. C# supports two main models of parallelism: • Data parallelism: where an operation is applied to each element in a collection. • Task parallelism: where independent computations are executed in parallel. 6 Types of Parallelism in C#
  • 7. A sequential for loop in C#: int n = ... for (int i = 0; i<=n; i++) { // ... } A parallel for loop in C#: int n = ... Parallel.For(0, n, i => { // ... }); 7 Parallel Loops in C#
  • 8.  The language construct for is translated into a (higher-order) function Parallel.For.  The argument to Parallel.For is an anonymous method, specifying the code to be performed in each loop iteration.  The arguments to this anonymous method are the start value, the end value and the iteration variable. 8 Parallel Loops in C#
  • 9. We can limit the degree of parallelism like this: var options = new ParallelOptions() { MaxDegreeOfParallelism = 2 }; Parallel.For(0, n, options, i => { fibs[i] = Fib(i); }); 9 A Simple Example
  • 10.  Parallel loops have two ways to break or stop a loop instead of just one.  Parallel break, loopState.Break(), allows all steps with indices lower than the break index to run before terminating the loop.  Parallel stop, loopState.Stop(), terminates the loop without allowing any new steps to begin. 10 Terminating a Parallel Loop
  • 11.  The parallel aggregate pattern combines data parallelism over a collection, with the aggregation of the result values to an overall result.  It is parameterized both over the operation on each element as well as the combination (aggregation) of the partial results to an overall results. An Example of Parallel Aggregates: var options = new ParallelOptions() { MaxDegreeOfParallelism = k}; Parallel.ForEach(seq /* sequence */, options, () => 0, // The local initial partial result // The loop body }); 11 Parallel Aggregates
  • 12.  When independent computations are started in different tasks, we use a model of task parallelism.  This model is more general than data parallelism, but requires more detailed control of synchronization and communication.  The most basic construct for task parallelism is: Parallel.Invoke(DoLeft, DoRight);  It executes the methods DoLeft and DoRight in parallel, and waits for both of them to finish. 12 Task Parallelism in C#
  • 13. The following code sorts 2 lists in parallel, providing a comparison operation as an argument: Parallel.Invoke( // generate two parallel threads () => ic1.Sort(cmp_int_lt), () => ic2.Sort(cmp_int_gt)); 13 Example of Task Parallelism
  • 14.  The implementation of Invoke uses the more basic constructs StartNew, for starting a computation; Wait, WaitAll, WaitAny, for synchronising several computations.  Any shared data structure needs to be protected with locks, semaphores or such.  Programming on this level is similar to explicitly managing threads: it can be more efficient it is error-prone. 14 Implementation of Task Parallelism
  • 15. static void SequentialQuickSort(int[] array, int from, int to) { if (to - from <= Threshold) { InsertionSort(array, from, to); } else { int pivot = from + (to - from) / 2; pivot = Partition(array, from, to, pivot); SequentialQuickSort(array, from, pivot - 1); SequentialQuickSort(array, pivot + 1, to); } } 15 Example: Sequential Code
  • 16. static void ParallelQuickSort(int[] array, int from, int to, int depthRemaining) { if (to - from <= Threshold) { InsertionSort(array, from, to); } else { int pivot = from + (to - from) / 2; pivot = Partition(array, from, to, pivot); if (depthRemaining > 0) { Parallel.Invoke( () => ParallelQuickSort(array, from, pivot - 1, depthRemaining - 1), () => ParallelQuickSort(array, pivot + 1, to, depthRemaining - 1)); } else { ParallelQuickSort(array, from, pivot - 1, 0); ParallelQuickSort(array, pivot + 1, to, 0); } } } 16 Example: Parallel Code
  • 17.  The preferred, high-level way of coding parallel computation in C# is through parallel patterns, an instance of design patterns.  Parallel patterns capture common patterns of parallel computation.  Two main classes of parallelism exist: Data parallelism, which is implemented through parallel For/Foreach loops. Task parallelism, which is implemented through parallel method invocation.  Tuning the parallel performance often requires code restructuring. 17 Summary