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

PPTX
Task and Data Parallelism: Real-World Examples
PPT
memory
PPTX
Programming Environment in Matlab
PPTX
Multi layered perceptron (mlp)
PPTX
A Complete Guide on While Loop in MATLAB
PDF
Matlab HTI summer training course_Lecture2
PPTX
Matlab
PPTX
Intro to RX
Task and Data Parallelism: Real-World Examples
memory
Programming Environment in Matlab
Multi layered perceptron (mlp)
A Complete Guide on While Loop in MATLAB
Matlab HTI summer training course_Lecture2
Matlab
Intro to RX

What's hot (20)

PDF
Lesson 21. Pattern 13. Data alignment
PPTX
Dynamic memory Allocation in c language
PPTX
Introduction to MATLAB
PPT
Dynamic Memory Allocation
PPTX
16 dynamic-memory-allocation
PPTX
Matlab for Electrical Engineers
PPTX
C dynamic ppt
DOCX
Parallel programming Comparisions
PPT
MATLAB/SIMULINK for engineering applications: day 3
PPTX
Java 8 streams
PPTX
Ppt presentation of queues
PPTX
Dynamic Memory Allocation(DMA)
PPSX
Data structure stack&queue basics
PPTX
Java.util.concurrent.concurrent hashmap
PPTX
Matlab HTI summer training course Lecture3
PPTX
Matlab introduction
PPTX
Stack & heap
PPS
PRAM algorithms from deepika
Lesson 21. Pattern 13. Data alignment
Dynamic memory Allocation in c language
Introduction to MATLAB
Dynamic Memory Allocation
16 dynamic-memory-allocation
Matlab for Electrical Engineers
C dynamic ppt
Parallel programming Comparisions
MATLAB/SIMULINK for engineering applications: day 3
Java 8 streams
Ppt presentation of queues
Dynamic Memory Allocation(DMA)
Data structure stack&queue basics
Java.util.concurrent.concurrent hashmap
Matlab HTI summer training course Lecture3
Matlab introduction
Stack & heap
PRAM algorithms from deepika
Ad

Viewers also liked (20)

PDF
My englishfriends cas
ODP
Sant jordi
PDF
Start-up Battlefield in the Middle East
PPTX
Technology[1]
PPS
Arany kezek(36) ani (nx power lite)
PPS
心肌梗塞急救法
PPTX
EME2040 Project VI, Part III
PDF
List Growth In the Shadow of CASL (Canada Anti-Spam Law)
PPT
PDF
Ipad Usability 2nd Edition
PPTX
Tour Ancient Mexico!
PDF
ICE President Apprentices 2006-07
PDF
Conductedwork
PPS
Minden, ami szép(5) (nx power lite)+ani
PPTX
How to provide 24/7 support in a 9-5 work day: the benefit of e-mental health...
PPT
Protests past and present
PDF
17 dsp dunia muzik tahun 3 5 feb 2013
PDF
Catalog dental-general
PDF
Parenting U: Child Nutrition - Recipes
PPS
差異是祝福
My englishfriends cas
Sant jordi
Start-up Battlefield in the Middle East
Technology[1]
Arany kezek(36) ani (nx power lite)
心肌梗塞急救法
EME2040 Project VI, Part III
List Growth In the Shadow of CASL (Canada Anti-Spam Law)
Ipad Usability 2nd Edition
Tour Ancient Mexico!
ICE President Apprentices 2006-07
Conductedwork
Minden, ami szép(5) (nx power lite)+ani
How to provide 24/7 support in a 9-5 work day: the benefit of e-mental health...
Protests past and present
17 dsp dunia muzik tahun 3 5 feb 2013
Catalog dental-general
Parenting U: Child Nutrition - Recipes
差異是祝福
Ad

Similar to Dot net parallelism and multicore computing (20)

PPT
Migration To Multi Core - Parallel Programming Models
PPTX
C# Parallel programming
PDF
IRJET- Latin Square Computation of Order-3 using Open CL
DOCX
Parallel Programming With Dot Net
PPT
Code Tuning
PDF
Operating Systems 3rd Edition Nutt Solutions Manual
PPTX
Parallel computing and its applications
PPTX
Modern processors
PDF
Parallel Programming
PPT
Parallel Computing
PPTX
Complier design
PPTX
Matlab ppt
PDF
Operating Systems 3rd Edition Nutt Solutions Manual
PPT
Lecture18-19 (1).ppt
PDF
Operating Systems 3rd Edition Nutt Solutions Manual
PDF
Performance Analysis of Parallel Algorithms on Multi-core System using OpenMP
PPT
Lect 3-4 Zaheer Abbas
PPTX
Concurrency and Parallelism, Asynchronous Programming, Network Programming
PDF
Operating Systems 3rd Edition Nutt Solutions Manual
PDF
Unit2-Part2-MultithreadAlgos.pptx.pdf
Migration To Multi Core - Parallel Programming Models
C# Parallel programming
IRJET- Latin Square Computation of Order-3 using Open CL
Parallel Programming With Dot Net
Code Tuning
Operating Systems 3rd Edition Nutt Solutions Manual
Parallel computing and its applications
Modern processors
Parallel Programming
Parallel Computing
Complier design
Matlab ppt
Operating Systems 3rd Edition Nutt Solutions Manual
Lecture18-19 (1).ppt
Operating Systems 3rd Edition Nutt Solutions Manual
Performance Analysis of Parallel Algorithms on Multi-core System using OpenMP
Lect 3-4 Zaheer Abbas
Concurrency and Parallelism, Asynchronous Programming, Network Programming
Operating Systems 3rd Edition Nutt Solutions Manual
Unit2-Part2-MultithreadAlgos.pptx.pdf

Recently uploaded (20)

PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
gpt5_lecture_notes_comprehensive_20250812015547.pdf
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Unlocking AI with Model Context Protocol (MCP)
PPTX
Big Data Technologies - Introduction.pptx
PDF
Machine learning based COVID-19 study performance prediction
PDF
Assigned Numbers - 2025 - Bluetooth® Document
PDF
Spectral efficient network and resource selection model in 5G networks
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Electronic commerce courselecture one. Pdf
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PPTX
Machine Learning_overview_presentation.pptx
PDF
Empathic Computing: Creating Shared Understanding
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
“AI and Expert System Decision Support & Business Intelligence Systems”
gpt5_lecture_notes_comprehensive_20250812015547.pdf
20250228 LYD VKU AI Blended-Learning.pptx
Review of recent advances in non-invasive hemoglobin estimation
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Network Security Unit 5.pdf for BCA BBA.
Unlocking AI with Model Context Protocol (MCP)
Big Data Technologies - Introduction.pptx
Machine learning based COVID-19 study performance prediction
Assigned Numbers - 2025 - Bluetooth® Document
Spectral efficient network and resource selection model in 5G networks
Programs and apps: productivity, graphics, security and other tools
Dropbox Q2 2025 Financial Results & Investor Presentation
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Electronic commerce courselecture one. Pdf
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Per capita expenditure prediction using model stacking based on satellite ima...
Machine Learning_overview_presentation.pptx
Empathic Computing: Creating Shared Understanding
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf

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