Thursday, January 15, 2009

C# Concurrent Programming

Concurrent Programming is being developed to be scalable and produce high performance as manycore hardware systems are now being released for PCs, routers, and small devices. Programming for parallel processing will require optimizing multiple task execution.

Microsoft is planning on releasing concurrent programming tools for windows developers as fast as they can.

The Windows and .NET Framework platforms currently offer threading support for scheduling performance, synchronization AI, and memory hierarchy awareness. Microsoft’s Visual Studio 2010 will add concurrency at the library level for native as well as managed .NET languages.

Traditionally programming languages perform computations using syntax and semantic rules based upon the basic constructs: sequential statements, looping, branching and hierarchical organization. For C# managed code Microsoft has developed a Task Class, a Parallel Class, and a Enumerable Class to take advantage of these constructs for optimizing and simplifying concurrent programming.

Amdahl’s Law applies directly to the optimization of serial and parallel operations performed by software including branching (If, switch, etc.) operations and looping (do, for, and foreach) operations in programs where repetitious operations offer efficient points for concurrent programming methods.

While Microsoft has supported threading operations for many years thread have many hazards associated with simultaneous access of shared memory by different threads. This can lead to hazards that arise from competing threads that jeopardize state management including: deadlocks, livelocks, and race conditions. The next generation of Visual Studio 2010 tools addresses these difficulties.

As a result, Microsoft has developed a Task Program Library to exploits concurrency in program operations without the complexity and error prone direct exposure to threads. In addition, Microsoft’s implementation of these features optimizes core utilization while minimizing complexity.

The following Figure show the Visual Studio 2010 model for building parallel tasks for managed and native code on top of both threads and thread pools.



Figure: Visual Studio 2010 Programming Model

Parallel Extensions for .NET 3.5 provides library-based support for concurrency with any .NET language, such as C++, C# and Visual Basic. It includes: Task Parallel Library, Parallel LINQ, and parallel method extensions.

Visual Studio 2010 and .NET 4.0 provide these extensions in the form of a library for rapid development:

 Task Parallel Library (TPL)
 Imperative task parallelism – Task Class
 Imperative data parallelism – Parallel Class (Parallel.For)
 Parallel LINQ (PLINQ)
 Declarative data parallelism – ParallelEnumerable and AsParallel Class

The Task Parallel Library (TPL) provides support for imperative data and task parallelism. The Task Parallel Library (TPL) makes it easy to add data and task parallelization to an application.

Parallel LINQ (PLINQ) provides support for declarative data parallelism. PLINQ is an extension of LINQ where the query is run in parallel. PLINQ takes advantage of TPL by taking query iterations and assigning work units to threads (typically processor cores). Adding concurrent programming capabilities to LINQ is a natural extension of LINQ.

Coordination Data Structures (CDS) provide support for work coordination and managing shared state.

The .NET application developers can look forward to the release of Visual Studio 2010 for the tools and techniques to write simple efficient thread-safe code for manycore systems.

[1] Alesso, H. P. and Smith, C. F., Connections: Patterns of Discovery, John Wiley & Sons Inc., New York, NY, 2007.

[2] Alesso, H. P. and Smith, C. F., Thinking on the Web: Berners-lee, Turing and Godel, John Wiley & Sons, Inc. 2008.

[3] Microsoft Visual Studio 2010

No comments: