Daniel Moth recently blogged about the sad fact that there are no managed APIs for working with more than 64 logical processors, even though as you probably know, Windows 7 (and of course Windows Server 2008 R2) features support for up to 256 logical processors.
Frankly, these APIs aren’t designed to be very friendly, but sure enough they give you the ability to create threads (within a single process) that will run on different processor groups. As each processor group is limited to 64 processors, by creating 4 threads you can utilize up to 256 processors, which is currently the cap.
I’ve decided to write a C++/CLI wrapper titled Multi-Processor Extensions for .NET (published on CodePlex today) that wraps these native APIs. Among them you’ll find:
- Logical processor information (GetLogicalProcessorInformationEx), including cache relationships, processors and processor groups, NUMA nodes and everything else
- NUMA information, including memory available on each node, NUMA node per process allocation etc.
- Facilities for modifying the processor group affinity of a thread, retrieving the processor group affinity of a process and creating a new process inheriting the parent’s processor group affinity (which is not the default)
Some example use:
foreach (ProcessorGroup group in Processor.ProcessorGroups)
Console.WriteLine("Processors in group: " + group.Processors);
foreach (NumaNodeRelationship numa in Processor.GetNumaNodeRelationships())
Console.WriteLine("NUMA node number: " + numa.NodeNumber);
foreach (CacheRelationship cache in Processor.GetCacheRelationships())
Console.WriteLine("Cache: " + cache.Type + " " + cache.CacheSize);
Console.WriteLine("Memory on NUMA node 0: " + Numa.GetAvailableMemory(0));
Admittedly I haven’t wrapped the API for creating a new thread and assigning it to a processor group that is different from the processor group of its creating process, but I did wrap the API for modifying the processor group of a thread, so you can still do it in two steps. If there’s much demand, I will add it later, or you can do it yourself (you need to use the new API for modifying extended process & thread attributes).
If you’re the lucky owner of dedicated hardware with more than 64 logical processors, please give these wrappers a try and see if they work