views:

4502

answers:

6

Is there any easy way to explicitly make an already threaded application utilise a multicore environment? (if avaliable).

The first problem would be how do I determine if my runtime environment supports multi-core applications?

If I then determine that I can use multi core functionality, can I explicitly assign threads to run on different cores? If so Is the thread communication handled by the OS/Hardware or do I have to get my hands dirty?

A: 

Without getting into specifics (I'm not sure how much information is public yet), the next version of the .NET framework will be more helpful with doing this. You will likely not want or need to be thinking about managing threads by hand. I'm sure more information will be public about this after PDC (end of October).

Nick
+8  A: 

If your application is already threaded properly, you dont have to do anything. Thread context execution and handling is done for you.

Now when it comes to threading, is your app threaded in a way to utilize the cores? do you have processor intensive tasks split into seperate threads. If not, then you will need to make changes to split up your processing tasks into more threads. You can use Environment.ProcessorCount to get the core count and make as many threads as appropriate at runtime for your tasks.

As of now, there is not really any way to make an improperly threaded app(single thread) into a threaded app taking advantage of all the processors/cores, unless you look to future technologies, such as plinq and Parallel FX

mattlant
+1  A: 

Hi there are 2 extentions that I know about

Parallel C# Homepage

Check out Somasegars MSDN blog on MS June CTP for parallel 3.5 extenstions

MSDN

The library is made up of the following components:

  • The Task Parallel Library (TPL), which provides support for imperative data and task parallelism.
  • Parallel LINQ (PLINQ), which provides support for declarative data parallelism.
  • Coordination Data Structures (CDS), which provide support for work coordination and managing shared state.
+1  A: 

Currently, you can set the available processors for a given process using Process.ProcessorAffinity, but assigning specific threads to specific processors is handled under the hood implicitly. This is actually a good thing most of the time, as an intelligent runtime using real-time performance and load balance information can usually do a better job than you can statically, at least for the few-core context mainstream multicore operates in.

Matt J
+1  A: 

That's the problem. How to make a threaded application, how to convert your existing code. I want to exploit multi-core in C#. However, ParallelFX is still beta. I won't develop using a beta. And, I don't want to change all the code again (I translated my apps from VB 6). Today, I received a newsletter from Packt Publishing announcing a new book about parallel programming with C#. C# 2008 and 2005 Threaded Programming. I think it focuses in the things we are blogging about everywhere. How to think and develop a threaded application without waiting for a new miracle language. It's cool to see books entirely dedicated about the topic, because we have full of blogs about that. The link is http://www.packtpub.com/beginners-guide-for-C-sharp-2008-and-2005-threaded-programming/book I think it deserves an apportunity. I'll let you know my feedback when I buy it.

A: 

Finally, I bought the e-book version of the book "C# 2008 and 2005 threaded programming", by Gaston C. Hillar - Packt Publishing, 5 days ago. I downloaded the code and I began following the exercises. The book is a nice guide with a lot of code to practice. I read the first 6 chapters. It tells stories while it explains the most difficult concepts. That's good. It's nice to read. I could see my Core 2 Quad Q6700 reach 98% CPU usage programming in C# using 4 concurrent threads!! It is easier than I thought. I am impressed with the results you can achieve using many cores at the same time. I recommend the book to those who are interested in beginning with multicore or threaded programming using C#.