I'm developing some C++ multi-core programs with a variable number of threads and I'd like to know how to set a proper (actually "the best") affinity. I use Boost-threads, so I can call get_hardware_concurrency() to know how many logical cores there are. Until now, I wrote a mapping "n_th thread to n-th logical core", but it's not the most smart thing to do, due to multi-socket processors and HyperThreading. My programs are always SIMD-like, so threads have nothing to share between them and, in case of an HT computer, I'd like to bind threads to logical cores in the smartest way I can imagine: 1st logical core on 1st physical, 1st logical on 2nd physical, ... , 1st logical on n-th physical, 2nd logical on 1st physical and so on.
I found a lot of stuff where is discussed how to discover whether HT is enabled or not (CPUID) and how to determine logical and physical cores PER package. I know I have to deal with some assembly code, and it doesn't scare me, but I really couldn't find how to know complete informations about logical cores, physical cores, and packages and how OS deals with all of that.
Being the most concise I can: how can I know the exact location (physical core and package) of the thread referred by OS (Windows and Linux) as N-th ?