Just sharing some of my inconsequential lunch conversations with you... RSS  

Saturday, December 01, 2007

Running Queries On Multi-Core Processors - the 1 core case

As a general rule I develop on VMs, using VMWare Player. Yes, VMWare player just throws you a single thread of execution from the host OS, but most of the software I used was single threaded anyway, so I really didn't miss that much of the 2nd core lying there in my host OS. Now VS2k8 uses all the threads I can throw it, so I'll probably have to look for another virtualization solution.

So I've decided to do my first PLINQ tests on this 1 CPU virtual machines. It obviously cannot be faster than LINQ, but will it be as fast? Here's a silly test:


var query = ParallelEnumerable.Range(1, 10000)
.AsParallel()
.Where(x => x * x < 100)
.OrderBy(x => x % 2)
.Select(x => x);

And here are the results (after looping 10000 times):

PLINQ: 00:00:05.3483487
LINQ : 00:00:02.0147759

Ok, not really a problem, it makes sense - in many other queries the difference wouldn't be as hard - and single core machines are harder to find these days. The question is: should PLINQ automatic downgrade to LINQ when a single thread of execution was found?

My opinion is: absolutely not! With the PLINQ version we can't predict the order like in the LINQ version (this will probably introduce a new class of problem to people used to single threaded programming). But as this affects the predictability of the results, this should be a programmers decision, not PLINQ's. It could, however, accept some hint.

Can't wait to put my hands on a 2 SMP 4 cores machine to do some real fun tests. Until then I'll continue reading Running Queries On Multi-Core Processors. Yeap, because if you were expecting a bunch of samples to mess with, think again, not much there to play.

Can't wait either to read the WideFinder results on PLINQ - expect them to be a fun test on PLINQ.

PS: don't forget to add the reference to "C:\Program Files\Microsoft Parallel Extensions Dec07 CTP\System.Threading.dll"

No comments:

Development Catharsis :: Copyright 2006 Mário Romano