00af0ebb |
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 |
5 | // |
6 | // This file is part of Open CASCADE Technology software library. |
7 | // |
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. |
13 | // |
14 | // Alternatively, this file may be used under the terms of Open CASCADE |
15 | // commercial license or contractual agreement. |
16 | |
17 | // Version of parallel executor used when TBB is available |
18 | #ifdef HAVE_TBB |
19 | |
20 | #include <OSD_Parallel.hxx> |
e9fb0cba |
21 | #include <OSD_ThreadPool.hxx> |
00af0ebb |
22 | #include <Standard_ProgramError.hxx> |
23 | |
1bd04b5a |
24 | Standard_DISABLE_DEPRECATION_WARNINGS |
00af0ebb |
25 | #include <tbb/parallel_for.h> |
26 | #include <tbb/parallel_for_each.h> |
27 | #include <tbb/blocked_range.h> |
e9fb0cba |
28 | #include <tbb/task_scheduler_init.h> |
1bd04b5a |
29 | Standard_ENABLE_DEPRECATION_WARNINGS |
00af0ebb |
30 | |
31 | //======================================================================= |
fc867b96 |
32 | //function : forEachExternal |
00af0ebb |
33 | //purpose : |
34 | //======================================================================= |
35 | |
fc867b96 |
36 | void OSD_Parallel::forEachExternal (UniversalIterator& theBegin, |
37 | UniversalIterator& theEnd, |
38 | const FunctorInterface& theFunctor, |
39 | Standard_Integer theNbItems) |
00af0ebb |
40 | { |
41 | try |
42 | { |
e9fb0cba |
43 | const Handle(OSD_ThreadPool)& aThreadPool = OSD_ThreadPool::DefaultPool(); |
44 | const Standard_Integer aNbThreads = theNbItems > 0 ? |
3068c3bb |
45 | aThreadPool->NbDefaultThreadsToLaunch() : -1; |
e9fb0cba |
46 | |
47 | tbb::task_scheduler_init aScheduler (aNbThreads); |
48 | tbb::parallel_for_each (theBegin, theEnd, theFunctor); |
00af0ebb |
49 | } |
50 | catch (tbb::captured_exception& anException) |
51 | { |
e9fb0cba |
52 | throw Standard_ProgramError (anException.what()); |
00af0ebb |
53 | } |
54 | } |
55 | |
e9fb0cba |
56 | #endif /* HAVE_TBB */ |