SlideShare a Scribd company logo
Parallel Extensions in .Net 4.0Dmytro Maleev for Lviv.Net User Group
AgendaКуда катится мир?Hello, Parallel Extensions!Parallel vs MultithreadingParallel LoopsTasksPLINQCDS & Thread EnchantmentsReferencesQ&A
Куда катится мирForget about CPU frequency increase! There are a lot of issues with this, which will be fixed in future!1998 Intel 8048680Mhz1 Core2007Core 2 Duo 2.13 GHz2 Core2000Celeron 400Mhz1 Core2010Intel i5 3.3GHz2 Core 4 Threads2003Athlon XP 1.6+GHz1 Core?
Куда катится мирFor now…ENLARGE YOUR…CPU CORE COUNT!PENPEN
Hello, Parallel Extensions!Parallel Extensions, previously known as the Parallel Framework Extensions or PFX, is a managed concurrency library being developed by a collaboration between Microsoft Research and the CLR team at Microsoft. It is composed of two parts: Parallel LINQ (PLINQ) andTask Parallel Library (TPL).It also consists of a set of coordination data structures (CDS) – sets of data structures used to synchronize and co-ordinate the execution of concurrent tasks.Thelibrary was released as a CTP on November 29, 2007and refreshed again in December 2007 and June 2008. Microsoft has announced that the Parallel Extensions to .NET will release as part of the .NET 4.0 Framework release.©Wikipedia
Hello, Parallel Extensions!Visual Studio Debugging and profiling supportParallel ExtensionsPLINQTask Parallel LibraryTask SchedulerCDS
Parallel vs MultithreadingMultithreaded!=parallelization“ If on a single core machine you are using threads and it makes perfect sense for your scenario, then you are not "doing parallelism", you are just doing multithreading””On a single core you can use threads and you can have concurrency, but to achieveparallelism on a multi-core box you have to identify in your code the exploitableconcurrency: the portions of your code that can truly run at the same time.”Daniel Moth
Parallel vs Multithreading
Dark Side of Paprallelization and MultithreadingRace conditionshttp://en.wikipedia.org/wiki/Race_condition2.	Deadlockshttp://en.wikipedia.org/wiki/Deadlockhttp://en.wikipedia.org/wiki/Dining_philosophers_problemThread starvationDifficult to code and debugEnvironmental
Народная мудрость!
Parallel LoopsParallel.For()Parallel.For(0, 100, i =>            {                Console.WriteLine("This is I-I-I-I-I-I: {0}", i);            });Parallel.ForEach()Parallel.ForEach(ThisIsCollection, collectionItem =>{collectionItem.Hello();});Parallel OptionsParallel.Invoke()
Parallel Loops. Use Force wisely!Parallelization Can Hurt Performancehttp://msdn.microsoft.com/en-us/library/dd560853(VS.100).aspxhttp://en.wikipedia.org/wiki/Context_switch
DEMOAntiSocialRobots
Task - Task SchedulerTask is a new class that represents the work you want completed. There are methods to create,  schedule, and synchronize tasks in your application.Tasks are controlled by task scheduler.Tasks scheduler works with thread pool.
Task In DeepTasks can:Task can be createdTask can wait! Task can simply Wait(), WaitAll() or WaitAny().Task knows when it is completed ( IsCompleted property)Task can ContinueWith()Task can return valueTask has Options and Status
DemoStrassen algorithm
PLINQPLINQ is just parallelized version of LINQNot parallelized: LINQ-to-SQL & LINQ-to-Entity.LINQ:var query = from s in someCollectionlet result = CoolService.CallService(s)select result;PLINQ:varquery = from s in someCollection.AsParallel()let result = CoolService.CallService(s)select result;
PLINQ. How it works?
PLINQ. Overview	Ordering ResultsAsOrdered()ForAll Operator()AsSequential()WithMergeOptionsParallel Performance Analyzer. Just for rich
DEMO	Baby Names
CDS & Thread EnchantmentsThread Enchantments:Thread.Yield()Monitor.Enter()Concurrent CollectionsConcurrentStack (LIFO)ConcurrentQueue (FIFO)ConcurrentDictionaryConcurrentBagBlockingCollection
Synchronization PrimitivesBarrier“Let’s meet near monument and then go to have a beer”Cancellation TokensCountDownEventManualResetEventSlim and SemaphoreSlimSpinLockThreadLocal<T>
References	Parallel Programming with .NEThttp://blogs.msdn.com/b/pfxteam/Wikihttp://en.wikipedia.org/wiki/Parallel_ExtensionsIntroducing .NET 4.0http://www.amazon.com/Introducing-NET-4-0-Visual-Experts/dp/143022455XLviv.Net User Grouphttp://dotnetug-lviv.blogspot.com/
Q&A?
If you still have a questions	Mail me:diwingless@gmail.comSkype me:hmmidmaTwitter:dimko1

