Mar
04

All those things I’ve been talking about…

Well, I finally got a really rough prototype going of some C# code making my sandbox engine create a renderer and attach it to a .NET window. Here’s a screenie…

A screenshot of the SuperNova engine using DirectX to draw into a .NET Windows Forms window

SuperNova drawing into a .NET window

Jan
27

Lambda expressions in C# – How useful are they really?

I’m currently working on a project where we are using a technology called DDS (Data Distribution Service). DDS is a Publish/Subscribe technology for Inter-Process Communication. It is fast, and very flexible in terms of the Quality-of-Service that you want. Now, I have developed a framework around it so that various parts of our application need only interact with a state class, and in fact they can register to be notified of changes to properties on these state classes. These state classes effectively register an interest in a particular Topic (the fundamental unit of data within DDS, a collection of repeated fields, a single occurrence of which is called a Sample). Now, when a class uses my framework to register an interest in a particular topic, it supplies an Action<T> which is used to process Samples of the Topic in question. In some cases I have passed a C# Lambda Expression in as the Action, but I find a key problem with these lambdas is that they are very hard to test (I’m pretty much doing TDD, not quite, but pretty much). I’m leaning towards the idea that if you can’t test it easily, it isn’t all that useful as language element. I’m interested to see what people think.

Dec
02

Windows Phone 7 game “Get Kicking” out now!

My first Windows Phone 7 game “Get Kicking” is available now on the Windows Phone 7 Marketplace: http://social.zune.net/redirect?type=phoneApp&id=72d6c3a5-a6f9-df11-9264-00237de2db9e

Oct
30

Windows Phone 7 Challenge Entry is in…

I’ve been working on an entry for the Windows Phone 7 Challenge the Microsoft NZ are running. The game is done (not withstanding a few minor tweaks), and the video has been uploaded to youtube. Check it out below:

Jul
06

.NET 4.0 and the Task Parallel Library (TPL)

I’ve been tasked with presenting a training session at work on the new concurrent programming features in the .NET Framework 4.0, so I’ve been playing around with a Mandelbrot set visualiser for which I have written three routines: a sequential routine, a (potentially) each line can be calculated in parallel, and a third where (potentially) each pixel can be calculated in parallel. I say “potentially” because the resource manager underneath the TPL actually manages the threading for you. In essence, when using a technique like Parallel.For you create a lambda function for the loop body, any single iteration of which could be executed in parallel to any other iteration of the loop body, and the TPL takes care of scheduling these iterations across some magically optimized number of threads.

My sequential code is a nested for loop where the out loop iterates y and the inner loop iterates x. In the Parallel.For version of the visualiser I replace the outer loop with a Parallel.For like so:

Parallel.For(0, parameters.imageHeight, y =>
{
    double c_im = parameters.maxIm - y * parameters.imFactor;
    for (uint x = 0; x < parameters.imageWidth; ++x)
    {
        mandelbrotPixel(bmd, (uint)y, c_im, x);
    }
});

What this means is that the TPL will try to run as many iterations of the body of the lambda function in parallel as is sensible.

So, onto the results. I ran the same program on my work machine (Core2 Duo, 4GB RAM, Vista 32) and my home machine (Core2 Quad, 2GB RAM, Windows 7 64), and got the following results:

Test        |     Time (work)        | Time (home)
-------------------------------------------
Sequential  | 9.480s                 | 9.373s
Parallel.For| 4.540s                 | 2.451s
Nested P.F  | 4.300s                 | 2.403s

As you can see, by simply running the code on a machine with two more cores, the runtime was halved.

In order to get the run-times large enough for changes in performance to be meaningful I made the application generate a 4096 by 4096 image.

Take a look at the source code here: ParallelProgramming.zip, it’s a Visual Studio 2010 solution, but the code is fairly straightforward.

Older posts «

» Newer posts