diff --git a/src/tbb/misc_ex.cpp b/src/tbb/misc_ex.cpp index 13b7b04fb1..3eaf33fca1 100644 --- a/src/tbb/misc_ex.cpp +++ b/src/tbb/misc_ex.cpp @@ -297,11 +297,21 @@ static void initialize_hardware_concurrency_info () { if ( pam & m ) ++nproc; } - __TBB_ASSERT( nproc <= (int)si.dwNumberOfProcessors, nullptr); + int number_of_processors = (int)si.dwNumberOfProcessors; + if (nproc > number_of_processors && TBB_GetThreadGroupAffinity) { + // Sometimes on systems with multiple processor groups GetNativeSystemInfo + // reports mask and processor count from the parent process + TBB_GROUP_AFFINITY ga; + if (TBB_GetThreadGroupAffinity( GetCurrentThread(), &ga)) { + number_of_processors = (int)TBB_GetActiveProcessorCount(ga.Group); + } + } + + __TBB_ASSERT( nproc <= number_of_processors, nullptr); // By default setting up a number of processors for one processor group theProcessorGroups[0].numProcs = theProcessorGroups[0].numProcsRunningTotal = nproc; // Setting up processor groups in case the process does not restrict affinity mask and more than one processor group is present - if ( nproc == (int)si.dwNumberOfProcessors && TBB_GetActiveProcessorCount ) { + if ( nproc == number_of_processors && TBB_GetActiveProcessorCount ) { // The process does not have restricting affinity mask and multiple processor groups are possible ProcessorGroupInfo::NumGroups = (int)TBB_GetActiveProcessorGroupCount(); __TBB_ASSERT( ProcessorGroupInfo::NumGroups <= MaxProcessorGroups, nullptr);