More Related Content

PPTX
Hands On Intro to Node.js
PDF
Redis on AWS
PPTX
Whats new in .net framework 4
PPT
on the trails
PDF
Mobile applications development - why should you start learning it right now?
PDF
Prezentácia PRINS, Agrofinal Hlohovec, Sandecký
PPT
Microsoft Azure
PPT
MCS Machining Offering 2009
Hands On Intro to Node.js
Redis on AWS
Whats new in .net framework 4
on the trails
Mobile applications development - why should you start learning it right now?
Prezentácia PRINS, Agrofinal Hlohovec, Sandecký
Microsoft Azure
MCS Machining Offering 2009

Similar to Parallel extensions in .Net 4.0 (20)

PPT
MTaulty_DevWeek_Parallel
PPT
Parallel Extentions to the .NET Framework
PDF
JDD 2016 - Grzegorz Rozniecki - Java 8 What Could Possibly Go Wrong
PDF
Here comes the Loom - Ya!vaConf.pdf
PPT
Clustering van IT-componenten
PPTX
Parallel Computing For Managed Developers
PPT
ODP
Getting started with Clojure
PDF
ABRIDGED VERSION - Joys & frustrations of putting 34,000 lines of Haskell in...
PPTX
DotNetFest - Let’s refresh our memory! Memory management in .NET
PPT
Oscon keynote: Working hard to keep it simple
PDF
JVM in the Age of AI: Babylon, Valhalla, TornadoVM and friends
PPTX
Exploring .NET memory management - JetBrains webinar
PDF
Using spl tools in your code
PPTX
Thinking in parallel ab tuladev
PPTX
Optimizing Application Architecture (.NET/Java topics)
PDF
Sparklife - Life In The Trenches With Spark
PPT
Parallel Programming: Beyond the Critical Section
PPTX
SQL Server In-Memory OLTP introduction (Hekaton)
PDF
Hadoop Performance Optimization at Scale, Lessons Learned at Twitter
MTaulty_DevWeek_Parallel
Parallel Extentions to the .NET Framework
JDD 2016 - Grzegorz Rozniecki - Java 8 What Could Possibly Go Wrong
Here comes the Loom - Ya!vaConf.pdf
Clustering van IT-componenten
Parallel Computing For Managed Developers
Getting started with Clojure
ABRIDGED VERSION - Joys & frustrations of putting 34,000 lines of Haskell in...
DotNetFest - Let’s refresh our memory! Memory management in .NET
Oscon keynote: Working hard to keep it simple
JVM in the Age of AI: Babylon, Valhalla, TornadoVM and friends
Exploring .NET memory management - JetBrains webinar
Using spl tools in your code
Thinking in parallel ab tuladev
Optimizing Application Architecture (.NET/Java topics)
Sparklife - Life In The Trenches With Spark
Parallel Programming: Beyond the Critical Section
SQL Server In-Memory OLTP introduction (Hekaton)
Hadoop Performance Optimization at Scale, Lessons Learned at Twitter
Ad

