# Parallel Extensions

> Mediated Wiki article. Canonical URL: https://mediated.wiki/source/Parallel_Extensions
> Markdown URL: https://mediated.wiki/source/Parallel_Extensions.md
> Source: https://en.wikipedia.org/wiki/Parallel_Extensions
> Source revision: 1321299614
> License: Creative Commons Attribution-ShareAlike 4.0 International (https://creativecommons.org/licenses/by-sa/4.0/)

.NET managed concurrency library

 .NET Store APIs

 Async model

 [Parallel LINQ](#Parallel_LINQ)

 [TPL](#Task_Parallel_Library)

 [LINQ](/source/Language_Integrated_Query)

 [EF](/source/Entity_Framework)

 [WPF](/source/Windows_Presentation_Foundation)

 [WCF](/source/Windows_Communication_Foundation)

 [WF](/source/Windows_Workflow_Foundation)

 [WCS](/source/Windows_CardSpace)

 [WinForms](/source/Windows_Forms)

 [ASP.NET](/source/ASP.NET)

 [ADO.NET](/source/ADO.NET)

 [Framework Class Library](/source/Framework_Class_Library)

 [Common Language Runtime](/source/Common_Language_Runtime)

The [.NET Framework](/source/.NET_Framework) stack

**Parallel Extensions** was the development name for a [managed](/source/Managed_code) [concurrency](/source/Concurrent_programming) [library](/source/Library_(computing)) developed by a collaboration between [Microsoft Research](/source/Microsoft_Research) and the [CLR](/source/Common_Language_Runtime) team at [Microsoft](/source/Microsoft). The library was released in version 4.0 of the [.NET Framework](/source/.NET_Framework).[1] It is composed of two parts: *Parallel LINQ* (PLINQ) and *Task Parallel Library* (TPL).[2][3] It also consists of a set of *coordination data structures* (CDS) – sets of [data structures](/source/Data_structure) used to synchronize and co-ordinate the execution of concurrent tasks.[4]

## Parallel LINQ

**PLINQ**, or **Parallel [LINQ](/source/Language_Integrated_Query)**, parallelizing the execution of queries on objects (LINQ to Objects) and XML data (LINQ to XML). PLINQ is intended for exposing [data parallelism](/source/Data_parallelism) by use of queries.[2] Any computation on objects that has been implemented as queries can be parallelized by PLINQ. However, the objects need to implement the IParallelEnumerable interface, which is defined by PLINQ itself. Internally it uses [TPL](#Task_Parallel_Library) for execution.[4][5]

## Task Parallel Library

The **Task Parallel Library** (**TPL**) is the [task parallelism](/source/Task_parallelism) component of the Parallel Extensions to .NET.[6] It exposes parallel constructs like parallel For and ForEach loops, using regular method calls and [delegates](/source/Delegate_(CLI)), thus the constructs can be used from any [CLI languages](/source/List_of_CLI_languages). The job of spawning and terminating [threads](/source/Thread_(computing)), as well as scaling the number of threads according to the number of available processors, is done by the library itself,[3] using a [work stealing](/source/Work_stealing) scheduler.[7]

TPL also includes other constructs like *Task* and *[Future](/source/Future_(programming))*. 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](/source/Thread_pool_pattern) 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.[3] 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.[6]

The other construct of TPL is **Parallel** class. TPL provides a basic form of structured parallelism via three static methods in the Parallel class:

**Parallel.Invoke**
- Executes an array of Action delegates in parallel, and then waits for them to complete

**Parallel.For**
- Parallel equivalent of a C# for loop

**Parallel.ForEach**
- Parallel equivalent of a C# [foreach loop](/source/Foreach_loop)

## Architecture

The main concept in the Parallel Extensions to .NET is a Task, which is a small unit of code, usually represented as a [lambda function](/source/Lambda_(programming)), 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 Parallel.For, Parallel.ForEach and Parallel.Invoke methods divide a loop into Tasks.

PFX includes a Task Manager object which schedules the Tasks for execution. A Task Manager contains a global [queue](/source/Queue_(data_structure)) of Tasks, which are then executed. It also encapsulates multiple [threads](/source/Thread_(computing)) 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](/source/Concurrency_and_Coordination_Runtime)

- [Joins](/source/Joins_(concurrency_library))

- [Cilk](/source/Cilk)/[Cilk Plus](/source/Cilk_Plus) – comparable technology for C and C++

- [Grand Central Dispatch](/source/Grand_Central_Dispatch) – comparable technology in [Mac OS X 10.6](/source/Mac_OS_X_10.6) developed by [Apple](/source/Apple_Inc.).

- [Java Concurrency](/source/Java_Concurrency) – comparable technology in [Java](/source/Java_(software_platform)) (also known as [JSR 166](/source/JSR_166)).

- [Threading Building Blocks](/source/Threading_Building_Blocks) (TBB) – comparable technology for C++ available for many systems created originally by Intel (also open source)

- [Thread pool pattern](/source/Thread_pool_pattern)

- [Task parallelism](/source/Task_parallelism)

- [ReactiveX](/source/ReactiveX) (Reactive Extensions)

## References

1. **[^](#cite_ref-1)** ["What's New in the .NET Framework 4"](https://msdn.microsoft.com/en-us/library/ms171868.aspx#parallel_computing). Retrieved 21 September 2011.

1. ^ [***a***](#cite_ref-channel9_2-0) [***b***](#cite_ref-channel9_2-1) ["Programming in the Age of Concurrency: Concurrent Programming with PFX"](http://channel9.msdn.com/Showpost.aspx?postid=347531). Retrieved 16 October 2007.

1. ^ [***a***](#cite_ref-msdnmag_3-0) [***b***](#cite_ref-msdnmag_3-1) [***c***](#cite_ref-msdnmag_3-2) ["MSDN Magazine: Task Parallel Library"](https://web.archive.org/web/20071014104004/http://msdn.microsoft.com/msdnmag/issues/07/10/futures/default.aspx). Archived from [the original](http://msdn.microsoft.com/msdnmag/issues/07/10/Futures/default.aspx) on 14 October 2007. Retrieved 16 October 2007.

1. ^ [***a***](#cite_ref-somajune_4-0) [***b***](#cite_ref-somajune_4-1) ["June 2008 CTP – Parallel Extensions to the .NET FX"](https://blogs.msdn.com/somasegar/archive/2008/06/02/june-2008-ctp-parallel-extensions-to-the-net-fx.aspx). Retrieved 6 August 2008.

1. **[^](#cite_ref-5)** ["More powerful aggregations in PLINQ"](https://blogs.msdn.com/pfxteam/archive/2008/06/05/8576194.aspx). Retrieved 6 August 2008.

1. ^ [***a***](#cite_ref-Concurrent_Programming_on_Windows_Appendix_B_6-0) [***b***](#cite_ref-Concurrent_Programming_on_Windows_Appendix_B_6-1) Duffy, Joe (2009). *Concurrent Programming on Windows*. pp. 887–929. [ISBN](/source/ISBN_(identifier)) [978-0321434821](https://en.wikipedia.org/wiki/Special:BookSources/978-0321434821).

1. **[^](#cite_ref-7)** Leijen, Daan; Schulte, Wolfram; Burckhardt, Sebastian (2009). "The Design of a Task Parallel Library". *ACM SIGPLAN Notices*. **44** (10): 227. [CiteSeerX](/source/CiteSeerX_(identifier)) [10.1.1.146.4197](https://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.146.4197). [doi](/source/Doi_(identifier)):[10.1145/1639949.1640106](https://doi.org/10.1145%2F1639949.1640106).

## External links

Wikibooks has a book on the topic of: ***[.NET Development Foundation](https://en.wikibooks.org/wiki/.NET_Development_Foundation)***

- [Parallel FX CTP June 2008](http://www.microsoft.com/downloads/details.aspx?FamilyId=348F73FD-593D-4B3C-B055-694C50D2B0F3&displaylang=en)

- [Parallel Computing Developer Center](http://msdn.microsoft.com/en-us/concurrency/default.aspx)

v t e .NET .NET strategy Libraries and frameworks Implementations .NET (Core) .NET Framework Version history .NET Compact Framework .NET Micro Framework DotGNU Mono XNA Framework Architecture Common Language Runtime (CLR) COM Interop Framework Class Library (FCL) Components ADO.NET Entity Framework ASP.NET Web Forms AJAX Core Dynamic Data MVC Razor Avalonia ClickOnce Dynamic Language Runtime Extensible Application Markup Language (XAML) Language Integrated Query (LINQ) Managed Extensibility Framework Microsoft Silverlight Microsoft XNA Parallel Extensions Windows Communication Foundation (WCF) WCF Data Services Windows Forms (WinForms) Windows Identity Foundation (WIF) Windows Presentation Foundation (WPF) Windows Workflow Foundation (WF) .NET Remoting Tools Decompilers .NET Reflector dotPeek Obfuscators Dotfuscator SmartAssembly CLR Profiler ILAsm .NET Compiler Platform Native Image Generator (NGen) XAMLPad IDEs Visual Studio Blend Express MonoDevelop SharpDevelop Xamarin Studio Organizations .NET Foundation Microsoft Xamarin Category List Commons

v t e Parallel computing General Distributed computing Parallel computing Parallel algorithm Massively parallel Cloud computing High-performance computing Multiprocessing Manycore processor GPGPU Computer network Systolic array Levels Bit Instruction Thread Task Data Memory Loop Pipeline Multithreading Temporal Simultaneous (SMT) Simultaneous and heterogenous Speculative (SpMT) Preemptive Cooperative Clustered multi-thread (CMT) Hardware scout Theory PRAM model PEM model Analysis of parallel algorithms Amdahl's law Gustafson's law Cost efficiency Karp–Flatt metric Slowdown Speedup Elements Process Thread Fiber Instruction window Array Coordination Multiprocessing Memory coherence Cache coherence Cache invalidation Barrier Synchronization Application checkpointing Programming Stream processing Dataflow programming Models Implicit parallelism Explicit parallelism Concurrency Non-blocking algorithm Hardware Flynn's taxonomy SISD SIMD Array processing (SIMT) Pipelined processing Associative processing MISD MIMD Dataflow architecture Pipelined processor Superscalar processor Vector processor Multiprocessor symmetric asymmetric Memory shared distributed distributed shared UMA NUMA COMA Massively parallel computer Computer cluster Beowulf cluster Grid computer Hardware acceleration APIs Ateji PX Boost Chapel HPX Charm++ Cilk Coarray Fortran CUDA Dryad C++ AMP Global Arrays GPUOpen MPI OpenMP OpenCL OpenHMPP OpenACC Parallel Extensions PVM pthreads RaftLib ROCm UPC TBB ZPL Problems Automatic parallelization Cache stampede Deadlock Deterministic algorithm Embarrassingly parallel Parallel slowdown Race condition Software lockout Scalability Starvation Category: Parallel computing

---
Adapted from the Wikipedia article [Parallel Extensions](https://en.wikipedia.org/wiki/Parallel_Extensions) by Wikipedia contributors ([contributor history](https://en.wikipedia.org/wiki/Parallel_Extensions?action=history)). Available under [Creative Commons Attribution-ShareAlike 4.0 International](https://creativecommons.org/licenses/by-sa/4.0/). Changes may have been made.
