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