More from Dima Maleev (17)

PDF
PPTX
JavaScript in Mobile Development
PDF
What is new in Angular 2.0
PPTX
Fear and Loathing at PhoneGap
PPTX
Development Applications for Chrome OS
PPTX
Mobile for JS Developer
PDF
Gamification
PPTX
Development Application for Windows 8 by Eugene Kiriyan
PDF
.NET MicroFramework by Yulian Slobodyan
PPT
Modern mobile development overview
PPTX
Go mobile with Windows Phone
PPTX
Lviv .Net User Group. NHibernate
PPTX
Time. To manage, or not to manage
PPTX
Создание SharePoint 2010 решений в Visual Studio
PPTX
24000 Days Of UX
PPTX
Developing silverlight applications for windows phone 7 series
PPT
New Features Of ASP.Net 4 0
JavaScript in Mobile Development
What is new in Angular 2.0
Fear and Loathing at PhoneGap
Development Applications for Chrome OS
Mobile for JS Developer
Gamification
Development Application for Windows 8 by Eugene Kiriyan
.NET MicroFramework by Yulian Slobodyan
Modern mobile development overview
Go mobile with Windows Phone
Lviv .Net User Group. NHibernate
Time. To manage, or not to manage
Создание SharePoint 2010 решений в Visual Studio
24000 Days Of UX
Developing silverlight applications for windows phone 7 series
New Features Of ASP.Net 4 0
Ad

Recently uploaded (20)

PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PDF
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
PDF
Insiders guide to clinical Medicine.pdf
PDF
Sports Quiz easy sports quiz sports quiz
PPTX
Lesson notes of climatology university.
PPTX
Cell Types and Its function , kingdom of life
PDF
TR - Agricultural Crops Production NC III.pdf
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PPTX
PPH.pptx obstetrics and gynecology in nursing
PDF
Classroom Observation Tools for Teachers
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PPTX
Pharma ospi slides which help in ospi learning
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PPTX
master seminar digital applications in india
PDF
Basic Mud Logging Guide for educational purpose
PDF
O7-L3 Supply Chain Operations - ICLT Program
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
Insiders guide to clinical Medicine.pdf
Sports Quiz easy sports quiz sports quiz
Lesson notes of climatology university.
Cell Types and Its function , kingdom of life
TR - Agricultural Crops Production NC III.pdf
Module 4: Burden of Disease Tutorial Slides S2 2025
PPH.pptx obstetrics and gynecology in nursing
Classroom Observation Tools for Teachers
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
Supply Chain Operations Speaking Notes -ICLT Program
2.FourierTransform-ShortQuestionswithAnswers.pdf
Pharma ospi slides which help in ospi learning
O5-L3 Freight Transport Ops (International) V1.pdf
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
master seminar digital applications in india
Basic Mud Logging Guide for educational purpose
O7-L3 Supply Chain Operations - ICLT Program

