Skip to content

Commit

Permalink
Fallback to GetThreadGroupAffinity if GetNativeSystemInfo reports wro…
Browse files Browse the repository at this point in the history
…ngly

Signed-off-by: Isaev, Ilya <[email protected]>
  • Loading branch information
isaevil committed Dec 16, 2024
1 parent 4719ac1 commit f3319f0
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/tbb/misc_ex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit f3319f0

Please sign in to comment.