1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-04-10 18:51:21 +03:00

0030573: OSD_Parallel_TBB: limit number of execution threads using settings of OSD_ThreadPool::DefaultPool()

Add tbb::task_scheduler_init to OSD_Parallel::forEach().
This commit is contained in:
oan 2019-03-14 19:22:04 +03:00 committed by apn
parent f2b42160f4
commit e9fb0cba58

View File

@ -18,11 +18,13 @@
#ifdef HAVE_TBB #ifdef HAVE_TBB
#include <OSD_Parallel.hxx> #include <OSD_Parallel.hxx>
#include <OSD_ThreadPool.hxx>
#include <Standard_ProgramError.hxx> #include <Standard_ProgramError.hxx>
#include <tbb/parallel_for.h> #include <tbb/parallel_for.h>
#include <tbb/parallel_for_each.h> #include <tbb/parallel_for_each.h>
#include <tbb/blocked_range.h> #include <tbb/blocked_range.h>
#include <tbb/task_scheduler_init.h>
//======================================================================= //=======================================================================
//function : forEach //function : forEach
@ -34,15 +36,19 @@ void OSD_Parallel::forEach (UniversalIterator& theBegin,
const FunctorInterface& theFunctor, const FunctorInterface& theFunctor,
Standard_Integer theNbItems) Standard_Integer theNbItems)
{ {
(void )theNbItems;
try 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) catch (tbb::captured_exception& anException)
{ {
throw Standard_ProgramError(anException.what()); throw Standard_ProgramError (anException.what());
} }
} }
#endif /* HAVE_TBB */ #endif /* HAVE_TBB */