Parallel Extension in .NET 4.0 (Part 1 - Introduction and Motivation)

I still remembered that I asked Risman few months ago “what’s your favorite feature in .NET 4.0?”. He replied me “parallel extension”. Then I answered him “me too…”.

Yes, I find that this is the most useful API for developer.

 

Let me begin the story Wink.

While clock speed is reaching the limit because of high power consumption as well as high temperature, microprocessor company such as Intel and AMD produce their multi-core processor as the new solution. The idea of multi-core processor is to attach two or more core processor into the CPU. People usually are more familiar with the term Core2Duo / Dual Core /etc. I know that people usually get confuse what’s the difference between Core2Duo and Dual Core, check out the discussion here.

People sometimes are so proud with their multi-core computer without knowing an important fact that the the multi-core processor without the multi-core enabled application are worthless. More or less, it will still run as single core performance if the software cannot take advantage on it. That’s one of the reason why sometimes people keep mumbling that their PC still run slowly even though with their C2D processor. Come on, processor is only one of the so many factor that affect our PC Smile!

The Experiment

Let me show you a little experiment to prove about that. Over here, I have a simple application that will query on a huge XML file that potentially takes quite long time.

This application therefore could enable us to select number of core on your processor. Since my laptop is running on 2 cores, so I will have selection to use one core or two cores. Of course, if you have quadcore, you will have to be able to select up to four cores.

image

Next, I have two buttons, one is LINQ and another one is PLINQ. Note that, I haven’t discussed what is PLINQ here, so just bear that in mind that LINQ is the normal query using Language Integrated Query syntax, while PLINQ is LINQ with parallelism capability. Let’s do with few scenarios as following:

1. Using one core processor

a. LINQ

The first scenario is using one core processor to query with conventional LINQ query.

 image

The result shows 19.31 seconds to finish the query.

b. PLINQ

How about using PLINQ? Let’s try.

image

The result shows 19.37 seconds. No much different. In fact, more or less actually they work exactly the same.

What does it mean? Finding no 1. It means that no matter what the query style you use (LINQ or PLINQ), in one core processor environment, you will get the same result.

2. Using 2 cores processor

Now, let’s set the processor to two cores and see what happen.

a. LINQ

image

We get 18.22 seconds on this experiment. It seems like slightly improve a bit, but it still very very slight, yet probably we can ignore it.

b. PLINQ

Let’s see if we could get better result when we are querying with PLINQ in two cores processor.

image

Aha!!! Now I only get 9.68 seconds to finish the query. It’s almost 1.88 times faster than before. This is what I’ve been expected.

So, what do learn from this experiment again? Finding no 2. No matter how many core processor you have, if you query using conventional style (I mean without parallelism), you will get more or less the same result with one core processor.

Finding no 3. The performance will increase significantly only when you use parallel technique in multi-core processor.

Let’s summarize our experiment in more concise view

# of core Conventional Query / LINQ Parallel-enabled Query / PLINQ
1 core 19.31 seconds 19.31 seconds
2 cores 18.22 seconds 9.68 seconds

Our findings

Finding no 1. It means that no matter what’s the query style you use (LINQ or PLINQ), in one core processor environment, you will get the same result.

Finding no 2. No matter how many core processor you have, if you query using conventional style (I mean without parallelism), you will get more or less the same result with one core processor.

Finding no 3. The performance will increase significantly only when you use parallel technique in multi-core processor.

However, creating the multi-core enabled application is still a tough job for most developer including .NET developer. They will have to directly deal with threading related stuff and take care of it manually. This usually become stumble to developer to do so.

In the subsequent post, I’ll show you how parallel extension come to make our life easier. Stay tuned Smile

Share this post: | | | |
Published Tuesday, February 02, 2010 7:12 AM by Wely

Comments

# Twitter Trackbacks for Parallel Extension in .NET 4.0 (Part 1 - Introduction and Motivation) - Wely [netindonesia.net] on Topsy.com

Pingback from  Twitter Trackbacks for                 Parallel Extension in .NET 4.0 (Part 1 - Introduction and Motivation) - Wely         [netindonesia.net]        on Topsy.com

# Parallel Extension in .NET 4.0 (Part 2 – Task Parallel Library)

Saturday, March 27, 2010 11:12 AM by Wely

Introduction This is the second post of Parallel Extension series. You can read my first post about the

# Parallel Extension in .NET 4.0 (Part 3 – PLINQ)

Friday, April 16, 2010 9:44 AM by Wely

I am very delighted as Visual Studio 2010 has finally released on last 12 April 2010. Now let me continue

# Parallel Extension in .NET 4.0 (Part 4 – Debugging Support from IDE)

Monday, April 26, 2010 7:59 PM by Wely

What we have cover so far? So far in the Parallel Extension series, I’ve talked about: Introduction and

# Parallel Extension in .NET 4.0 (Part 5 – Visualization Support from IDE)

Sunday, May 02, 2010 7:36 PM by Wely Lau

What we have cover so far? So far in the Parallel Extension series, I’ve talked about: Introduction and

Powered by Community Server (Commercial Edition), by Telligent Systems