|
1 | 1 | /* |
2 | | - Copyright (c) 2005-2023 Intel Corporation |
| 2 | + Copyright (c) 2005-2024 Intel Corporation |
3 | 3 |
|
4 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); |
5 | 5 | you may not use this file except in compliance with the License. |
@@ -297,11 +297,21 @@ static void initialize_hardware_concurrency_info () { |
297 | 297 | if ( pam & m ) |
298 | 298 | ++nproc; |
299 | 299 | } |
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); |
301 | 311 | // By default setting up a number of processors for one processor group |
302 | 312 | theProcessorGroups[0].numProcs = theProcessorGroups[0].numProcsRunningTotal = nproc; |
303 | 313 | // 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 ) { |
305 | 315 | // The process does not have restricting affinity mask and multiple processor groups are possible |
306 | 316 | ProcessorGroupInfo::NumGroups = (int)TBB_GetActiveProcessorGroupCount(); |
307 | 317 | __TBB_ASSERT( ProcessorGroupInfo::NumGroups <= MaxProcessorGroups, nullptr); |
|
0 commit comments