1 // Created on: 2014-08-19
2 // Created by: Alexander Zaikin
3 // Copyright (c) 1996-1999 Matra Datavision
4 // Copyright (c) 2013-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 // Version of parallel executor used when TBB is available
20 #include <OSD_Parallel.hxx>
21 #include <OSD_ThreadPool.hxx>
22 #include <Standard_ProgramError.hxx>
24 #include <tbb/parallel_for.h>
25 #include <tbb/parallel_for_each.h>
26 #include <tbb/blocked_range.h>
27 #include <tbb/task_scheduler_init.h>
29 //=======================================================================
30 //function : forEachExternal
32 //=======================================================================
34 void OSD_Parallel::forEachExternal (UniversalIterator& theBegin,
35 UniversalIterator& theEnd,
36 const FunctorInterface& theFunctor,
37 Standard_Integer theNbItems)
41 const Handle(OSD_ThreadPool)& aThreadPool = OSD_ThreadPool::DefaultPool();
42 const Standard_Integer aNbThreads = theNbItems > 0 ?
43 aThreadPool->NbDefaultThreadsToLaunch() : -1;
45 tbb::task_scheduler_init aScheduler (aNbThreads);
46 tbb::parallel_for_each (theBegin, theEnd, theFunctor);
48 catch (tbb::captured_exception& anException)
50 throw Standard_ProgramError (anException.what());