Parallel Processing in Visual Studio 2010 - Part I

Karthikanbarasan
Posted by in .NET Framework category on for Intermediate level | Points: 250 | Views : 10786 red flag
Rating: 5 out of 5  
 1 vote(s)

This articles is 1st part of the 5 part series which gives overview of the Parallel Processing in Visual Studio 2010.

Introduction

The .net framework 4.0 introduces a new programming architecture for doing multiple processes asynchronously that greatly simplifies the application load and gets better performance.  The new programming architecture helps developers to write a scalable and more efficient code in order to achieve better performance for the application development. Parallel LINQ (PLINQ) which is a parallel implementation of LINQ to Objects enables similar functionality for the developers through declarative coding.

You can have in your mind how multi core processor is related with multi threaded application. The concept would be like application development processes based on the environment the application is running. Even though the application runs in multi core processor, fewer resources will be taken by the application to run the process. Say for example multi core processor has the ability to handle n number of process; code will work step by step in any one of the processor leaving remain processor unused. Now the developers can make use of this particularly when working on complex algorithms or in case of need to handle multiple processes asynchronously.

Multi threaded programming is one of the way which gives developers an option to work with multiple threads concurrently. Even though this concept is been available since .net 1.1, its been avoided due to the complexity and developers need to write clean code in order to get performance using Multi threaded concept rather spending most of the time with business and functionality.


Using Normal Process

Consider a real time example of a web page having a Tab Control, as per the normal programming each tab will be loaded sequentially as per the business and not in parallel. Definitely it takes more time to load the contents to different tabs from each data source.

Normal Process


Using Parallel Process

Normal processing uses only a single processor even though the other processors are idle over there. But when using parallel processing (using Parallel Library) the other processors are also used to execute the core functionality which gives application a much performance.

Finally Multi Threaded application works on both multi core and also on a single core processor as it’s based on the hardware configuration. Underneath the code will be working on the single thread if it goes to a single processor and multiple threads if it goes to a multi processor.

Parallel Process


Concurrent Processing vs Parallel Processing


Concurrent Processing

In Concurrent programming several streams of functionality may be executed concurrently. Each one of the functionality operated in a sequential order process except that it communicate and interfere with one another. For Example: Two thread tasks Task1 and Task2 are concurrent if the order in which the tasks are executed is not predetermined. The possible execution is as follows.

  • Task1 may be executed and completed before Task2
  • Task2 may be executed and completed before Task1
  • Task1 and Task2 may need to be executed alternatively
  • Task1 and Task2 may be executed and completed simultaneously at the same time period (Parallelism)

Parallel Processing

In parallel Programming, it’s the process of executing the functionality by dividing into sub functionalities that are to be operated as concurrent programs. For Example: If two concurrent thread tasks are scheduled to run by OS and if these threads run on a single core processor we will get concurrency if the same is running on a multi core processor we will get parallelism.

So we can't say which is more efficient programming that the other, but neither is the superset of the other programming process. Based on the business requirement the processor can be selected and used in the application development process.


Parallel Programming Architecture


Architecture

Figure – Reference from http://msdn.microsoft.com/en-us/library/dd460693%28VS.100%29.aspx

Above architecture diagram explains in detail on how the parallel processing will takes and gets scheduled based on the needs. The main components of this architecture are as follow.

  • ·         Task Parallel Library
  • ·         Parallel LINQ (PLINQ)
  • ·         Task Schedulers
  • ·         Lambda Expressions in PLINQ

Conclusion

We will get into detail of each component and see how the process takes place in each component in the next upcoming article.

Page copy protected against web site content infringement by Copyscape

About the Author

Karthikanbarasan
Full Name: Karthikeyan Anbarasan
Member Level: Silver
Member Status: Member,Moderator,Microsoft_MVP,MVP
Member Since: 1/2/2011 3:00:14 AM
Country: India
Thanks Karthik www.f5Debug.net
www.f5Debug.net
www.f5Debug.net Around 5 years of experience in Microsoft technologies like ASP.Net, VB.Net, C#.net, SQL server, Biztalk Server, WCF, WPF, SSIS, SSRS, SSAS, AJAX and working as Senior Analyst in a US based MNC.

Login to vote for this post.

Comments or Responses

Posted by: Samarmir on: 1/17/2011 | Points: 25
Hi
Thanks for this article and the upcoming ones.
Just a silly question, is parallel programming equal to threading?
Posted by: Karthikanbarasan on: 1/17/2011 | Points: 25
Hi,

yes its almost equal to threading... but we have some enhancements added to on top of it to make better performance using it in development time.

Login to post response

Comment using Facebook(Author doesn't get notification)