Question

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?

Était-ce utile?

La solution

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.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top