Skip to content

Commit 8659619

Browse files
authored
Fallback to GetThreadGroupAffinity if GetNativeSystemInfo reports wrongly (#1587)
Signed-off-by: Isaev, Ilya <[email protected]>
1 parent 503fdb2 commit 8659619

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

src/tbb/misc_ex.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (c) 2005-2023 Intel Corporation
2+
Copyright (c) 2005-2024 Intel Corporation
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.
@@ -297,11 +297,21 @@ static void initialize_hardware_concurrency_info () {
297297
if ( pam & m )
298298
++nproc;
299299
}
300-
__TBB_ASSERT( nproc <= (int)si.dwNumberOfProcessors, nullptr);
300+
int number_of_processors = (int)si.dwNumberOfProcessors;
301+
if (nproc > number_of_processors && TBB_GetThreadGroupAffinity) {
302+
// Sometimes on systems with multiple processor groups GetNativeSystemInfo
303+
// reports mask and processor count from the parent process
304+
TBB_GROUP_AFFINITY ga;
305+
if (TBB_GetThreadGroupAffinity(GetCurrentThread(), &ga)) {
306+
number_of_processors = (int)TBB_GetActiveProcessorCount(ga.Group);
307+
}
308+
}
309+
310+
__TBB_ASSERT( nproc <= number_of_processors, nullptr);
301311
// By default setting up a number of processors for one processor group
302312
theProcessorGroups[0].numProcs = theProcessorGroups[0].numProcsRunningTotal = nproc;
303313
// Setting up processor groups in case the process does not restrict affinity mask and more than one processor group is present
304-
if ( nproc == (int)si.dwNumberOfProcessors && TBB_GetActiveProcessorCount ) {
314+
if ( nproc == number_of_processors && TBB_GetActiveProcessorCount ) {
305315
// The process does not have restricting affinity mask and multiple processor groups are possible
306316
ProcessorGroupInfo::NumGroups = (int)TBB_GetActiveProcessorGroupCount();
307317
__TBB_ASSERT( ProcessorGroupInfo::NumGroups <= MaxProcessorGroups, nullptr);

0 commit comments

Comments
 (0)