.NET Framework Bookmark and Share   
 index > .NET Base Class Library > How to calculate number of effective CPUs?
 

How to calculate number of effective CPUs?

Hi

I wonder if there is a simple call that will tell me the number of effective CPUs on the local computer?

I want to know so I can figure out how many threads to launch. I know I could simply launch "many" and allow them to time slice on the same CPU, but there is overhead in managing them.

I wrote a simple C# prog that measures the threaded execution time versus non-threaded, and it seems to work OK for my quad core, but it takes a few seconds to run and seems as though it might be inaccurate if other processes are running. I'm guessing there should be some CPU info call available but I'm new to C# and .NET.

Thanks

Greg
Greg Watson
Check out this article on Codeproject entitled Counting Physical and Logical Processors to see if that is what you are looking for...
OmegaMan
Check out this article on Codeproject entitled Counting Physical and Logical Processors to see if that is what you are looking for...
OmegaMan
If you see four processors, you probably have an Intel dual-core with hyperthreading support. While one core hyperthreading isn't as efficient as a true dual-core, it still does a credible job running two threads in parallel. In which case Environment.ProcessorCount might be good enough.
nobugz

You can use google to search for other answers

Custom Search

More Threads

• saving two images to the output stream at a time.
• How create nested namespace?
• Problems with reading from an INI file
• Problem With System.Reflection.Emit
• How to redirect STDOUT generated using WriteConsole in kernel32.dll?
• error CS0117: 'System.Web.UI.IPageHeader' does not contain a definition for 'Metadata'
• Handle exception under timer tick event
• Default value for a type T
• metaclass/class references
• MY.Resources help