0030924: Coding - incorrect header in file OSD_ThreadPool.hxx
[occt.git] / src / OSD / OSD_Parallel_TBB.cxx
CommitLineData
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
24#include <tbb/parallel_for.h>
25#include <tbb/parallel_for_each.h>
26#include <tbb/blocked_range.h>
e9fb0cba 27#include <tbb/task_scheduler_init.h>
00af0ebb 28
29//=======================================================================
fc867b96 30//function : forEachExternal
00af0ebb 31//purpose :
32//=======================================================================
33
fc867b96 34void OSD_Parallel::forEachExternal (UniversalIterator& theBegin,
35 UniversalIterator& theEnd,
36 const FunctorInterface& theFunctor,
37 Standard_Integer theNbItems)
00af0ebb 38{
39 try
40 {
e9fb0cba 41 const Handle(OSD_ThreadPool)& aThreadPool = OSD_ThreadPool::DefaultPool();
42 const Standard_Integer aNbThreads = theNbItems > 0 ?
43 Min (theNbItems, aThreadPool->NbDefaultThreadsToLaunch()) : -1;
44
45 tbb::task_scheduler_init aScheduler (aNbThreads);
46 tbb::parallel_for_each (theBegin, theEnd, theFunctor);
00af0ebb 47 }
48 catch (tbb::captured_exception& anException)
49 {
e9fb0cba 50 throw Standard_ProgramError (anException.what());
00af0ebb 51 }
52}
53
e9fb0cba 54#endif /* HAVE_TBB */