Parallel Extensions: Difference between revisions

Content deleted Content added
Adding short description: ".NET managed concurrency library"
 
(22 intermediate revisions by 17 users not shown)
Line 1:
{{Short description|.NET managed concurrency library}}
{{Use dmy dates|date=MayNovember 20132022}}
[[File:DotNet.svg|thumb|right|250px|The [[.NET Framework]] stack]]
{{Annotated image
'''Parallel Extensions''' was the development name for a [[Managed code|managed]] [[Concurrent programming|concurrency]] [[Library (computing)|library]] developed by a collaboration between [[Microsoft Research]] and the [[Common Language Runtime|CLR]] team at [[Microsoft]]. The library was released in version 4.0 of the [[.NET Framework]].<ref>{{cite web | url = http://msdn.microsoft.com/en-us/library/ms171868.aspx#parallel_computing | title = What's New in the .NET Framework 4 | accessdate = 2011-09-21}}</ref> It is composed of two parts: [[#Parallel LINQ|''Parallel LINQ'']] (PLINQ) and [[#Task Parallel Library|''Task Parallel Library'']] (TPL).<ref name="channel9">{{cite web | url = http://channel9.msdn.com/Showpost.aspx?postid=347531 | title = Programming in the Age of Concurrency: Concurrent Programming with PFX | accessdate = 2007-10-16}}</ref><ref name="msdnmag">{{cite web | url = http://msdn.microsoft.com/msdnmag/issues/07/10/Futures/default.aspx | title = MSDN Magazine: Task Parallel Library | accessdate = 2007-10-16}}</ref> It also consists of a set of ''coordination data structures'' (CDS) – sets of [[data structure]]s used to synchronize and co-ordinate the execution of concurrent tasks.<ref name="somajune"/>
| image = Dot-Net 1 SVG.svg
| image-width = 252
| image-left = 0
| image-top = 0
| width = 252
| height = 280
| float = 0
| annotations =
{{Annotation |10|12| {{color|#11404A|.NET Store APIs}} | text-align=center | font-size=12 | font-weight=bold | font-family=Segoe UI | background-color=#ffcccee}}
{{Annotation |118|12| {{color|#11404A|Async model}} | text-align=center | font-size=12 | font-weight=bold | font-family=Segoe UI | background-color=#ffcccee}}
{{Annotation |16|54| {{colored link|#3C360B|Parallel Extensions#Parallel LINQ|Parallel LINQ}} | text-align=center | font-size=12 | font-weight=bold | font-family=Segoe UI | background-color=#ffcccee | colored link=blue}}
{{Annotation |144|54| {{colored link|#3C360B|Parallel Extensions#Task_Parallel_Library|TPL}} | text-align=center | font-size=12 | font-weight=bold | font-family=Segoe UI | background-color=#ffcccee | colored link=white}}
{{Annotation |40|96| {{colored link|#2A1540|Language Integrated Query|LINQ}} | text-align=center | font-size=12 | font-weight=bold | font-family=Segoe UI | background-color=#ffcccee | colored link=blue}}
{{Annotation |148|96| {{colored link|#2A1540|Entity_Framework|EF}} | text-align=center | font-size=12 | font-weight=bold | font-family=Segoe UI | background-color=#ffcccee | colored link=blue}}
{{Annotation |16|136| {{colored link|#41250E|Windows Presentation Foundation|WPF}} | text-align=center | font-size=12 | font-weight=bold | font-family=Segoe UI | background-color=#ffcccee | colored link=blue}}
{{Annotation |68|136| {{colored link|#41250E|Windows Communication Foundation|WCF}} | text-align=center | font-size=12 | font-weight=bold | font-family=Segoe UI | background-color=#ffcccee | colored link=blue}}
{{Annotation |122|136| {{colored link|#41250E|Windows Workflow Foundation|WF}} | text-align=center | font-size=12 | font-weight=bold | font-family=Segoe UI | background-color=#ffcccee | colored link=blue}}
{{Annotation |170|136| {{colored link|#41250E|Windows CardSpace|WCS}} | text-align=center | font-size=12 | font-weight=bold | font-family=Segoe UI | background-color=#ffcccee | colored link=blue}}
{{Annotation |9|178| {{colored link|#1A2B0B|Windows Forms|WinForms}} | text-align=center | font-size=12 | font-weight=bold | font-family=Segoe UI | background-color=#ffcccee}}
{{Annotation |81|178| {{colored link|#1A2B0B|ASP.NET|ASP.NET}} | text-align=center | font-size=12 | font-weight=bold | font-family=Segoe UI | background-color=#ffcccee}}
{{Annotation |148|178| {{colored link|#1A2B0B|ADO.NET|ADO.NET}} | text-align=center | font-size=12 | font-weight=bold | font-family=Segoe UI | background-color=#ffcccee}}
{{Annotation |36|212| {{colored link|#1A2B0B|Framework Class Library|Framework Class Library}} | text-align=center | font-size=12 | font-weight=bold | font-family=Segoe UI | background-color=#ffcccee}}
{{Annotation |26|250| {{colored link|#0E2237|Common Language Runtime|Common Language Runtime}} | text-align=center | font-size=12 | font-weight=bold | font-family=Segoe UI | background-color=#ffcccee}}
| caption = The [[.NET Framework]] stack
}}
'''Parallel Extensions''' was the development name for a [[Managed code|managed]] [[Concurrent programming|concurrency]] [[Library (computing)|library]] developed by a collaboration between [[Microsoft Research]] and the [[Common Language Runtime|CLR]] team at [[Microsoft]]. The library was released in version 4.0 of the [[.NET Framework]].<ref>{{cite web | url = http://msdn.microsoft.com/en-us/library/ms171868.aspx#parallel_computing | title = What's New in the .NET Framework 4 | accessdateaccess-date = 2011-09-21}}</ref> It is composed of two parts: [[#Parallel LINQ|''Parallel LINQ'']] (PLINQ) and [[#Task Parallel Library|''Task Parallel Library'']] (TPL).<ref name="channel9">{{cite web | url = http://channel9.msdn.com/Showpost.aspx?postid=347531 | title = Programming in the Age of Concurrency: Concurrent Programming with PFX | accessdateaccess-date = 2007-10-16}}</ref><ref name="msdnmag">{{cite web | url = http://msdn.microsoft.com/msdnmag/issues/07/10/Futures/default.aspx | title = MSDN Magazine: Task Parallel Library | accessdateaccess-date = 2007-10-16 | archive-url = https://web.archive.org/web/20071014104004/http://msdn.microsoft.com/msdnmag/issues/07/10/futures/default.aspx | archive-date = 14 October 2007 | url-status = dead }}</ref> It also consists of a set of ''coordination data structures'' (CDS) – sets of [[data structure]]s used to synchronize and co-ordinate the execution of concurrent tasks.<ref name="somajune"/>
 
==Parallel LINQ{{Anchor|PLINQ}}==
'''Parallel LINQPLINQ''', or ('''PLINQ''') Parallel [[Language Integrated Query|LINQ]]''', parallelizing the execution of queries on objects (LINQ to Objects) and XML data (LINQ to XML). PLINQ is intended for exposing [[data parallelism]] by use of queries.<ref name="channel9"/> Any computation on objects that has been implemented as queries can be parallelized by PLINQ. However, the objects need to impimplement the <code>IParallelEnumerable</code> interface, which is defined by PLINQ itself. Internally it uses [[#Task Parallel Library|TPL]] for execution.<ref name="somajune">{{cite web | url = http://blogs.msdn.com/somasegar/archive/2008/06/02/june-2008-ctp-parallel-extensions-to-the-net-fx.aspx | title = June 2008 CTP - Parallel Extensions to the .NET FX | accessdateaccess-date = 2008-08-06}}</ref><ref>{{cite web | url = http://blogs.msdn.com/pfxteam/archive/2008/06/05/8576194.aspx | title = More powerful aggregations in PLINQ | accessdateaccess-date = 2008-08-06}}</ref>
 
==Task Parallel Library==
The '''Task Parallel Library''' ('''TPL''') is the [[task parallelism]] component of the Parallel Extensions to .NET.<ref name="Concurrent Programming on Windows Appendix B"/> It exposes parallel constructs like parallel <code>For</code> and <code>ForEach</code> loops, using regular method calls and [[Delegate (CLI)|delegate]]s, thus the constructs can be used from any [[List of CLI languages|CLI languages]]. The job of spawning and terminating [[Thread (computing)|threads]], as well as scaling the number of threads according to the number of available processors, is done by the library itself,<ref name="msdnmag"/> using a [[work stealing]] scheduler.<ref>{{cite journal |last1=Leijen |first1=Daan |first2=Wolfram |last2=Schulte |first3=Sebastian |last3=Burckhardt |title=The Design of a Task Parallel Library |journal=ACM SIGPLAN Notices |volume=44 |issue=10 |pages=227 |year=2009| doi = 10.1145/1639949.1640106 |citeseerx=10.1.1.146.4197 }}</ref>
 
TPL also includes other constructs like ''Task'' and ''[[Future (programming)|Future]]''. A ''Task'' is an action that can be executed independent of the rest of the program. In that sense, it is semantically equivalent to a thread, except that it is a more light-weight object and comes without the overhead of creating an OS thread. Tasks are queued by a ''Task Manager'' object and are scheduled to run on multiple OS threads in a [[thread pool pattern|thread pool]] when their turn comes.
 
''Future'' is a task that returns a result. The result is computed in a background thread encapsulated by the ''Future'' object, and the result is buffered until it is retrieved.<ref name="msdnmag"/> If an attempt is made to retrieve the result before it has been computed then the requesting thread will block until the result is available.<ref name="Concurrent_Programming_on_Windows_Appendix_BConcurrent Programming on Windows Appendix B">{{cite book | first=Joe | last=Duffy | year=2009 | title=Concurrent Programming on Windows | isbn=032143482X978-0321434821| pages="887–929" }}</ref>
 
The other construct of TPL is '''Parallel''' class.
Line 20 ⟶ 46:
 
==Architecture==
The main concept in the Parallel Extensions to .NET is a <code>Task</code>, which is a small unit of code, usually represented as a [[lambda (programming)|lambda function]], that can be executed independently. Both PLINQ and the TPL API provides methods to create the Tasks - PLINQ divides a query into smaller Tasks, and the <code>Parallel.For</code>, <code>Parallel.ForEach</code> and <code>Parallel.Invoke</code> methods divide a loop into Tasks.
 
PFX includes a <code>Task Manager</code> object which schedules the Tasks for execution. A Task Manager contains a global [[queue (data structure)|queue]] of Tasks, which are then executed. In addition, itIt also encapsulates multiple [[Thread (computing)|threads]] onto which the Tasks are executed. By default, as many threads as there are processors (or processor cores) on the system are created, though this number may be manually modified. Each thread is associated with a thread-specific queue of Tasks. When idle, each thread picks up a batch of Tasks and puts them on its local queue, where they are then executed, one by one. If the global queue is empty, a thread will look for Tasks in the queues of its peers, and will take the Tasks which have been in the queue the longest (''task stealing''). When in execution, the Tasks will be executed independently, with the change in state of one Task independent of others. As a result, if they use a shared resource, they still need to be synchronized manually using locks or other constructs.
 
==See also==
*[[Concurrency and Coordination Runtime]]
*[[Joins (concurrency library)|Joins]]
*[[Cilk]]/[[Cilk Plus]] - comparable technology for C and C++
*[[Grand Central Dispatch]] - comparable technology in [[Mac OS X 10.6]] developed by [[Apple Inc.|Apple]].
*[[Java Concurrency]] - comparable technology in [[Java (software platform)|Java]] (also known as [[JSR 166]]).
*[[Threading Building Blocks]] (TBB) - comparable technology for C++ available for many systems created originally by Intel (also open source)
*[[Thread pool pattern]]
*[[Task parallelism]]
*[[ReactiveX]] (Reactive Extensions)
 
==References==
{{reflist|2}}
 
==External links==
{{Wikibooks|.NET Development Foundation}}
*[http://www.microsoft.com/downloads/details.aspx?FamilyId=348F73FD-593D-4B3C-B055-694C50D2B0F3&displaylang=en Parallel FX CTP June 2008]
*[http://msdn.microsoft.com/en-us/concurrency/default.aspx Parallel Computing Developer Center]
 
*[http://blog.linqexchange.com/index.php/using-parallel-linq/ How to Use PLINQ (Parallel LINQ)]
{{.NET Framework}}
{{Parallel computing}}
[[Category:.NET Framework]]
 
[[Category:.NET Frameworkterminology]]
[[Category:Concurrent programming libraries]]