Parallel extensions in .Net 4.0

  • 1. Parallel Extensions in .Net 4.0Dmytro Maleev for Lviv.Net User Group
  • 2. AgendaКуда катится мир?Hello, Parallel Extensions!Parallel vs MultithreadingParallel LoopsTasksPLINQCDS & Thread EnchantmentsReferencesQ&A
  • 3. Куда катится мирForget about CPU frequency increase! There are a lot of issues with this, which will be fixed in future!1998 Intel 8048680Mhz1 Core2007Core 2 Duo 2.13 GHz2 Core2000Celeron 400Mhz1 Core2010Intel i5 3.3GHz2 Core 4 Threads2003Athlon XP 1.6+GHz1 Core?
  • 4. Куда катится мирFor now…ENLARGE YOUR…CPU CORE COUNT!PENPEN
  • 5. Hello, Parallel Extensions!Parallel Extensions, previously known as the Parallel Framework Extensions or PFX, is a managed concurrency library being developed by a collaboration between Microsoft Research and the CLR team at Microsoft. It is composed of two parts: Parallel LINQ (PLINQ) andTask Parallel Library (TPL).It also consists of a set of coordination data structures (CDS) – sets of data structures used to synchronize and co-ordinate the execution of concurrent tasks.Thelibrary was released as a CTP on November 29, 2007and refreshed again in December 2007 and June 2008. Microsoft has announced that the Parallel Extensions to .NET will release as part of the .NET 4.0 Framework release.©Wikipedia
  • 6. Hello, Parallel Extensions!Visual Studio Debugging and profiling supportParallel ExtensionsPLINQTask Parallel LibraryTask SchedulerCDS
  • 7. Parallel vs MultithreadingMultithreaded!=parallelization“ If on a single core machine you are using threads and it makes perfect sense for your scenario, then you are not "doing parallelism", you are just doing multithreading””On a single core you can use threads and you can have concurrency, but to achieveparallelism on a multi-core box you have to identify in your code the exploitableconcurrency: the portions of your code that can truly run at the same time.”Daniel Moth
  • 9. Dark Side of Paprallelization and MultithreadingRace conditionshttp://en.wikipedia.org/wiki/Race_condition2. Deadlockshttp://en.wikipedia.org/wiki/Deadlockhttp://en.wikipedia.org/wiki/Dining_philosophers_problemThread starvationDifficult to code and debugEnvironmental
  • 11. Parallel LoopsParallel.For()Parallel.For(0, 100, i => { Console.WriteLine("This is I-I-I-I-I-I: {0}", i); });Parallel.ForEach()Parallel.ForEach(ThisIsCollection, collectionItem =>{collectionItem.Hello();});Parallel OptionsParallel.Invoke()
  • 12. Parallel Loops. Use Force wisely!Parallelization Can Hurt Performancehttp://msdn.microsoft.com/en-us/library/dd560853(VS.100).aspxhttp://en.wikipedia.org/wiki/Context_switch
  • 14. Task - Task SchedulerTask is a new class that represents the work you want completed. There are methods to create, schedule, and synchronize tasks in your application.Tasks are controlled by task scheduler.Tasks scheduler works with thread pool.
  • 15. Task In DeepTasks can:Task can be createdTask can wait! Task can simply Wait(), WaitAll() or WaitAny().Task knows when it is completed ( IsCompleted property)Task can ContinueWith()Task can return valueTask has Options and Status
  • 17. PLINQPLINQ is just parallelized version of LINQNot parallelized: LINQ-to-SQL & LINQ-to-Entity.LINQ:var query = from s in someCollectionlet result = CoolService.CallService(s)select result;PLINQ:varquery = from s in someCollection.AsParallel()let result = CoolService.CallService(s)select result;
  • 18. PLINQ. How it works?
  • 19. PLINQ. Overview Ordering ResultsAsOrdered()ForAll Operator()AsSequential()WithMergeOptionsParallel Performance Analyzer. Just for rich
  • 21. CDS & Thread EnchantmentsThread Enchantments:Thread.Yield()Monitor.Enter()Concurrent CollectionsConcurrentStack (LIFO)ConcurrentQueue (FIFO)ConcurrentDictionaryConcurrentBagBlockingCollection
  • 22. Synchronization PrimitivesBarrier“Let’s meet near monument and then go to have a beer”Cancellation TokensCountDownEventManualResetEventSlim and SemaphoreSlimSpinLockThreadLocal<T>
  • 23. References Parallel Programming with .NEThttp://blogs.msdn.com/b/pfxteam/Wikihttp://en.wikipedia.org/wiki/Parallel_ExtensionsIntroducing .NET 4.0http://www.amazon.com/Introducing-NET-4-0-Visual-Experts/dp/143022455XLviv.Net User Grouphttp://dotnetug-lviv.blogspot.com/
  • 24. Q&A?
  • 25. If you still have a questions Mail me:diwingless@gmail.comSkype me:hmmidmaTwitter:dimko1