Your SlideShare is downloading. ×
0
Parallel extensions in .Net 4.0
Parallel extensions in .Net 4.0
Parallel extensions in .Net 4.0
Parallel extensions in .Net 4.0
Parallel extensions in .Net 4.0
Parallel extensions in .Net 4.0
Parallel extensions in .Net 4.0
Parallel extensions in .Net 4.0
Parallel extensions in .Net 4.0
Parallel extensions in .Net 4.0
Parallel extensions in .Net 4.0
Parallel extensions in .Net 4.0
Parallel extensions in .Net 4.0
Parallel extensions in .Net 4.0
Parallel extensions in .Net 4.0
Parallel extensions in .Net 4.0
Parallel extensions in .Net 4.0
Parallel extensions in .Net 4.0
Parallel extensions in .Net 4.0
Parallel extensions in .Net 4.0
Parallel extensions in .Net 4.0
Parallel extensions in .Net 4.0
Parallel extensions in .Net 4.0
Parallel extensions in .Net 4.0
Parallel extensions in .Net 4.0
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Parallel extensions in .Net 4.0

2,303

Published on

Published in: Education, Technology
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
2,303
On Slideshare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
68
Comments
0
Likes
2
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Parallel Extensions in .Net 4.0<br />Dmytro Maleev for Lviv.Net User Group<br />
  • 2. Agenda<br />Куда катится мир?<br />Hello, Parallel Extensions!<br />Parallel vs Multithreading<br />Parallel Loops<br />Tasks<br />PLINQ<br />CDS &amp; Thread Enchantments<br />References<br />Q&amp;A<br />
  • 3. Куда катится мир<br />Forget about CPU frequency increase! There are a lot of issues with this, which will be fixed in future!<br />1998 <br />Intel 80486<br />80Mhz<br />1 Core<br />2007<br />Core 2 Duo 2.13 GHz<br />2 Core<br />2000<br />Celeron 400Mhz<br />1 Core<br />2010<br />Intel i5 3.3GHz<br />2 Core 4 Threads<br />2003<br />Athlon XP 1.6+GHz<br />1 Core<br />?<br />
  • 4. Куда катится мир<br />For now…ENLARGE YOUR…<br />CPU CORE COUNT!<br />PEN<br />PEN<br />
  • 5. Hello, Parallel Extensions!<br />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.<br />©Wikipedia<br />
  • 6. Hello, Parallel Extensions!<br />Visual Studio Debugging and profiling support<br />Parallel Extensions<br />PLINQ<br />Task Parallel Library<br />Task Scheduler<br />CDS<br />
  • 7. Parallel vs Multithreading<br />Multithreaded!=parallelization<br />“ If on a single core machine you are using threads and it makes perfect sense for your scenario, then you are not &quot;doing parallelism&quot;, you are just doing multithreading”<br />”On a single core you can use threads and you can have concurrency, but to achieve<br />parallelism on a multi-core box you have to identify in your code the exploitable<br />concurrency: the portions of your code that can truly run at the same time.”<br />Daniel Moth<br />
  • 8. Parallel vs Multithreading<br />
  • 9. Dark Side of Paprallelization and Multithreading<br />Race conditions<br />http://en.wikipedia.org/wiki/Race_condition<br />2. Deadlocks<br />http://en.wikipedia.org/wiki/Deadlock<br />http://en.wikipedia.org/wiki/Dining_philosophers_problem<br />Thread starvation<br />Difficult to code and debug<br />Environmental<br />
  • 10. Народная мудрость!<br />
  • 11. Parallel Loops<br />Parallel.For()<br />Parallel.For(0, 100, i =&gt;<br /> {<br /> Console.WriteLine(&quot;This is I-I-I-I-I-I: {0}&quot;, i);<br /> });<br />Parallel.ForEach()<br />Parallel.ForEach(ThisIsCollection, collectionItem =&gt;<br />{<br />collectionItem.Hello();<br />});<br />Parallel Options<br />Parallel.Invoke()<br />
  • 12. Parallel Loops. Use Force wisely!<br />Parallelization Can Hurt Performance<br />http://msdn.microsoft.com/en-us/library/dd560853(VS.100).aspx<br />http://en.wikipedia.org/wiki/Context_switch<br />
  • 13. DEMO<br />AntiSocialRobots<br />
  • 14. Task - Task Scheduler<br />Task is a new class that represents the work you want completed. There are methods to create, schedule, and synchronize tasks in your application.<br />Tasks are controlled by task scheduler.<br />Tasks scheduler works with thread pool.<br />
  • 15. Task In Deep<br />Tasks can:<br />Task can be created<br />Task can wait! Task can simply Wait(), WaitAll() or WaitAny().<br />Task knows when it is completed ( IsCompleted property)<br />Task can ContinueWith()<br />Task can return value<br />Task has Options and Status<br />
  • 16. Demo<br />Strassen algorithm<br />
  • 17. PLINQ<br />PLINQ is just parallelized version of LINQ<br />Not parallelized: LINQ-to-SQL &amp; LINQ-to-Entity.<br />LINQ:<br />var query = from s in someCollection<br />let result = CoolService.CallService(s)<br />select result;<br />PLINQ:<br />varquery = from s in someCollection.AsParallel()<br />let result = CoolService.CallService(s)<br />select result;<br />
  • 18. PLINQ. How it works?<br />
  • 19. PLINQ. Overview <br />Ordering Results<br />AsOrdered()<br />ForAll Operator()<br />AsSequential()<br />WithMergeOptions<br />Parallel Performance Analyzer. Just for rich<br />
  • 20. DEMO <br />Baby Names<br />
  • 21. CDS &amp; Thread Enchantments<br />Thread Enchantments:<br />Thread.Yield()<br />Monitor.Enter()<br />Concurrent Collections<br />ConcurrentStack (LIFO)<br />ConcurrentQueue (FIFO)<br />ConcurrentDictionary<br />ConcurrentBag<br />BlockingCollection<br />
  • 22. Synchronization Primitives<br />Barrier<br />“Let’s meet near monument and then go to have a beer”<br />Cancellation Tokens<br />CountDownEvent<br />ManualResetEventSlim and SemaphoreSlim<br />SpinLock<br />ThreadLocal&lt;T&gt;<br />
  • 23. References <br />Parallel Programming with .NET<br />http://blogs.msdn.com/b/pfxteam/<br />Wiki<br />http://en.wikipedia.org/wiki/Parallel_Extensions<br />Introducing .NET 4.0<br />http://www.amazon.com/Introducing-NET-4-0-Visual-Experts/dp/143022455X<br />Lviv.Net User Group<br />http://dotnetug-lviv.blogspot.com/<br />
  • 24. Q&amp;A<br />?<br />
  • 25. If you still have a questions <br />Mail me:<br />diwingless@gmail.com<br />Skype me:<br />hmmidma<br />Twitter:<br />dimko1<br />

×