From f3319f0ede2432a04e51cc286e9df0e8a6efac26 Mon Sep 17 00:00:00 2001 From: "Isaev, Ilya" Date: Mon, 16 Dec 2024 20:08:20 +0100 Subject: [PATCH 1/2] Fallback to GetThreadGroupAffinity if GetNativeSystemInfo reports wrongly Signed-off-by: Isaev, Ilya --- src/tbb/misc_ex.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) 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); From 2577389f6d3f946ad289ba645361d7241ab96d65 Mon Sep 17 00:00:00 2001 From: "Isaev, Ilya" Date: Wed, 18 Dec 2024 10:20:54 +0100 Subject: [PATCH 2/2] Fix copyright Signed-off-by: Isaev, Ilya --- src/tbb/misc_ex.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/tbb/misc_ex.cpp b/src/tbb/misc_ex.cpp index 3eaf33fca1..03b33b464f 100644 --- a/src/tbb/misc_ex.cpp +++ b/src/tbb/misc_ex.cpp @@ -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. @@ -302,7 +302,7 @@ static void initialize_hardware_concurrency_info () { // 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)) { + if (TBB_GetThreadGroupAffinity(GetCurrentThread(), &ga)) { number_of_processors = (int)TBB_GetActiveProcessorCount(ga.Group); } }