From: oan Date: Thu, 14 Mar 2019 16:22:04 +0000 (+0300) Subject: 0030573: OSD_Parallel_TBB: limit number of execution threads using settings of OSD_Th... X-Git-Tag: V7_4_0_beta~212 X-Git-Url: http://git.dev.opencascade.org/gitweb/?a=commitdiff_plain;h=e9fb0cba580f4012825eac0ad87b68a6bafd175f;p=occt.git 0030573: OSD_Parallel_TBB: limit number of execution threads using settings of OSD_ThreadPool::DefaultPool() Add tbb::task_scheduler_init to OSD_Parallel::forEach(). --- diff --git a/src/OSD/OSD_Parallel_TBB.cxx b/src/OSD/OSD_Parallel_TBB.cxx index 508119f393..425fdf2ea6 100644 --- a/src/OSD/OSD_Parallel_TBB.cxx +++ b/src/OSD/OSD_Parallel_TBB.cxx @@ -18,11 +18,13 @@ #ifdef HAVE_TBB #include +#include #include #include #include #include +#include //======================================================================= //function : forEach @@ -34,15 +36,19 @@ void OSD_Parallel::forEach (UniversalIterator& theBegin, const FunctorInterface& theFunctor, Standard_Integer theNbItems) { - (void )theNbItems; try { - tbb::parallel_for_each(theBegin, theEnd, theFunctor); + const Handle(OSD_ThreadPool)& aThreadPool = OSD_ThreadPool::DefaultPool(); + const Standard_Integer aNbThreads = theNbItems > 0 ? + Min (theNbItems, aThreadPool->NbDefaultThreadsToLaunch()) : -1; + + tbb::task_scheduler_init aScheduler (aNbThreads); + tbb::parallel_for_each (theBegin, theEnd, theFunctor); } catch (tbb::captured_exception& anException) { - throw Standard_ProgramError(anException.what()); + throw Standard_ProgramError (anException.what()); } } -#endif /* HAVE_TBB */ \ No newline at end of file +#endif /* HAVE_TBB */