문제

I have noticed that several of my multi-threaded calculations run faster if I disable hyper-threading in the BIOS.

I have also learnt that I can programmatically disable the (logical) CPU:s by modifying the processor affinity for the current process, for example like this in C#:

// using System.Diagnostics;
var current = Process.GetCurrentProcess();
var affinity = current.ProcessorAffinity.ToInt32();
current.ProcessorAffinity = new IntPtr(affinity & 0x5555);

At least from a performance point of view, will disabling every second (logical) CPU by changing processor affinity have the same effect as disabling hyperthreading altogether?

도움이 되었습니까?

해결책

You can try utilizing the NUMA APIs, or manually discover CPU topology with the CPUID instruction... But IMHOthe best solution is doing some sane defaults, and let the end-user tweak threading settings. Unless you have a specific hardware target, there's a fair amou t of possible scenarios to handle - logical vs. physical cores, hyper-threading or not, single- vs. multi-socket systems, cache and memory topology.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top