views:

215

answers:

4

Hello.

I was wondering if anyone knows about a good article which describes dividing workload on to several Threads? Preferebly it would be written for C# but it's really the concept I'm after, so it's not an issue if it's written for a different, similar, language.

I have a problem where I would have to divide a large amount of computing into several threads and then Sum the generated data after one iteration completes (so I would need to know that all threads have finished) and then start a new iteration, supplying all the threads with the data generated in the last iteration (the data would be modified before the end of each iteration).

I hope this makes sense, and is possible. Either way I would appreciate some advice on how to tackle the problem of computing large amounts of data divided on to several threads (so I can use more than one processor's core).

Thank you for your answers!

+3  A: 

"Parallel Extensions" is designed for this, in particular the Parallel class (which allows you to split work up between the threads very easily). The aggregation of results is trickier; some quick searching shows some mixed results - but I don't know what will be in the final release (i.e. it could be easier).

The CTP is available here, or wait for .NET 4.0.

Marc Gravell
+6  A: 

You should look at Parallel FX (PFX), you can find the blog here and the download link here (Thanks Marc).

Unfortunately I don't know if this will be released for .NET 2.0/3.5 as it is currently slated for .NET 4.0.

If you're looking at implementing it yourself, look into Work Stealing Algorithms.

There is also a library named Power Threading, by Jeffrey Richter from Wintellect which has some rather good classes available for you.

Lasse V. Karlsen
CTP: http://www.microsoft.com/downloads/details.aspx?FamilyId=348F73FD-593D-4B3C-B055-694C50D2B0F3
Marc Gravell
+4  A: 

Lasse and Marc have already spoken about Parallel Extensions. I have a couple of blog articles (with code) about using and benchmarking it:

These might be helpful to show various different ways that work can be broken up.

Jon Skeet
A: 

Paint.NET does this quite well (for image processing) and the source code to older versions of might still be freely available somewhere.

For more information, please move over to my question regarding a white paper by the author I once saw about this subject. When I wanted to show that article it to a co-worker recently I (that is: Google) was not able to find this any more, hence the question.

peSHIr