Number of threads created per Core?
-
Monday, September 29, 2008 7:54 AM
Hi All,
I have started learning PFX library.I wrote a sample which finds Primary numbers. Ran the sample on a Dual core machine.
Noticed higher performance when Paralle.For loop was used .
When i went through the documentation , i came to know , for each core a single thread will be created ,and the work items will be queued to the worker thread.
I used Intel VTUNE and also used Process Explorer ( Systnternals) to check number of threads created.
Both the tools reported 4 worker threads created to run the code.
I even ran the parallel code on a Quad Core machine , the result was 8 worker threads created to run the code ,rest were system threads..
Why does PFX create 2 worker threads per core ,but the documentation says one worker thread per core.
Following is the sample code written
private
static void CalculatePrimeParalell(List<int> primesList, int max){
Parallel.For(3, max, delegate(int i){
bool isNotPrime = false; for (int j = 0; j < primesList.Count; j++){
if(primesList[j]>0){
if (i % primesList[j] == 0)
true;isNotPrime =
}
}
if (isNotPrime == false)primesList.Add(i);
});
}
}
Thanks in advance.
- Edited by Narendra Monster Sunday, February 15, 2009 5:36 PM
All Replies
-
Monday, September 29, 2008 12:10 PMThe reason is that CLR handles not physical but logical cores. I guess your system is Intel based with the hyper-threading enabled. Thus, when using dual core machine, we have 2 physical cores x 2 = 4 virtual processors.
Good luck. -
Monday, September 29, 2008 2:16 PMOwner
narendra_007, you're correct that, by default, the June 2008 CTP is creating two threads per logical processor (i.e. Environment.ProcessorCount). The CTP didn't have thread injection support yet (i.e. adding more threads when the system detects they're needed), and thus deadlocks became much more likely. To make them a little less likely by default, we started with twice as many threads as were actually needed. As mentioned, this was just a temporary workaround for the CTP release.
-
Thursday, October 02, 2008 6:45 AM
Hey thanks Stephen for helping me .
I am really amazed with the ease of writing multi threaded parallel applications using PFX.
Could you tell me whether current CTP reelease is fit enough to be used in Project development . Now i am in an planning phase of a new Project .
Once i get a reply from you , i have to propose to my CTO about the usage model of PFX in the project .
Regards,
Narendra Kumar.A
Software Engineer
Sportingmindz Technology Pvt Ltd
- Marked As Answer by Narendra Monster Wednesday, December 03, 2008 2:32 PM
- Unmarked As Answer by Narendra Monster Wednesday, December 03, 2008 2:32 PM
-
Thursday, October 02, 2008 3:01 PMOwner
Narendra, great to here it's helping you out. You should definitely be able to start factoring it in during your planning phase; just keep in mind that the June CTP isn't meant for production use. You might be interested in the following article from the October 2008 issue of MSDN Magazine, which just went online yesterday:
-
Friday, October 03, 2008 8:45 AM
Hi Leon , this reply is for you.
My question was incomplete without mentioning about Hardware.
I tested the sample code in Intel Core 2 Duo and Intel Core 2 Quad processors. Both the processors does not support Hyer-Threading technology . Any way i got answer to my question..
Thanks,
Narendra Kumar. A
Sportingmindz Technology Pvt Ltd

