ArticleslgStudy

science

Parallel Extensions

Parallel Extensions is a science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Parallel Extensions rather than just read about it. In short: Parallel Extensions was the development name for a managed concurrency library developed by a collaboration between Microsoft Research and the CLR team at Microsoft. The library was released in version 4.0 of the .NET Framework.

Parallel Extensions — main illustration
Parallel Extensions — illustration

Key takeaways

  • Parallel Extensions belongs to science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Parallel Extensions to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Parallel Extensions from memory before moving on to harder problems.

Reference excerpt

Parallel Extensions was the development name for a managed concurrency library developed by a collaboration between Microsoft Research and the CLR team at Microsoft. The library was released in version 4.0 of the .NET Framework. 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.

Parallel LINQ PLINQ, or Parallel 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 consume the System.Linq.ParallelQuery<T> class, 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, thus the constructs can be used from any CLI languages. 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, using a work stealing scheduler. TPL also includes other constructs like 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 requesting thread will block until the result is available. 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

Architecture The main concept in the Parallel Extensions to .NET is a System.Threading.Tasks.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. 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. 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 Cilk/Cilk Plus – comparable technology for C and C++ Grand Central Dispatch – comparable technology in Mac OS X 10.6 developed by Apple. Java Concurrency – comparable technology in 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

External links

Parallel FX CTP June 2008 Parallel Computing Developer Center

Illustrations

Parallel Extensions illustration

Worked examples

Example 1 — a first encounter with Parallel Extensions

Start with the simplest possible case. Write down what Parallel Extensions claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Parallel Extensions before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Parallel Extensions ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Parallel Extensions

In research
Parallel Extensions appears in science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Parallel Extensions in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Parallel Extensions is common in secondary-school and first-year university syllabi. It links to neighbouring topics .NET terminology, Concurrent programming libraries, so understanding it makes those chapters shorter.
In everyday life
Look for Parallel Extensions outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Parallel Extensions” →

How to study Parallel Extensions in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Parallel Extensions means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Parallel Extensions out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Parallel Extensions in simple terms?

Parallel Extensions was the development name for a managed concurrency library developed by a collaboration between Microsoft Research and the CLR team at Microsoft. The library was released in version 4.0 of the .NET Framework.

Why does Parallel Extensions matter?

Because it connects several science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Parallel Extensions?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Parallel Extensions.

Tags

  • .NET terminology
  • Concurrent programming libraries

Keep exploring