I want to have a parallel function with different code paths depending on whether the function is being run in a system with an UMA or NUMA architecture, and I wonder how I can detect at runtime if the system is NUMA with more than 1 node.
I see Windows has some headers with kernel functions that can detect this, and Linux has a libnuma
library that could be linked against to determine NUMA capabilities, but such library is not guaranteed to always be available. I see also there's lscpu
in Linux as a command line utility that can get this info, but such function is not available in the BSDs.
Is there any reliable cross-platform and cross-compiler solution to detect at runtime if a program is being run on a system with NUMA architecture having more than 1 node?