Skip to content

Commit

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

Signed-off-by: Isaev, Ilya <ilya.isaev@intel.com>
  • Loading branch information
isaevil authored Dec 20, 2024
1 parent 503fdb2 commit 8659619
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/tbb/misc_ex.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (c) 2005-2023 Intel Corporation
Copyright (c) 2005-2024 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down 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 8659619

Please sign in to comment.