Just out of curiosity I would like to know how many processor cores the .NET task scheduler supports.
Windows Server 2012 supports up to 640 cores. Was (is) .NET limited to 64 or would it use all available cores?
Just out of curiosity I would like to know how many processor cores the .NET task scheduler supports.
Windows Server 2012 supports up to 640 cores. Was (is) .NET limited to 64 or would it use all available cores?
.NET does support all cores. Answer from Stehphen Toub in the MSDN Parallel Extensions Forum:
The default TPL
TaskScheduler
targets the .NETThreadPool
. By default, the pool is restricted to a single processor group, and thus to 64 cores. However, in .NET 4.5 you can set the<Thread_UseAllCpuGroups enabled="true"/>
flag. When your computer has multiple CPU groups, enabling this element causes the runtime to distribute managed threads across all CPU groups rather than being limited to just one, and thus the default scheduler can target whatever the OS supports. (GCCpuGroup
must also be enabled for this setting to take effect.)
By Eric Lippert (source)
For Beta 1 of CLR 4.0, the default scheduler for TPL will be the CLR thread pool
This roughly means that the work comes into a FIFO queue and each core dequeues a workload item. In other words, now there is no fixed upper boundary for the number of cores that CLR threadpool supports. This upper boundary is enforced by other parties - OS, hardware and CPU platform.
The default number of threads in a pool (per this answer)
- 1023 in Framework 4.0 (32-bit environment)
- 32768 in Framework 4.0 (64-bit environment)
- 250 per core in Framework 3.5
- 25 per core in Framework 2.0
Which technically allows that many parallel executions on dedicated cores.
Note it doesn't mean, that at any given moment of time, there are that many threads in a pool. CLR and OS generally try to slowly decrease the number of threads in a pool to release the resources which are not used.
According to CLR via C#, 3rd ed., chapter 25 Thread Basics:
Today, the CLR […] can only use up to 64 cores when running on 64-bit Windows. [… M]anaged applications can use up to 32 cores when running on a 32-bit version of Windows.
The book was written in 2010, so it contains information relevant to .Net 4.0 and Windows Server 2008 R2, but I don't think .Net 4.5 changed anything in this regard. EDIT: It seems .Net 4.5 did actually change this, see Peter Meinl's answer quoting Stephen Toub.