views:

83

answers:

4

Are there any .NET classes/functions that are optimized for multiple cores?

I know that the developer is supposed to do this himself/herself. But seeing how we are getting CPUs with more and more cores and there are still many developers who do not use multithreading, if we have this functionality built in, it could increase performance dramatically in some scenarios.

One particular example where this could be quite useful is in image processing. I doubt that the built in GDI+ classes are multithreaded.

+6  A: 

All the parallel extensions for .NET?

http://blogs.msdn.com/pfxteam/

jvenema
+2  A: 

You could consider PLINQ made for multicore CPUs.

http://en.wikipedia.org/wiki/PLINQ#PLINQ

JTA
+4  A: 

Take a look at this (discusses, among other parallelization-related things, the Task Parallel Library).

New to .NET 4.0, "the purpose of the TPL is to make developers more productive by simplifying the process of adding parallelism and concurrency to applications." Sounds pretty similar to what you're looking for.

And, since you mentioned image processing as a good scenario where taking advantage of multiple processors would be warranted, check out this blog post in which the author does just that.

Hope this is helpful!

Donut
+2  A: 

Definitely take a look at the Task Parallel Library, which was specifically created in .NET 4 to improve multi-threaded operations, which is using the new improvements in the .NET Thread Pool (improved a lot in .NET 4, and optimised for multi-core / multi-processor machines)!

You can also check out the videos in Channel 9 tagged Parallel Computing which display a lot of working examples of using these new structures and classes, if if you want some theoretical discussion - check this discussion with Stephen Toub from the parallel extensions team about Multi-Core and Parallel Programming Practices

Finally I've added this question of SO, talking about multithreading improvements in .NET 4

UPD: Looking at your particular example with GDI: what exactly do you imagine they could do with it to make with multithreaded?
The applications that use GDI to draw can be multithreaded and process data in multiple threads. Also, making things run in parallel changes the way your code works. You can't just "make it work" in multiple threads, and "optimising for multiple cores" isn't just as simple as adding a compiler directive. This means a whole new approach to using this api.

Finally I have to add, that Mucrosoft is slowly moving away from the older windows API, like GDI towards things like WPF, where the whole interface is powered and enhanced using your GPU. This takes a lot of the processing power from the CPU and towards GPU, where these operations are processed a lot faster and better.

Artiom Chilaru
Well i guess if you are drawing several thousand pixels to a Graphics object it would be much faster if the class that does the drawing multithreads the task. I am not saying it suitable in all scenarios but there are certainly many resource consuming methods that can be optimized.
diamandiev
Actually, I think you should be the one that multi-threads your code, not the gdi library. Sure, it really depends on the situation, but still, you should have multiple threads for generation of the data / preparing it for rendering, and then you send it to the gdi to display it on screen :)
Artiom Chilaru
not saying here that MS apis are all optimised.. Even they themselves accept that it's not.. but still :P
Artiom Chilaru