+/// get_group() retrieves logical processor information using Windows specific
+/// API and returns the best group id for the thread with index idx. Original
+/// code from Texel by Peter Ă–sterlund.
+
+int get_group(size_t idx) {
+
+ int threads = 0;
+ int nodes = 0;
+ int cores = 0;
+ DWORD returnLength = 0;
+ DWORD byteOffset = 0;
+
+ // Early exit if the needed API are not available at runtime
+ HMODULE k32 = GetModuleHandle("Kernel32.dll");
+ if ( !GetProcAddress(k32, "GetLogicalProcessorInformationEx")
+ || !GetProcAddress(k32, "GetNumaNodeProcessorMaskEx")
+ || !GetProcAddress(k32, "SetThreadGroupAffinity"))
+ return -1;