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) and Task 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. The library was released as a CTP on November 29, 2007 and 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.
Parallel LINQ
See also: Language Integrated Query
Parallel LINQ (PLINQ) is a concurrent query execution engine for 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. 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 for execution.
Task Parallel Library
The Task Parallel Library (TPL) is the task parallelism component of the Parallel Extensions to .NET. It exposes parallel constructs like parallel For
and ForEach
loops, using regular method calls and delegates. As such, the constructs can be used from any language supporting the .NET Framework. The job of spawning and terminating threads, as well as scaling the number of threads according to the number of available processors, is done by the library itself.
TPL also includes other constructs such as Task and 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 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. If an attempt is made to retrieve the result before it has been computed then the asking thread will block until the result is available.
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, 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 of Tasks, which are then executed. In addition, it also encapsulates multiple 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. Each thread, when idle, picks up a batch of Tasks, and puts on its local queue, and then executes them 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.
More on Parallel Computing Visit
http://blogs.msdn.com/pfxteam/
http://blogs.techrepublic.com.com/programming-and-development/?p=657
http://msdn.microsoft.com/en-us/concurrency/default.aspx
Discover more from Cloud Distilled ~ Nithin Mohan
Subscribe to get the latest posts sent to your email.