private static CPUID[][] GroupThreadsByCore(IEnumerable <CPUID> threads) { SortedDictionary <uint, List <CPUID> > cores = new SortedDictionary <uint, List <CPUID> >(); foreach (CPUID thread in threads) { List <CPUID> coreList; cores.TryGetValue(thread.CoreId, out coreList); if (coreList == null) { coreList = new List <CPUID>(); cores.Add(thread.CoreId, coreList); } coreList.Add(thread); } CPUID[][] coreThreads = new CPUID[cores.Count][]; int index = 0; foreach (List <CPUID> list in cores.Values) { coreThreads[index] = list.ToArray(); index++; } return(coreThreads); }
private static CPUID[][] GetProcessorThreads() { List <CPUID> threads = new List <CPUID>(); for (int i = 0; i < 64; i++) { try { threads.Add(new CPUID(i)); } catch (ArgumentOutOfRangeException) { } } SortedDictionary <uint, List <CPUID> > processors = new SortedDictionary <uint, List <CPUID> >(); foreach (CPUID thread in threads) { List <CPUID> list; processors.TryGetValue(thread.ProcessorId, out list); if (list == null) { list = new List <CPUID>(); processors.Add(thread.ProcessorId, list); } list.Add(thread); } CPUID[][] processorThreads = new CPUID[processors.Count][]; int index = 0; foreach (List <CPUID> list in processors.Values) { processorThreads[index] = list.ToArray(); index++; } return(processorThreads); }