From c7b59798ca0b9fbeb174c342678d609253140e97 Mon Sep 17 00:00:00 2001 From: msv Date: Thu, 5 Feb 2015 15:49:35 +0300 Subject: [PATCH] 0024826: Wrapping of parallelisation algorithms Simple primitives to parallelize loops type "for" and "foreach" were implemented. The primitives encapsulates complete logic for creating and managing parallel context of loops. Moreover the primitives may be a wrapper for some primitives from 3rd-party library - TBB. To use it is necessary to implement TBB like interface which is based on functors. For example: Class Functor { public: void operator() ([proccesing instance]) const { //... } }; In the body of the operator () should be implemented thread-safe logic of computations that can be performed in parallel context. If parallelized loop iterates on the collections with direct access by index (such as Vector, Array), it is more efficient to use the primitive ParallelFor (because it has no critical section). All parts of OCC code which are using tbb were changed on new primitives. 0024826: Wrapping of parallelisation algorithms Small fix. --- src/BOPAlgo/BOPAlgo_BuilderSolid.cxx | 6 +- src/BOPAlgo/BOPAlgo_Builder_2.cxx | 14 +- src/BOPAlgo/BOPAlgo_Builder_3.cxx | 6 +- src/BOPAlgo/BOPAlgo_PaveFiller_2.cxx | 6 +- src/BOPAlgo/BOPAlgo_PaveFiller_3.cxx | 14 +- src/BOPAlgo/BOPAlgo_PaveFiller_4.cxx | 6 +- src/BOPAlgo/BOPAlgo_PaveFiller_5.cxx | 6 +- src/BOPAlgo/BOPAlgo_PaveFiller_6.cxx | 6 +- src/BOPAlgo/BOPAlgo_PaveFiller_7.cxx | 14 +- src/BOPAlgo/BOPAlgo_PaveFiller_9.cxx | 6 +- src/BOPAlgo/BOPAlgo_ShellSplitter.cxx | 6 +- src/BOPAlgo/BOPAlgo_WireSplitter.cxx | 55 ++-- src/BOPCol/BOPCol_Parallel.hxx | 174 ++++++++++ src/BOPCol/BOPCol_TBB.hxx | 248 --------------- src/BOPCol/FILES | 2 +- src/BOPDS/BOPDS_Iterator.cxx | 6 +- src/BOPTest/BOPTest_CheckCommands.cxx | 22 +- src/BOPTest/BOPTest_Chronometer.hxx | 50 --- src/BOPTest/BOPTest_PartitionCommands.cxx | 51 ++- src/BOPTest/FILES | 1 - src/BOPTools/BOPTools_AlgoTools_1.cxx | 26 +- src/BRepMesh/BRepMesh_FastDiscret.cxx | 22 +- src/BRepMesh/BRepMesh_IncrementalMesh.cxx | 25 +- src/BRepMesh/BRepMesh_WireChecker.cxx | 25 +- .../BRepMesh_WireInterferenceChecker.cxx | 36 +-- .../BRepMesh_WireInterferenceChecker.hxx | 23 +- src/MeshTest/MeshTest_PluginCommands.cxx | 1 - src/OSD/EXTERNLIB | 1 + src/OSD/FILES | 2 + src/OSD/OSD_Parallel.cxx | 93 ++++++ src/OSD/OSD_Parallel.hxx | 298 ++++++++++++++++++ src/OpenGl/OpenGl_SceneGeometry.cxx | 39 +-- src/QABugs/QABugs_19.cxx | 125 ++++++-- src/QANCollection/QANCollection_Stl.cxx | 105 ++---- 34 files changed, 837 insertions(+), 683 deletions(-) create mode 100644 src/BOPCol/BOPCol_Parallel.hxx delete mode 100755 src/BOPCol/BOPCol_TBB.hxx delete mode 100644 src/BOPTest/BOPTest_Chronometer.hxx create mode 100644 src/OSD/OSD_Parallel.cxx create mode 100644 src/OSD/OSD_Parallel.hxx diff --git a/src/BOPAlgo/BOPAlgo_BuilderSolid.cxx b/src/BOPAlgo/BOPAlgo_BuilderSolid.cxx index 8986652964..fbeb55f4e2 100644 --- a/src/BOPAlgo/BOPAlgo_BuilderSolid.cxx +++ b/src/BOPAlgo/BOPAlgo_BuilderSolid.cxx @@ -62,7 +62,7 @@ #include #include #include -#include +#include // #include #include @@ -247,13 +247,13 @@ class BOPAlgo_FaceSolid : public BOPAlgo_Algo { typedef BOPCol_NCVector BOPAlgo_VectorOfFaceSolid; // -typedef BOPCol_TBBContextFunctor +typedef BOPCol_ContextFunctor BOPAlgo_FaceSolidFunctor; // -typedef BOPCol_TBBContextCnt +typedef BOPCol_ContextCnt BOPAlgo_FaceSolidCnt; diff --git a/src/BOPAlgo/BOPAlgo_Builder_2.cxx b/src/BOPAlgo/BOPAlgo_Builder_2.cxx index eb24e6b96d..7ba2e5c29b 100644 --- a/src/BOPAlgo/BOPAlgo_Builder_2.cxx +++ b/src/BOPAlgo/BOPAlgo_Builder_2.cxx @@ -36,7 +36,7 @@ #include #include #include -#include +#include // #include // @@ -138,13 +138,13 @@ class BOPAlgo_PairOfShapeBoolean : public BOPAlgo_Algo { typedef BOPCol_NCVector \ BOPAlgo_VectorOfPairOfShapeBoolean; // -typedef BOPCol_TBBContextFunctor +typedef BOPCol_ContextFunctor BOPCol_BuilderSDFaceFunctor; // -typedef BOPCol_TBBContextCnt +typedef BOPCol_ContextCnt BOPAlgo_BuilderSDFaceCnt; @@ -154,11 +154,11 @@ typedef BOPCol_TBBContextCnt // typedef BOPCol_NCVector BOPAlgo_VectorOfBuilderFace; // -typedef BOPCol_TBBFunctor +typedef BOPCol_Functor BOPAlgo_BuilderFaceFunctor; // -typedef BOPCol_TBBCnt +typedef BOPCol_Cnt BOPAlgo_BuilderFaceCnt; // @@ -223,13 +223,13 @@ class BOPAlgo_VFI : public BOPAlgo_Algo { // typedef BOPCol_NCVector BOPAlgo_VectorOfVFI; // -typedef BOPCol_TBBContextFunctor +typedef BOPCol_ContextFunctor BOPAlgo_VFIFunctor; // -typedef BOPCol_TBBContextCnt +typedef BOPCol_ContextCnt BOPAlgo_VFICnt; diff --git a/src/BOPAlgo/BOPAlgo_Builder_3.cxx b/src/BOPAlgo/BOPAlgo_Builder_3.cxx index 65d8d7e6e0..6b2605ed5b 100644 --- a/src/BOPAlgo/BOPAlgo_Builder_3.cxx +++ b/src/BOPAlgo/BOPAlgo_Builder_3.cxx @@ -52,7 +52,7 @@ #include #include #include -#include +#include // #include // @@ -84,11 +84,11 @@ static typedef BOPCol_NCVector BOPAlgo_VectorOfBuilderSolid; // -typedef BOPCol_TBBFunctor +typedef BOPCol_Functor BOPAlgo_BuilderSolidFunctor; // -typedef BOPCol_TBBCnt +typedef BOPCol_Cnt BOPAlgo_BuilderSolidCnt; // diff --git a/src/BOPAlgo/BOPAlgo_PaveFiller_2.cxx b/src/BOPAlgo/BOPAlgo_PaveFiller_2.cxx index c0584d1964..69cfa25e38 100644 --- a/src/BOPAlgo/BOPAlgo_PaveFiller_2.cxx +++ b/src/BOPAlgo/BOPAlgo_PaveFiller_2.cxx @@ -22,7 +22,7 @@ #include #include -#include +#include #include @@ -118,13 +118,13 @@ class BOPAlgo_VertexEdge : public BOPAlgo_Algo { typedef BOPCol_NCVector BOPAlgo_VectorOfVertexEdge; // -typedef BOPCol_TBBContextFunctor +typedef BOPCol_ContextFunctor BOPAlgo_VertexEdgeFunctor; // -typedef BOPCol_TBBContextCnt +typedef BOPCol_ContextCnt BOPAlgo_VertexEdgeCnt; diff --git a/src/BOPAlgo/BOPAlgo_PaveFiller_3.cxx b/src/BOPAlgo/BOPAlgo_PaveFiller_3.cxx index c20af59375..bbafce4fbd 100644 --- a/src/BOPAlgo/BOPAlgo_PaveFiller_3.cxx +++ b/src/BOPAlgo/BOPAlgo_PaveFiller_3.cxx @@ -47,7 +47,7 @@ #include #include #include -#include +#include // #include #include @@ -116,11 +116,11 @@ class BOPAlgo_EdgeEdge : typedef BOPCol_NCVector BOPAlgo_VectorOfEdgeEdge; // -typedef BOPCol_TBBFunctor +typedef BOPCol_Functor BOPAlgo_EdgeEdgeFunctor; // -typedef BOPCol_TBBCnt +typedef BOPCol_Cnt BOPAlgo_EdgeEdgeCnt; // @@ -163,11 +163,11 @@ class BOPAlgo_TNV : public BOPCol_BoxBndTreeSelector{ typedef BOPCol_NCVector BOPAlgo_VectorOfTNV; // -typedef BOPCol_TBBFunctor +typedef BOPCol_Functor BOPAlgo_TNVFunctor; // -typedef BOPCol_TBBCnt +typedef BOPCol_Cnt BOPAlgo_TNVCnt; ///////////////////////////////////////////////////////////////////////// @@ -254,13 +254,13 @@ class BOPAlgo_PVE { typedef BOPCol_NCVector BOPAlgo_VectorOfPVE; // -typedef BOPCol_TBBContextFunctor +typedef BOPCol_ContextFunctor BOPAlgo_PVEFunctor; // -typedef BOPCol_TBBContextCnt +typedef BOPCol_ContextCnt BOPAlgo_PVECnt; diff --git a/src/BOPAlgo/BOPAlgo_PaveFiller_4.cxx b/src/BOPAlgo/BOPAlgo_PaveFiller_4.cxx index 5b92b5eb1c..1bd5fc0319 100644 --- a/src/BOPAlgo/BOPAlgo_PaveFiller_4.cxx +++ b/src/BOPAlgo/BOPAlgo_PaveFiller_4.cxx @@ -27,7 +27,7 @@ // #include #include -#include +#include // #include // @@ -125,13 +125,13 @@ class BOPAlgo_VertexFace : public BOPAlgo_Algo { typedef BOPCol_NCVector BOPAlgo_VectorOfVertexFace; // -typedef BOPCol_TBBContextFunctor +typedef BOPCol_ContextFunctor BOPAlgo_VertexFaceFunctor; // -typedef BOPCol_TBBContextCnt +typedef BOPCol_ContextCnt BOPAlgo_VertexFaceCnt; diff --git a/src/BOPAlgo/BOPAlgo_PaveFiller_5.cxx b/src/BOPAlgo/BOPAlgo_PaveFiller_5.cxx index b3f45d36ef..66aec9f8e8 100644 --- a/src/BOPAlgo/BOPAlgo_PaveFiller_5.cxx +++ b/src/BOPAlgo/BOPAlgo_PaveFiller_5.cxx @@ -38,7 +38,7 @@ // #include #include -#include +#include // #include #include @@ -119,13 +119,13 @@ class BOPAlgo_EdgeFace : //======================================================================= typedef BOPCol_NCVector BOPAlgo_VectorOfEdgeFace; // -typedef BOPCol_TBBContextFunctor +typedef BOPCol_ContextFunctor BOPAlgo_EdgeFaceFunctor; // -typedef BOPCol_TBBContextCnt +typedef BOPCol_ContextCnt BOPAlgo_EdgeFaceCnt; diff --git a/src/BOPAlgo/BOPAlgo_PaveFiller_6.cxx b/src/BOPAlgo/BOPAlgo_PaveFiller_6.cxx index 4e1c129fbd..738f9336e0 100644 --- a/src/BOPAlgo/BOPAlgo_PaveFiller_6.cxx +++ b/src/BOPAlgo/BOPAlgo_PaveFiller_6.cxx @@ -69,7 +69,7 @@ #include #include #include -#include +#include #include #include @@ -168,11 +168,11 @@ class BOPAlgo_FaceFace : typedef BOPCol_NCVector BOPAlgo_VectorOfFaceFace; // -typedef BOPCol_TBBFunctor +typedef BOPCol_Functor BOPAlgo_FaceFaceFunctor; // -typedef BOPCol_TBBCnt +typedef BOPCol_Cnt BOPAlgo_FaceFaceCnt; ///////////////////////////////////////////////////////////////////////// diff --git a/src/BOPAlgo/BOPAlgo_PaveFiller_7.cxx b/src/BOPAlgo/BOPAlgo_PaveFiller_7.cxx index 12b5e861dc..18b163103d 100644 --- a/src/BOPAlgo/BOPAlgo_PaveFiller_7.cxx +++ b/src/BOPAlgo/BOPAlgo_PaveFiller_7.cxx @@ -41,7 +41,7 @@ #include #include -#include +#include #include #include @@ -153,11 +153,11 @@ class BOPAlgo_SplitEdge : public BOPAlgo_Algo { typedef BOPCol_NCVector BOPAlgo_VectorOfSplitEdge; // -typedef BOPCol_TBBFunctor +typedef BOPCol_Functor BOPAlgo_SplitEdgeFunctor; // -typedef BOPCol_TBBCnt +typedef BOPCol_Cnt BOPAlgo_SplitEdgeCnt; // @@ -220,11 +220,11 @@ class BOPAlgo_MPC : public BOPAlgo_Algo { typedef BOPCol_NCVector BOPAlgo_VectorOfMPC; // -typedef BOPCol_TBBFunctor +typedef BOPCol_Functor BOPAlgo_MPCFunctor; // -typedef BOPCol_TBBCnt +typedef BOPCol_Cnt BOPAlgo_MPCCnt; // @@ -260,11 +260,11 @@ class BOPAlgo_BPC { typedef BOPCol_NCVector BOPAlgo_VectorOfBPC; // -typedef BOPCol_TBBFunctor +typedef BOPCol_Functor BOPAlgo_BPCFunctor; // -typedef BOPCol_TBBCnt +typedef BOPCol_Cnt BOPAlgo_BPCCnt; // diff --git a/src/BOPAlgo/BOPAlgo_PaveFiller_9.cxx b/src/BOPAlgo/BOPAlgo_PaveFiller_9.cxx index 2cbdec3eee..e3208e6b9b 100644 --- a/src/BOPAlgo/BOPAlgo_PaveFiller_9.cxx +++ b/src/BOPAlgo/BOPAlgo_PaveFiller_9.cxx @@ -21,7 +21,7 @@ #include #include -#include +#include #include #include @@ -75,13 +75,13 @@ class BOPAlgo_ShrunkRange : public IntTools_ShrunkRange { typedef BOPCol_NCVector BOPAlgo_VectorOfShrunkRange; // -typedef BOPCol_TBBContextFunctor +typedef BOPCol_ContextFunctor BOPAlgo_ShrunkRangeFunctor; // -typedef BOPCol_TBBContextCnt +typedef BOPCol_ContextCnt BOPAlgo_ShrunkRangeCnt; diff --git a/src/BOPAlgo/BOPAlgo_ShellSplitter.cxx b/src/BOPAlgo/BOPAlgo_ShellSplitter.cxx index a27392f55d..5c78dec61e 100644 --- a/src/BOPAlgo/BOPAlgo_ShellSplitter.cxx +++ b/src/BOPAlgo/BOPAlgo_ShellSplitter.cxx @@ -25,7 +25,7 @@ #include #include // -#include +#include #include #include #include @@ -77,11 +77,11 @@ class BOPAlgo_CBK { typedef BOPCol_NCVector BOPAlgo_VectorOfCBK; // -typedef BOPCol_TBBFunctor +typedef BOPCol_Functor BOPAlgo_CBKFunctor; // -typedef BOPCol_TBBCnt +typedef BOPCol_Cnt BOPAlgo_CBKCnt; // diff --git a/src/BOPAlgo/BOPAlgo_WireSplitter.cxx b/src/BOPAlgo/BOPAlgo_WireSplitter.cxx index d5c8b506d6..16f5323a2b 100644 --- a/src/BOPAlgo/BOPAlgo_WireSplitter.cxx +++ b/src/BOPAlgo/BOPAlgo_WireSplitter.cxx @@ -28,7 +28,7 @@ #include #include #include -#include +#include #include #include @@ -262,56 +262,47 @@ typedef BOPCol_NCVector \ //class : WireSplitterFunctor //purpose : //======================================================================= -class BOPAlgo_WireSplitterFunctor { - protected: +class BOPAlgo_WireSplitterFunctor +{ +protected: TopoDS_Face myFace; BOPTools_VectorOfConnexityBlock* myPVCB; - // - public: + +public: // BOPAlgo_WireSplitterFunctor(const TopoDS_Face& aF, - BOPTools_VectorOfConnexityBlock& aVCB) - : myFace(aF), myPVCB(&aVCB) { + BOPTools_VectorOfConnexityBlock& aVCB) + : myFace(aF), myPVCB(&aVCB) + { } // - void operator()( const flexible_range& aBR ) const{ - Standard_Size i, iBeg, iEnd; - // - BOPTools_VectorOfConnexityBlock& aVCB=*myPVCB; - // - iBeg=aBR.begin(); - iEnd=aBR.end(); - for(i=iBeg; i!=iEnd; ++i) { - BOPTools_ConnexityBlock& aCB=aVCB((Standard_Integer)i); - // - BOPAlgo_WireSplitter::SplitBlock(myFace, aCB); - } + void operator()( const Standard_Integer& theIndex ) const + { + BOPTools_VectorOfConnexityBlock& aVCB = *myPVCB; + BOPTools_ConnexityBlock& aCB = aVCB(theIndex); + BOPAlgo_WireSplitter::SplitBlock(myFace, aCB); } }; //======================================================================= //class : BOPAlgo_WireSplitterCnt //purpose : //======================================================================= -class BOPAlgo_WireSplitterCnt { - public: +class BOPAlgo_WireSplitterCnt +{ +public: //------------------------------- // Perform Standard_EXPORT - static void Perform(const Standard_Boolean bRunParallel, - const TopoDS_Face& aF, - BOPTools_VectorOfConnexityBlock& aVCB) { + static void Perform(const Standard_Boolean bRunParallel, + const TopoDS_Face& aF, + BOPTools_VectorOfConnexityBlock& aVCB) + { // BOPAlgo_WireSplitterFunctor aWSF(aF, aVCB); - Standard_Size aNbVCB=aVCB.Extent(); + Standard_Size aNbVCB = aVCB.Extent(); // - if (bRunParallel) { - flexible_for(flexible_range(0,aNbVCB), aWSF); - } - else { - aWSF.operator()(flexible_range(0,aNbVCB)); - } + OSD_Parallel::For(0, aNbVCB, aWSF, !bRunParallel); } - // }; //======================================================================= //function : MakeWires diff --git a/src/BOPCol/BOPCol_Parallel.hxx b/src/BOPCol/BOPCol_Parallel.hxx new file mode 100644 index 0000000000..d8088aebef --- /dev/null +++ b/src/BOPCol/BOPCol_Parallel.hxx @@ -0,0 +1,174 @@ +// Created by: Peter KURNEV +// Copyright (c) 1999-2013 OPEN CASCADE SAS +// +// This file is part of Open CASCADE Technology software library. +// +// This library is free software; you can redistribute it and/or modify it under +// the terms of the GNU Lesser General Public License version 2.1 as published +// by the Free Software Foundation, with special exception defined in the file +// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT +// distribution for complete text of the license and disclaimer of any warranty. +// +// Alternatively, this file may be used under the terms of Open CASCADE +// commercial license or contractual agreement. + +#ifndef _BOPDS_Col_HeaderFile +#define _BOPDS_Col_HeaderFile + +#include +#include +#include +#include + +// +// 1. Implementation of Functors/Starters +// +// 1.1. Pure version +// + +//======================================================================= +//class : BOPCol_Functor +//purpose : +//======================================================================= +template +class BOPCol_Functor +{ +public: + //! Constructor. + explicit BOPCol_Functor(TypeSolverVector& theSolverVec) + : mySolvers(theSolverVec) {} + + //! Defines functor interface. + void operator() (const Standard_Integer theIndex) const + { + TypeSolver& aSolver = mySolvers(theIndex); + aSolver.Perform(); + } + +private: + BOPCol_Functor(const BOPCol_Functor&); + BOPCol_Functor& operator= (const BOPCol_Functor&); + +private: + TypeSolverVector& mySolvers; +}; + +//======================================================================= +//class : BOPCol_Cnt +//purpose : +//======================================================================= +template +class BOPCol_Cnt +{ +public: + static void Perform( const Standard_Boolean isRunParallel, + TypeSolverVector& theSolverVector ) + { + TypeFunctor aFunctor(theSolverVector); + OSD_Parallel::For(0, theSolverVector.Extent(), aFunctor, !isRunParallel); + } +}; + +// +// 1.2. Context dependent version +// + +//======================================================================= +//class : BOPCol_ContextFunctor +//purpose : +//======================================================================= +template +class BOPCol_ContextFunctor +{ + //! Auxiliary thread ID hasher. + struct Hasher + { + static Standard_Integer HashCode(const Standard_ThreadId theKey, + const Standard_Integer Upper) + { + return ::HashCode(reinterpret_cast(theKey), Upper); + } + + static Standard_Boolean IsEqual(const Standard_ThreadId theKey1, + const Standard_ThreadId theKey2) + { + return theKey1 == theKey2; + } + }; + + typedef NCollection_DataMap ContextMap; + +public: + + //! Constructor + explicit BOPCol_ContextFunctor( TypeSolverVector& theVector ) + : mySolverVector(theVector) {} + + //! Binds main thread context + void SetContext( TypeContext& theContext ) + { + myContexts.Bind(OSD_Thread::Current(), theContext); + } + + //! Returns current thread context + TypeContext& GetThreadContext() const + { + const Standard_ThreadId aThreadID = OSD_Thread::Current(); + if ( myContexts.IsBound(aThreadID) ) + { + TypeContext& aContext = myContexts(aThreadID); + if ( aContext.IsNull() == Standard_False ) + return aContext; + } + + // Create new context + TypeContext aContext = new TN + ( NCollection_BaseAllocator::CommonBaseAllocator() ); + + Standard_Mutex::Sentry aLocker(myMutex); + myContexts.Bind(aThreadID, aContext); + + return myContexts(aThreadID); + } + + //! Defines functor interface + void operator()( const Standard_Integer theIndex ) const + { + TypeContext& aContext = GetThreadContext(); + TypeSolver& aSolver = mySolverVector(theIndex); + + aSolver.SetContext(aContext); + aSolver.Perform(); + } + +private: + BOPCol_ContextFunctor(const BOPCol_ContextFunctor&); + BOPCol_ContextFunctor& operator= (const BOPCol_ContextFunctor&); + +private: + TypeSolverVector& mySolverVector; + mutable ContextMap myContexts; + mutable Standard_Mutex myMutex; +}; + +//======================================================================= +//class : BOPCol_ContextCnt +//purpose : +//======================================================================= +template +class BOPCol_ContextCnt +{ +public: + static void Perform( const Standard_Boolean isRunParallel, + TypeSolverVector& theSolverVector, + TypeContext& theContext ) + { + TypeFunctor aFunctor(theSolverVector); + aFunctor.SetContext(theContext); + + OSD_Parallel::For(0, theSolverVector.Extent(), aFunctor, !isRunParallel); + } +}; + +#endif diff --git a/src/BOPCol/BOPCol_TBB.hxx b/src/BOPCol/BOPCol_TBB.hxx deleted file mode 100755 index 8f79013460..0000000000 --- a/src/BOPCol/BOPCol_TBB.hxx +++ /dev/null @@ -1,248 +0,0 @@ -// Created by: Peter KURNEV -// Copyright (c) 1999-2013 OPEN CASCADE SAS -// -// This file is part of Open CASCADE Technology software library. -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License version 2.1 as published -// by the Free Software Foundation, with special exception defined in the file -// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT -// distribution for complete text of the license and disclaimer of any warranty. -// -// Alternatively, this file may be used under the terms of Open CASCADE -// commercial license or contractual agreement. - -#ifndef _BOPDS_Col_HeaderFile -#define _BOPDS_Col_HeaderFile - -#include -#include - -#ifdef HAVE_TBB -// On Windows, function TryEnterCriticalSection has appeared in Windows NT -// and is surrounded by #ifdef in MS VC++ 7.1 headers. -// Thus to use it we need to define appropriate macro saying that we wil -// run on Windows NT 4.0 at least -#if ((defined(_WIN32) || defined(__WIN32__)) && !defined(_WIN32_WINNT)) - #define _WIN32_WINNT 0x0501 -#endif - -#include -using namespace tbb; - -#define flexible_range blocked_range -#define flexible_for parallel_for - -#else // not HAVE_TBB - -#define flexible_range serial_range -#define flexible_for serial_for - -//======================================================================= -//class : serial_range -//purpose : -//======================================================================= -template class serial_range { - public: - serial_range(const Type& aBegin, - const Type& aEnd) - : myBegin(aBegin), myEnd(aEnd) { - } - // - ~serial_range() { - } - // - const Type& begin() const{ - return myBegin; - } - // - const Type& end() const{ - return myEnd; - }; - // - protected: - Type myBegin; - Type myEnd; -}; - -//======================================================================= -//function : serial_for -//purpose : -//======================================================================= -template -static void serial_for( const Range& range, const Body& body ) { - body.operator()(range); -}; -#endif // not HAVE_TBB -// -// 2. Implementation of Functors/Starters -// -// 2.1. Pure version -// -//======================================================================= -//class : BOPCol_TBBFunctor -//purpose : -//======================================================================= -template class BOPCol_TBBFunctor { - - public: - BOPCol_TBBFunctor(TypeSolverVector& aV) - : myPV(&aV) { - } - // - ~BOPCol_TBBFunctor() { - } - // - void operator()( const flexible_range& aBR ) const{ - Standard_Integer i, iBeg, iEnd; - // - TypeSolverVector& aV=*myPV; - // - iBeg=aBR.begin(); - iEnd=aBR.end(); - for(i=iBeg; i!=iEnd; ++i) { - TypeSolver& aSolver=aV(i); - // - aSolver.Perform(); - } - } - // - protected: - TypeSolverVector* myPV; -}; -//======================================================================= -//class : BOPCol_TBBCnt -//purpose : -//======================================================================= -template class BOPCol_TBBCnt { - public: - //------------------------------- - // Perform - Standard_EXPORT - static void Perform(const Standard_Boolean bRunParallel, - TypeSolverVector& aV) { - // - TypeFunctor aFunctor(aV); - Standard_Integer aNb=aV.Extent(); - // - if (bRunParallel) { -#ifdef HAVE_TBB - try { - flexible_for(flexible_range(0,aNb), aFunctor); - } - // - catch( captured_exception& ) { - Standard_NotImplemented::Raise(""); - } - catch( ... ) { - Standard_NotImplemented::Raise(""); - } -#else // not HAVE_TBB - flexible_for(flexible_range(0,aNb), aFunctor); -#endif - } - else { - aFunctor.operator()(flexible_range(0,aNb)); - } - } -}; -// -// 2.2. Context dependent version -// - -//======================================================================= -//class : BOPCol_TBBContextFunctor -//purpose : -//======================================================================= -template class BOPCol_TBBContextFunctor { - - public: - BOPCol_TBBContextFunctor(TypeSolverVector& aV) - : myPV(&aV) { - } - // - ~BOPCol_TBBContextFunctor() { - } - // - void SetContext(TypeContext& aCtx) { - myContext=aCtx; - } - // - void operator()( const flexible_range& aBR ) const{ - Standard_Integer i, iBeg, iEnd; - TypeContext aCtx; - // - if (myContext.IsNull()) { - aCtx=new TN - (NCollection_BaseAllocator::CommonBaseAllocator()); - } - else { - aCtx=myContext; - } - // - TypeSolverVector& aV=*myPV; - // - iBeg=aBR.begin(); - iEnd=aBR.end(); - for(i=iBeg; i!=iEnd; ++i) { - TypeSolver& aSolver=aV(i); - // - aSolver.SetContext(aCtx); - aSolver.Perform(); - } - } - // - protected: - TypeSolverVector* myPV; - TypeContext myContext; - // -}; - -//======================================================================= -//class : BOPCol_TBBContextCnt -//purpose : -//======================================================================= -template class BOPCol_TBBContextCnt { - public: - //------------------------------- - // Perform - Standard_EXPORT - static void Perform(const Standard_Boolean bRunParallel, - TypeSolverVector& aV, - TypeContext& aCtx) { - // - TypeFunctor aFunctor(aV); - Standard_Integer aNb=aV.Extent(); - // - if (bRunParallel) { -#ifdef HAVE_TBB - try { - flexible_for(flexible_range(0,aNb), aFunctor); - } - // - catch(captured_exception& ) { - //cout<<" captured_exception: " << ex.what() << endl; - Standard_NotImplemented::Raise(""); - } - catch( ... ) { - Standard_NotImplemented::Raise(""); - } -#else // not HAVE_TBB - flexible_for(flexible_range(0,aNb), aFunctor); -#endif - } - else { - aFunctor.SetContext(aCtx); - aFunctor.operator()(flexible_range(0,aNb)); - } - } -}; - -#endif diff --git a/src/BOPCol/FILES b/src/BOPCol/FILES index 412ba9952d..8be3e7ddbd 100644 --- a/src/BOPCol/FILES +++ b/src/BOPCol/FILES @@ -28,7 +28,7 @@ BOPCol_SequenceOfReal.hxx BOPCol_DataMapOfIntegerShape.hxx BOPCol_IndexedDataMapOfIntegerListOfInteger.hxx BOPCol_IndexedDataMapOfShapeInteger.hxx -BOPCol_TBB.hxx +BOPCol_Parallel.hxx BOPCol_NCVector.hxx BOPCol_BoxBndTree.hxx diff --git a/src/BOPDS/BOPDS_Iterator.cxx b/src/BOPDS/BOPDS_Iterator.cxx index 29237d34e8..9029348157 100644 --- a/src/BOPDS/BOPDS_Iterator.cxx +++ b/src/BOPDS/BOPDS_Iterator.cxx @@ -25,7 +25,7 @@ #include // #include -#include +#include #include // #include @@ -70,8 +70,8 @@ class BOPDS_TSR : public BOPCol_BoxBndTreeSelector{ // //======================================================================= typedef BOPCol_NCVector BOPDS_VectorOfTSR; -typedef BOPCol_TBBFunctor BOPDS_TSRFunctor; -typedef BOPCol_TBBCnt BOPDS_TSRCnt; +typedef BOPCol_Functor BOPDS_TSRFunctor; +typedef BOPCol_Cnt BOPDS_TSRCnt; ///////////////////////////////////////////////////////////////////////// diff --git a/src/BOPTest/BOPTest_CheckCommands.cxx b/src/BOPTest/BOPTest_CheckCommands.cxx index 7da70dc77f..2c38c9d485 100644 --- a/src/BOPTest/BOPTest_CheckCommands.cxx +++ b/src/BOPTest/BOPTest_CheckCommands.cxx @@ -41,10 +41,9 @@ #include #include #include - #include -#include +#include #include // @@ -204,7 +203,7 @@ Standard_Integer bopcheck (Draw_Interpretor& di, if (!strcmp(a[i], "-t")) { bShowTime=Standard_True; } - } + } // //aLevel = (n==3) ? Draw::Atoi(a[2]) : aNbInterfTypes-1; //------------------------------------------------------------------- @@ -218,7 +217,6 @@ Standard_Integer bopcheck (Draw_Interpretor& di, BOPAlgo_CheckerSI aChecker; BOPCol_ListOfShape aLS; BOPDS_MapIteratorMapOfPassKey aItMPK; - BOPTest_Chronometer aChrono; // if (aLevel < (aNbInterfTypes-1)) { di << "Info:\nThe level of check is set to " @@ -239,11 +237,13 @@ Standard_Integer bopcheck (Draw_Interpretor& di, aChecker.SetRunParallel(bRunParallel); aChecker.SetFuzzyValue(aTol); // - aChrono.Start(); + OSD_Timer aTimer; + aTimer.Start(); // aChecker.Perform(); // - aChrono.Stop(); + aTimer.Stop(); + aTimer.Show(); // iErr=aChecker.ErrorStatus(); // @@ -316,11 +316,9 @@ Standard_Integer bopcheck (Draw_Interpretor& di, if (!iCnt) { di << " This shape seems to be OK." << "\n"; } - if (bShowTime) { - Standard_Real aTime; - // - aTime=aChrono.Time(); - Sprintf(buf, " Tps: %7.2lf\n", aTime); + if (bShowTime) + { + Sprintf(buf, " Tps: %7.2lf\n", aTimer.ElapsedTime()); di << buf; } return 0; @@ -924,7 +922,7 @@ Standard_Integer xdistef(Draw_Interpretor& di, Standard_Integer n, const char** a) { - if(n < 3) { + if(n < 3) { di << "use xdistef edge face\n"; return 1; } diff --git a/src/BOPTest/BOPTest_Chronometer.hxx b/src/BOPTest/BOPTest_Chronometer.hxx deleted file mode 100644 index ba88bf0351..0000000000 --- a/src/BOPTest/BOPTest_Chronometer.hxx +++ /dev/null @@ -1,50 +0,0 @@ -// Created by: Peter KURNEV -// Copyright (c) 2010-2014 OPEN CASCADE SAS -// -// This file is part of Open CASCADE Technology software library. -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License version 2.1 as published -// by the Free Software Foundation, with special exception defined in the file -// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT -// distribution for complete text of the license and disclaimer of any warranty. -// -// Alternatively, this file may be used under the terms of Open CASCADE -// commercial license or contractual agreement. - -#ifndef BOPTest_Chronometer_HeaderFile -#define BOPTest_Chronometer_HeaderFile -// -#include -//======================================================================= -//class : BOPTest_Chronometer -//purpose : -//======================================================================= -class BOPTest_Chronometer { - public: - BOPTest_Chronometer() { - } - // - ~BOPTest_Chronometer() { - } - // - void Start() { - myChronometer.Reset(); - myChronometer.Start(); - } - // - void Stop() { - myChronometer.Stop(); - myTime=myChronometer.ElapsedTime(); - } - // - double Time() const{ - return myTime; - }; - // - protected: - OSD_Timer myChronometer; - double myTime; -}; - -#endif diff --git a/src/BOPTest/BOPTest_PartitionCommands.cxx b/src/BOPTest/BOPTest_PartitionCommands.cxx index d8d69ce0c4..29c253c14f 100644 --- a/src/BOPTest/BOPTest_PartitionCommands.cxx +++ b/src/BOPTest/BOPTest_PartitionCommands.cxx @@ -35,7 +35,7 @@ #include #include -#include +#include static Standard_Integer bfillds (Draw_Interpretor&, Standard_Integer, const char**); static Standard_Integer bbuild (Draw_Interpretor&, Standard_Integer, const char**); @@ -76,8 +76,6 @@ Standard_Integer bfillds(Draw_Interpretor& di, Standard_Real aTol; BOPCol_ListIteratorOfListOfShape aIt; BOPCol_ListOfShape aLC; - BOPTest_Chronometer aChrono; - BOPCol_ListOfShape& aLS=BOPTest_Objects::Shapes(); aNbS=aLS.Extent(); if (!aNbS) { @@ -94,7 +92,7 @@ Standard_Integer bfillds(Draw_Interpretor& di, if (!strcmp(a[i], "-t")) { bShowTime=Standard_True; } - } + } // BOPCol_ListOfShape& aLT=BOPTest_Objects::Tools(); // @@ -107,7 +105,7 @@ Standard_Integer bfillds(Draw_Interpretor& di, aIt.Initialize(aLT); for (; aIt.More(); aIt.Next()) { const TopoDS_Shape& aS=aIt.Value(); - aLC.Append(aS); + aLC.Append(aS); } // BOPAlgo_PaveFiller& aPF=BOPTest_Objects::PaveFiller(); @@ -116,7 +114,8 @@ Standard_Integer bfillds(Draw_Interpretor& di, aPF.SetRunParallel(bRunParallel); aPF.SetFuzzyValue(aTol); // - aChrono.Start(); + OSD_Timer aTimer; + aTimer.Start(); // aPF.Perform(); iErr=aPF.ErrorStatus(); @@ -126,13 +125,12 @@ Standard_Integer bfillds(Draw_Interpretor& di, return 0; } // - aChrono.Stop(); + aTimer.Stop(); + aTimer.Show(); // - if (bShowTime) { - Standard_Real aTime; - // - aTime=aChrono.Time(); - Sprintf(buf, " Tps: %7.2lf\n", aTime); + if (bShowTime) + { + Sprintf(buf, " Tps: %7.2lf\n", aTimer.ElapsedTime()); di << buf; } // @@ -160,8 +158,7 @@ Standard_Integer bbuild(Draw_Interpretor& di, char buf[128]; Standard_Boolean bRunParallel, bShowTime; Standard_Integer i, iErr; - - BOPTest_Chronometer aChrono; + BOPCol_ListIteratorOfListOfShape aIt; // BOPAlgo_PaveFiller& aPF=BOPTest_Objects::PaveFiller(); @@ -193,7 +190,8 @@ Standard_Integer bbuild(Draw_Interpretor& di, aBuilder.SetRunParallel(bRunParallel); // // - aChrono.Start(); + OSD_Timer aTimer; + aTimer.Start(); // aBuilder.PerformWithFiller(aPF); iErr=aBuilder.ErrorStatus(); @@ -203,13 +201,12 @@ Standard_Integer bbuild(Draw_Interpretor& di, return 0; } // - aChrono.Stop(); + aTimer.Stop(); + aTimer.Show(); // - if (bShowTime) { - Standard_Real aTime; - // - aTime=aChrono.Time(); - Sprintf(buf, " Tps: %7.2lf\n", aTime); + if (bShowTime) + { + Sprintf(buf, " Tps: %7.2lf\n", aTimer.ElapsedTime()); di << buf; } // @@ -246,7 +243,6 @@ Standard_Integer bbop(Draw_Interpretor& di, Standard_Integer iErr, iOp, i; BOPAlgo_Operation aOp; BOPCol_ListIteratorOfListOfShape aIt; - BOPTest_Chronometer aChrono; // iOp=Draw::Atoi(a[2]); if (iOp<0 || iOp>4) { @@ -306,7 +302,8 @@ Standard_Integer bbop(Draw_Interpretor& di, // pBuilder->SetRunParallel(bRunParallel); // - aChrono.Start(); + OSD_Timer aTimer; + aTimer.Start(); // pBuilder->PerformWithFiller(aPF); iErr=pBuilder->ErrorStatus(); @@ -316,13 +313,11 @@ Standard_Integer bbop(Draw_Interpretor& di, return 0; } // - aChrono.Stop(); + aTimer.Stop(); + aTimer.Show(); // if (bShowTime) { - Standard_Real aTime; - // - aTime=aChrono.Time(); - Sprintf(buf, " Tps: %7.2lf\n", aTime); + Sprintf(buf, " Tps: %7.2lf\n", aTimer.ElapsedTime()); di << buf; } // diff --git a/src/BOPTest/FILES b/src/BOPTest/FILES index c478aee3a1..fad6632898 100755 --- a/src/BOPTest/FILES +++ b/src/BOPTest/FILES @@ -6,4 +6,3 @@ BOPTest_TolerCommands.cxx BOPTest_ObjCommands.cxx BOPTest_APICommands.cxx BOPTest_OptionCommands.cxx -BOPTest_Chronometer.hxx \ No newline at end of file diff --git a/src/BOPTools/BOPTools_AlgoTools_1.cxx b/src/BOPTools/BOPTools_AlgoTools_1.cxx index cacb2276ac..6fa2144fef 100644 --- a/src/BOPTools/BOPTools_AlgoTools_1.cxx +++ b/src/BOPTools/BOPTools_AlgoTools_1.cxx @@ -80,7 +80,7 @@ #include // #include -#include +#include #include static @@ -158,11 +158,11 @@ class BOPTools_CPC { //======================================================================= typedef BOPCol_NCVector BOPTools_VectorOfCPC; // -typedef BOPCol_TBBFunctor +typedef BOPCol_Functor BOPTools_CPCFunctor; // -typedef BOPCol_TBBCnt +typedef BOPCol_Cnt BOPTools_CPCCnt; // @@ -192,11 +192,11 @@ class BOPTools_CWT { //======================================================================= typedef BOPCol_NCVector BOPTools_VectorOfCWT; // -typedef BOPCol_TBBFunctor +typedef BOPCol_Functor BOPTools_CWTFunctor; // -typedef BOPCol_TBBCnt +typedef BOPCol_Cnt BOPTools_CWTCnt; // @@ -237,11 +237,11 @@ class BOPTools_CDT { //======================================================================= typedef BOPCol_NCVector BOPTools_VectorOfCDT; // -typedef BOPCol_TBBFunctor +typedef BOPCol_Functor BOPTools_CDTFunctor; // -typedef BOPCol_TBBCnt +typedef BOPCol_Cnt BOPTools_CDTCnt; // @@ -272,11 +272,11 @@ class BOPTools_CVT { //======================================================================= typedef BOPCol_NCVector BOPTools_VectorOfCVT; // -typedef BOPCol_TBBFunctor +typedef BOPCol_Functor BOPTools_CVTFunctor; // -typedef BOPCol_TBBCnt +typedef BOPCol_Cnt BOPTools_CVTCnt; // @@ -306,17 +306,17 @@ class BOPTools_CET { //======================================================================= typedef BOPCol_NCVector BOPTools_VectorOfCET; // -typedef BOPCol_TBBFunctor +typedef BOPCol_Functor BOPTools_CETFunctor; // -typedef BOPCol_TBBCnt +typedef BOPCol_Cnt BOPTools_CETCnt; // // //======================================================================= -// + // //======================================================================= // Function : CorrectTolerances // purpose : @@ -1063,6 +1063,6 @@ Standard_Boolean BOPTools_AlgoTools::ComputeTolerance // theMaxDist = aCS.MaxDistance(); theMaxPar = aCS.MaxParameter(); - // + // return Standard_True; } diff --git a/src/BRepMesh/BRepMesh_FastDiscret.cxx b/src/BRepMesh/BRepMesh_FastDiscret.cxx index 933a8b74c7..126e671f87 100644 --- a/src/BRepMesh/BRepMesh_FastDiscret.cxx +++ b/src/BRepMesh/BRepMesh_FastDiscret.cxx @@ -62,6 +62,8 @@ #include #include +#include + #include #include #include @@ -71,11 +73,6 @@ #include -#ifdef HAVE_TBB - // paralleling using Intel TBB - #include -#endif - #define UVDEFLECTION 1.e-05 IMPLEMENT_STANDARD_HANDLE (BRepMesh_FastDiscret, Standard_Transient) @@ -176,20 +173,7 @@ void BRepMesh_FastDiscret::Perform(const TopoDS_Shape& theShape) aFaces.push_back(aFace); } -#ifdef HAVE_TBB - if ( myInParallel ) - { - tbb::parallel_for_each(aFaces.begin(), aFaces.end(), *this); - } - else - { -#endif - std::vector::const_iterator anIt(aFaces.begin()); - for (; anIt != aFaces.end(); anIt++) - Process(*anIt); -#ifdef HAVE_TBB - } -#endif + OSD_Parallel::ForEach(aFaces.begin(), aFaces.end(), *this, !myInParallel); } diff --git a/src/BRepMesh/BRepMesh_IncrementalMesh.cxx b/src/BRepMesh/BRepMesh_IncrementalMesh.cxx index c7fefa84f6..8593287562 100644 --- a/src/BRepMesh/BRepMesh_IncrementalMesh.cxx +++ b/src/BRepMesh/BRepMesh_IncrementalMesh.cxx @@ -16,6 +16,7 @@ #include +#include #include #include @@ -52,11 +53,6 @@ #include -#ifdef HAVE_TBB - // paralleling using Intel TBB - #include -#endif - namespace { //! Default flag to control parallelization for BRepMesh_IncrementalMesh @@ -223,19 +219,7 @@ void BRepMesh_IncrementalMesh::update() update(aFaceIt.Value()); // Mesh faces -#ifdef HAVE_TBB - if (myInParallel) - { - tbb::parallel_for_each(myFaces.begin(), myFaces.end(), *myMesh); - } - else - { -#endif - for (aFaceIt.Init(myFaces); aFaceIt.More(); aFaceIt.Next()) - myMesh->Process(aFaceIt.Value()); -#ifdef HAVE_TBB - } -#endif + OSD_Parallel::ForEach(myFaces.begin(), myFaces.end(), *myMesh, !myInParallel); commit(); clear(); @@ -577,12 +561,7 @@ Standard_Integer BRepMesh_IncrementalMesh::Discret( //======================================================================= Standard_Boolean BRepMesh_IncrementalMesh::IsParallelDefault() { -#ifdef HAVE_TBB return IS_IN_PARALLEL; -#else - // no alternative parallelization yet - flag has no meaning - return Standard_False; -#endif } //======================================================================= diff --git a/src/BRepMesh/BRepMesh_WireChecker.cxx b/src/BRepMesh/BRepMesh_WireChecker.cxx index bed115d467..007ecf35f5 100644 --- a/src/BRepMesh/BRepMesh_WireChecker.cxx +++ b/src/BRepMesh/BRepMesh_WireChecker.cxx @@ -30,12 +30,8 @@ #include #include #include +#include -#ifdef HAVE_TBB - // paralleling using Intel TBB - #include - #include -#endif //======================================================================= //function : Selector::Constructor @@ -196,27 +192,18 @@ void BRepMesh_WireChecker::ReCompute(BRepMesh::HClassifier& theClassifier) BRepMesh::Array1OfSegmentsTree aWiresBiPoints(1, aNbWires); fillSegmentsTree(aDWires, aWiresBiPoints); -#ifdef HAVE_TBB - Standard_Mutex aWireMutex; - BRepMesh_WireInterferenceChecker aIntChecker(aWiresBiPoints, - &myStatus, &aWireMutex); - if (myIsInParallel && aNbWires > 1) { - // check wires in parallel threads using TBB - tbb::parallel_for(tbb::blocked_range(1, aNbWires + 1), - aIntChecker); + // Check wires in parallel threads. + Standard_Mutex aWireMutex; + BRepMesh_WireInterferenceChecker aIntChecker(aWiresBiPoints, &myStatus, &aWireMutex); + OSD_Parallel::For(1, aNbWires + 1, aIntChecker); } else { -#else BRepMesh_WireInterferenceChecker aIntChecker(aWiresBiPoints, &myStatus); -#endif - for (Standard_Integer i = 1; i <= aNbWires; ++i) - aIntChecker(i); -#ifdef HAVE_TBB + OSD_Parallel::For(1, aNbWires + 1, aIntChecker, Standard_True); } -#endif if (myStatus == BRepMesh_SelfIntersectingWire) return; diff --git a/src/BRepMesh/BRepMesh_WireInterferenceChecker.cxx b/src/BRepMesh/BRepMesh_WireInterferenceChecker.cxx index a8273b3f08..326dc8c3ac 100644 --- a/src/BRepMesh/BRepMesh_WireInterferenceChecker.cxx +++ b/src/BRepMesh/BRepMesh_WireInterferenceChecker.cxx @@ -20,7 +20,6 @@ // TODO: remove this variable after implementation of LoopChecker2d. static const Standard_Real MIN_LOOP_S = 2 * M_PI * 2.E-5; -#ifdef HAVE_TBB //======================================================================= //function : Constructor //purpose : @@ -35,30 +34,6 @@ BRepMesh_WireInterferenceChecker::BRepMesh_WireInterferenceChecker( { } -//======================================================================= -//function : Checker's body -//purpose : -//======================================================================= -void BRepMesh_WireInterferenceChecker::operator ()( - const tbb::blocked_range& theWireRange) const -{ - for (Standard_Integer i = theWireRange.begin(); i != theWireRange.end(); ++i) - this->operator ()(i); -} -#else -//======================================================================= -//function : Constructor -//purpose : -//======================================================================= -BRepMesh_WireInterferenceChecker::BRepMesh_WireInterferenceChecker( - const BRepMesh::Array1OfSegmentsTree& theWires, - BRepMesh_Status* theStatus) -: myWires (theWires), - myStatus(theStatus) -{ -} -#endif - //======================================================================= //function : Checker's body //purpose : @@ -75,11 +50,9 @@ void BRepMesh_WireInterferenceChecker::operator ()( for (Standard_Integer aWireIt = theWireId; aWireIt <= myWires.Upper(); ++aWireIt) { -#ifdef HAVE_TBB - // Break execution in case if flag was raised by another thread + // Break execution in case if flag was raised by another thread. if (*myStatus == BRepMesh_SelfIntersectingWire) return; -#endif const Standard_Boolean isSelfIntCheck = (aWireIt == theWireId); const BRepMesh::SegmentsTree& aWireSegTree2 = @@ -93,11 +66,9 @@ void BRepMesh_WireInterferenceChecker::operator ()( Standard_Integer aSegmentId1 = aWireSegments1->Lower(); for (; aSegmentId1 <= aWireSegments1->Upper(); ++aSegmentId1) { -#ifdef HAVE_TBB // Break execution in case if flag was raised by another thread if (*myStatus == BRepMesh_SelfIntersectingWire) return; -#endif aSelector.Clear(); aSelector.SetBox(aWireBoxTree1->FindNode(aSegmentId1).Bnd()); @@ -112,11 +83,9 @@ void BRepMesh_WireInterferenceChecker::operator ()( const Standard_Integer aSelectedNb = aSelector.IndicesNb(); for (Standard_Integer aBndIt = 0; aBndIt < aSelectedNb; ++aBndIt) { -#ifdef HAVE_TBB // Break execution in case if flag was raised by another thread if (*myStatus == BRepMesh_SelfIntersectingWire) return; -#endif const Standard_Integer aSegmentId2 = aSelected(aBndIt); const BRepMesh::Segment& aSegment2 = aWireSegments2->Value(aSegmentId2); @@ -154,10 +123,9 @@ void BRepMesh_WireInterferenceChecker::operator ()( continue; } -#ifdef HAVE_TBB Standard_Mutex::Sentry aSentry(myMutex); -#endif *myStatus = BRepMesh_SelfIntersectingWire; + return; } } diff --git a/src/BRepMesh/BRepMesh_WireInterferenceChecker.hxx b/src/BRepMesh/BRepMesh_WireInterferenceChecker.hxx index 1bfac79f15..03e7055ed4 100644 --- a/src/BRepMesh/BRepMesh_WireInterferenceChecker.hxx +++ b/src/BRepMesh/BRepMesh_WireInterferenceChecker.hxx @@ -21,11 +21,6 @@ #include #include -#ifdef HAVE_TBB - // paralleling using Intel TBB - #include -#endif - //! Auxilary class implementing functionality for //! checking interference between two discretized wires. class BRepMesh_WireInterferenceChecker @@ -43,7 +38,6 @@ public: Same }; -#ifdef HAVE_TBB //! Constructor //! @param theWires wires that should be checked. //! @param theStatus shared flag to set status of the check. @@ -51,19 +45,7 @@ public: BRepMesh_WireInterferenceChecker( const BRepMesh::Array1OfSegmentsTree& theWires, BRepMesh_Status* theStatus, - Standard_Mutex* theMutex); - - //! Checker's body. - //! @param theWireRange range of wires to be checked. - void operator ()(const tbb::blocked_range& theWireRange) const; -#else - //! Constructor - //! @param theWires wires that should be checked. - //! @param theStatus shared flag to set status of the check. - BRepMesh_WireInterferenceChecker( - const BRepMesh::Array1OfSegmentsTree& theWires, - BRepMesh_Status* theStatus); -#endif + Standard_Mutex* theMutex = NULL); //! Checker's body. //! @param theWireId Id of discretized wire to be checked. @@ -79,10 +61,7 @@ private: private: const BRepMesh::Array1OfSegmentsTree& myWires; BRepMesh_Status* myStatus; - -#ifdef HAVE_TBB Standard_Mutex* myMutex; -#endif }; #endif diff --git a/src/MeshTest/MeshTest_PluginCommands.cxx b/src/MeshTest/MeshTest_PluginCommands.cxx index 99b0e0817a..bff781887d 100644 --- a/src/MeshTest/MeshTest_PluginCommands.cxx +++ b/src/MeshTest/MeshTest_PluginCommands.cxx @@ -83,7 +83,6 @@ void MeshTest::PluginCommands(Draw_Interpretor& theCommands) __FILE__, mpparallel, g); theCommands.Add("triarea","shape [eps] (computes triangles and surface area)",__FILE__, triarea, g); theCommands.Add("tricheck", "shape (checks triangulation of shape)", __FILE__, tricheck, g); - } //======================================================================= diff --git a/src/OSD/EXTERNLIB b/src/OSD/EXTERNLIB index e69de29bb2..ca15c4ddef 100755 --- a/src/OSD/EXTERNLIB +++ b/src/OSD/EXTERNLIB @@ -0,0 +1 @@ +CSF_TBB \ No newline at end of file diff --git a/src/OSD/FILES b/src/OSD/FILES index eadc93711e..fca32d9ebc 100755 --- a/src/OSD/FILES +++ b/src/OSD/FILES @@ -17,5 +17,7 @@ OSD_MAllocHook.cxx OSD_MAllocHook.hxx OSD_MemInfo.hxx OSD_MemInfo.cxx +OSD_Parallel.hxx +OSD_Parallel.cxx OSD_OpenFile.hxx OSD_OpenFile.cxx diff --git a/src/OSD/OSD_Parallel.cxx b/src/OSD/OSD_Parallel.cxx new file mode 100644 index 0000000000..8b80fbade7 --- /dev/null +++ b/src/OSD/OSD_Parallel.cxx @@ -0,0 +1,93 @@ +// Created on: 2014-08-19 +// Created by: Alexander Zaikin +// Copyright (c) 1996-1999 Matra Datavision +// Copyright (c) 2013-2014 OPEN CASCADE SAS +// +// This file is part of Open CASCADE Technology software library. +// +// This library is free software; you can redistribute it and/or modify it under +// the terms of the GNU Lesser General Public License version 2.1 as published +// by the Free Software Foundation, with special exception defined in the file +// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT +// distribution for complete text of the license and disclaimer of any warranty. +// +// Alternatively, this file may be used under the terms of Open CASCADE +// commercial license or contractual agreement. + +#include + +#ifdef _WIN32 + #include + #include +#else + #include + + #ifdef __sun + #include + #include + #else + #include + #endif +#endif + +#ifdef _WIN32 +namespace { + // for a 64-bit app running under 64-bit Windows, this is FALSE + static bool isWow64() + { + typedef BOOL (WINAPI *LPFN_ISWOW64PROCESS) (HANDLE , PBOOL); + BOOL bIsWow64 = FALSE; + HMODULE aKern32Module = GetModuleHandleW(L"kernel32"); + LPFN_ISWOW64PROCESS aFunIsWow64 = (aKern32Module == NULL) ? (LPFN_ISWOW64PROCESS )NULL + : (LPFN_ISWOW64PROCESS)GetProcAddress(aKern32Module, "IsWow64Process"); + + return aFunIsWow64 != NULL && + aFunIsWow64(GetCurrentProcess(), &bIsWow64) && + bIsWow64 != FALSE; + } +} +#endif + +//======================================================================= +//function : NbLogicalProcessors +//purpose : Returns number of logical proccessors. +//======================================================================= +Standard_Integer OSD_Parallel::NbLogicalProcessors() +{ + static Standard_Integer aNumLogicalProcessors = 0; + if ( aNumLogicalProcessors != 0 ) + { + return aNumLogicalProcessors; + } +#ifdef _WIN32 + // GetSystemInfo() will return the number of processors in a data field in a SYSTEM_INFO structure. + SYSTEM_INFO aSysInfo; + if ( isWow64() ) + { + typedef BOOL (WINAPI *LPFN_GSI)(LPSYSTEM_INFO ); + HMODULE aKern32 = GetModuleHandleW(L"kernel32"); + LPFN_GSI aFuncSysInfo = (LPFN_GSI )GetProcAddress(aKern32, "GetNativeSystemInfo"); + // So, they suggest 32-bit apps should call this instead of the other in WOW64 + if ( aFuncSysInfo != NULL ) + { + aFuncSysInfo(&aSysInfo); + } + else + { + GetSystemInfo(&aSysInfo); + } + } + else + { + GetSystemInfo(&aSysInfo); + } + aNumLogicalProcessors = aSysInfo.dwNumberOfProcessors; +#else + // These are the choices. We'll check number of processors online. + // _SC_NPROCESSORS_CONF Number of processors configured + // _SC_NPROCESSORS_MAX Max number of processors supported by platform + // _SC_NPROCESSORS_ONLN Number of processors online + aNumLogicalProcessors = (Standard_Integer)sysconf(_SC_NPROCESSORS_ONLN); +#endif + return aNumLogicalProcessors; +} diff --git a/src/OSD/OSD_Parallel.hxx b/src/OSD/OSD_Parallel.hxx new file mode 100644 index 0000000000..7ac171a19f --- /dev/null +++ b/src/OSD/OSD_Parallel.hxx @@ -0,0 +1,298 @@ +// Copyright (c) 2013-2014 OPEN CASCADE SAS +// +// This file is part of Open CASCADE Technology software library. +// +// This library is free software; you can redistribute it and/or modify it under +// the terms of the GNU Lesser General Public License version 2.1 as published +// by the Free Software Foundation, with special exception defined in the file +// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT +// distribution for complete text of the license and disclaimer of any warranty. +// +// Alternatively, this file may be used under the terms of Open CASCADE +// commercial license or contractual agreement. + +#ifndef OSD_Parallel_HeaderFile +#define OSD_Parallel_HeaderFile + +#include +#include +#include +#include +#include + +#ifdef HAVE_TBB +#include +#include +#include +#endif + +//! @class OSD_Parallel +//! @brief Simplifies code parallelization. +//! +//! The Class provides an interface of parallel processing "for" and "foreach" loops. +//! These primitives encapsulates complete logic for creating and managing parallel context of loops. +//! Moreover the primitives may be a wrapper for some primitives from 3rd-party library - TBB. +//! To use it is necessary to implement TBB like interface which is based on functors. +//! +//! @code +//! class Functor +//! { +//! public: +//! void operator() ([proccesing instance]) const +//! { +//! //... +//! } +//! }; +//! @endcode +//! +//! In the body of the operator () should be implemented thread-safe logic of computations that can be performed in parallel context. +//! If parallelized loop iterates on the collections with direct access by index (such as Vector, Array), +//! it is more efficient to use the primitive ParallelFor (because it has no critical section). +class OSD_Parallel +{ + //! Auxiliary class which ensures exclusive + //! access to iterators of processed data pool. + template + class Range + { + public: //! @name public methods + + typedef Value Iterator; + + //! Constructor + Range(const Value& theBegin, const Value& theEnd) + : myBegin(theBegin), + myEnd (theEnd), + myIt (theBegin) + { + } + + //! Returns const link on the first element. + inline const Value& Begin() const + { + return myBegin; + } + + //! Returns const link on the last element. + inline const Value& End() const + { + return myEnd; + } + + //! Returns first non processed element or end. + //! Thread-safe method. + inline Iterator It() const + { + Standard_Mutex::Sentry aMutex( myMutex ); + return ( myIt != myEnd ) ? myIt++ : myEnd; + } + + private: //! @name private methods + + //! Empty copy constructor + Range(const Range& theCopy); + + //! Empty copy operator. + Range& operator=(const Range& theCopy); + + private: //! @name private fields + + const Value& myBegin; //!< Fisrt element of range. + const Value& myEnd; //!< Last element of range. + mutable Value myIt; //!< First non processed element of range. + mutable Standard_Mutex myMutex; //!< Access controller for the first non processed element. + }; + + //! Auxiliary wrapper class for thread function. + template + class Task + { + public: //! @name public methods + + //! Constructor. + Task(const Functor& thePerformer, Range& theRange) + : myPerformer(thePerformer), + myRange (theRange) + { + } + + //! Method is executed in the context of thread, + //! so this method defines the main calculations. + static Standard_Address RunWithIterator(Standard_Address theTask) + { + Task& aTask = + *( static_cast< Task* >(theTask) ); + + const Range& aData( aTask.myRange ); + typename Range::Iterator i = aData.It(); + + for ( ; i != aData.End(); i = aData.It() ) + { + aTask.myPerformer(*i); + } + + return NULL; + } + + //! Method is executed in the context of thread, + //! so this method defines the main calculations. + static Standard_Address RunWithIndex(Standard_Address theTask) + { + Task& aTask = + *( static_cast< Task* >(theTask) ); + + const Range& aData( aTask.myRange ); + Standard_Integer i = aData.It(); + + for ( ; i < aData.End(); i = aData.It()) + { + aTask.myPerformer(i); + } + + return NULL; + } + + private: //! @name private methods + + //! Empty copy constructor. + Task(const Task& theCopy); + + //! Empty copy operator. + Task& operator=(const Task& theCopy); + + private: //! @name private fields + + const Functor& myPerformer; //!< Link on functor. + const Range& myRange; //!< Link on processed data block. + }; + +public: //! @name public methods + + //! Returns number of logical proccesrs. + Standard_EXPORT static Standard_Integer NbLogicalProcessors(); + + //! Simple primitive for parallelization of "foreach" loops. + template + static void ForEach( InputIterator theBegin, + InputIterator theEnd, + const Functor& theFunctor, + const Standard_Boolean isForceSingleThreadExecution + = Standard_False ); + + //! Simple primitive for parallelization of "for" loops. + template + static void For( const Standard_Integer theBegin, + const Standard_Integer theEnd, + const Functor& theFunctor, + const Standard_Boolean isForceSingleThreadExecution + = Standard_False ); +}; + +//======================================================================= +//function : OSD_Parallel::Range::It +//purpose : Template concretization. +//======================================================================= +template<> inline Standard_Integer OSD_Parallel::Range::It() const +{ + return Standard_Atomic_Increment( reinterpret_cast(&myIt) ) - 1; +} + +//======================================================================= +//function : ParallelForEach +//purpose : +//======================================================================= +template +void OSD_Parallel::ForEach( InputIterator theBegin, + InputIterator theEnd, + const Functor& theFunctor, + const Standard_Boolean isForceSingleThreadExecution ) +{ + if ( isForceSingleThreadExecution ) + { + for ( InputIterator it(theBegin); it != theEnd; it++ ) + theFunctor(*it); + + return; + } + #ifdef HAVE_TBB + { + try + { + tbb::parallel_for_each(theBegin, theEnd, theFunctor); + } + catch ( tbb::captured_exception& anException ) + { + Standard_NotImplemented::Raise(anException.what()); + } + } + #else + { + Range aData(theBegin, theEnd); + Task aTask(theFunctor, aData); + + const Standard_Integer aNbThreads = OSD_Parallel::NbLogicalProcessors(); + NCollection_Array1 aThreads(0, aNbThreads - 1); + + for ( Standard_Integer i = 0; i < aNbThreads; ++i ) + { + OSD_Thread& aThread = aThreads(i); + aThread.SetFunction(&Task::RunWithIterator); + aThread.Run(&aTask); + } + + for ( Standard_Integer i = 0; i < aNbThreads; ++i ) + aThreads(i).Wait(); + } + #endif +} + +//======================================================================= +//function : ParallelFor +//purpose : +//======================================================================= +template +void OSD_Parallel::For( const Standard_Integer theBegin, + const Standard_Integer theEnd, + const Functor& theFunctor, + const Standard_Boolean isForceSingleThreadExecution ) +{ + if ( isForceSingleThreadExecution ) + { + for ( Standard_Integer i = theBegin; i < theEnd; ++i ) + theFunctor(i); + + return; + } + #ifdef HAVE_TBB + { + try + { + tbb::parallel_for( theBegin, theEnd, theFunctor ); + } + catch ( tbb::captured_exception& anException ) + { + Standard_NotImplemented::Raise(anException.what()); + } + } + #else + { + Range aData(theBegin, theEnd); + Task aTask(theFunctor, aData); + + const Standard_Integer aNbThreads = OSD_Parallel::NbLogicalProcessors(); + NCollection_Array1 aThreads(0, aNbThreads - 1); + + for ( Standard_Integer i = 0; i < aNbThreads; ++i ) + { + OSD_Thread& aThread = aThreads(i); + aThread.SetFunction(&Task::RunWithIndex); + aThread.Run(&aTask); + } + + for ( Standard_Integer i = 0; i < aNbThreads; ++i ) + aThreads(i).Wait(); + } + #endif +} + +#endif diff --git a/src/OpenGl/OpenGl_SceneGeometry.cxx b/src/OpenGl/OpenGl_SceneGeometry.cxx index 512bb22136..2411e1162f 100755 --- a/src/OpenGl/OpenGl_SceneGeometry.cxx +++ b/src/OpenGl/OpenGl_SceneGeometry.cxx @@ -13,17 +13,8 @@ // Alternatively, this file may be used under the terms of Open CASCADE // commercial license or contractual agreement. -#ifdef HAVE_TBB - // On Windows, function TryEnterCriticalSection has appeared in Windows NT - // and is surrounded by #ifdef in MS VC++ 7.1 headers. - // Thus to use it we need to define appropriate macro saying that we will - // run on Windows NT 4.0 at least - #if defined(_WIN32) && !defined(_WIN32_WINNT) - #define _WIN32_WINNT 0x0501 - #endif - - #include -#endif +#include +#include #include @@ -208,8 +199,6 @@ void OpenGl_RaytraceGeometry::Clear() Materials.swap (anEmptyMaterials); } -#ifdef HAVE_TBB - struct OpenGL_BVHParallelBuilder { BVH_ObjectSet* Set; @@ -220,23 +209,16 @@ struct OpenGL_BVHParallelBuilder // } - void operator() (const tbb::blocked_range& theRange) const + void operator() (const Standard_Integer theObjectIdx) const { - for (size_t anObjectIdx = theRange.begin(); anObjectIdx != theRange.end(); ++anObjectIdx) - { - OpenGl_TriangleSet* aTriangleSet = dynamic_cast ( - Set->Objects().ChangeValue (static_cast (anObjectIdx)).operator->()); + OpenGl_TriangleSet* aTriangleSet = dynamic_cast ( + Set->Objects().ChangeValue (static_cast (theObjectIdx)).operator->()); - if (aTriangleSet != NULL) - { - aTriangleSet->BVH(); - } - } + if (aTriangleSet != NULL) + aTriangleSet->BVH(); } }; -#endif - // ======================================================================= // function : ProcessAcceleration // purpose : Performs post-processing of high-level BVH @@ -254,12 +236,7 @@ Standard_Boolean OpenGl_RaytraceGeometry::ProcessAcceleration() aTimer.Start(); #endif -#ifdef HAVE_TBB - // If Intel TBB is available, perform the preliminary - // construction of bottom-level scene BVHs - tbb::parallel_for (tbb::blocked_range (0, Size()), - OpenGL_BVHParallelBuilder (this)); -#endif + OSD_Parallel::For(0, Size(), OpenGL_BVHParallelBuilder(this)); myBottomLevelTreeDepth = 0; diff --git a/src/QABugs/QABugs_19.cxx b/src/QABugs/QABugs_19.cxx index 67f8d9e246..bebcdab56b 100755 --- a/src/QABugs/QABugs_19.cxx +++ b/src/QABugs/QABugs_19.cxx @@ -39,8 +39,9 @@ #include #include #include -#include #include +#include +#include #include #include #include @@ -157,32 +158,23 @@ static Standard_Integer OCC23237 (Draw_Interpretor& di, Standard_Integer /*argc* return 0; } -#ifdef HAVE_TBB - -#include -#include - class IncrementerDecrementer { public: IncrementerDecrementer (Standard_Integer* theVal, Standard_Boolean thePositive) : myVal (theVal), myPositive (thePositive) {} - void operator() (const tbb::blocked_range& r) const + void operator() (const size_t) const { - if (myPositive) - for (size_t i = r.begin(); i != r.end(); ++i) - Standard_Atomic_Increment (myVal); - else - for (size_t i = r.begin(); i != r.end(); ++i) - Standard_Atomic_Decrement (myVal); + if ( myPositive ) + Standard_Atomic_Increment(myVal); + else + Standard_Atomic_Decrement(myVal); } private: Standard_Integer* myVal; - Standard_Boolean myPositive; + Standard_Boolean myPositive; }; -#endif -#ifdef HAVE_TBB static Standard_Integer OCC22980 (Draw_Interpretor& di, Standard_Integer /*argc*/, const char ** /*argv*/) { int aSum = 0; @@ -200,26 +192,16 @@ static Standard_Integer OCC22980 (Draw_Interpretor& di, Standard_Integer /*argc* const int N = 1 << 24; //big enough to ensure concurrency //increment - tbb::parallel_for (tbb::blocked_range (0, N), IncrementerDecrementer (&aSum, true)); + OSD_Parallel::For(0, N, IncrementerDecrementer (&aSum, true)); QCOMPARE (aSum, N); //decrement - tbb::parallel_for (tbb::blocked_range (0, N), IncrementerDecrementer (&aSum, false)); + OSD_Parallel::For(0, N, IncrementerDecrementer (&aSum, false)); QCOMPARE (aSum, 0); return 0; } -#else /* HAVE_TBB */ - -static Standard_Integer OCC22980 (Draw_Interpretor& di, Standard_Integer /*argc*/, const char **argv) -{ - di << "Test skipped: command " << argv[0] << " requires TBB library\n"; - return 0; -} - -#endif /* HAVE_TBB */ - #include #include #include @@ -2902,6 +2884,92 @@ static Standard_Integer OCC25340 (Draw_Interpretor& /*theDI*/, return 0; } +//======================================================================= +//function : OCC24826 +//purpose : +//======================================================================= +class ParallelTest_Saxpy +{ +public: + typedef NCollection_Array1 Vector; + + //! Constructor + ParallelTest_Saxpy(const Vector& theX, Vector& theY, Standard_Real theScalar) + : myX(theX), + myY(theY), + myScalar(theScalar) + { + } + + //! Dummy calculation + void operator() (const Standard_Integer theIndex) const + { + myY(theIndex) = myScalar * myX(theIndex) + myY(theIndex); + } + +private: + ParallelTest_Saxpy( const ParallelTest_Saxpy& ); + ParallelTest_Saxpy& operator =( ParallelTest_Saxpy& ); + +private: + const Vector& myX; + Vector& myY; + const Standard_Real myScalar; +}; + +//--------------------------------------------------------------------- +static Standard_Integer OCC24826(Draw_Interpretor& theDI, + Standard_Integer trheArgc, + const char** theArgv) +{ + if ( trheArgc != 2 ) + { + theDI << "Usage: " + << theArgv[0] + << " vec_length\n"; + return 1; + } + + // Generate data; + Standard_Integer aLength = Draw::Atoi(theArgv[1]); + + NCollection_Array1 aX (0, aLength - 1); + NCollection_Array1 anY(0, aLength - 1); + + for ( Standard_Integer i = 0; i < aLength; ++i ) + { + aX(i) = anY(i) = (Standard_Real) i; + } + + OSD_Timer aTimer; + + aTimer.Start(); + + //! Serial proccesing + for ( Standard_Integer i = 0; i < aLength; ++i ) + { + anY(i) = 1e-6 * aX(i) + anY(i); + } + + aTimer.Stop(); + cout << "Processing time (sequential mode):\n"; + aTimer.Show(); + + const ParallelTest_Saxpy aFunctor(aX, anY, 1e-6); + + aTimer.Reset(); + aTimer.Start(); + + // Parallel processing + OSD_Parallel::For(0, aLength, aFunctor); + + aTimer.Stop(); + cout << "Processing time (parallel mode):\n"; + aTimer.Show(); + + return 0; +} + /*****************************************************************************/ #include @@ -3328,6 +3396,7 @@ void QABugs::Commands_19(Draw_Interpretor& theCommands) { __FILE__, OCC24925, group); theCommands.Add ("OCC23010", "OCC23010 STEP_file", __FILE__, OCC23010, group); theCommands.Add ("OCC25043", "OCC25043 shape", __FILE__, OCC25043, group); + theCommands.Add ("OCC24826,", "This test performs simple saxpy test.\n Usage: OCC24826 length", __FILE__, OCC24826, group); theCommands.Add ("OCC24606", "OCC24606 : Tests ::FitAll for V3d view ('vfit' is for NIS view)", __FILE__, OCC24606, group); theCommands.Add ("OCC25202", "OCC25202 res shape numF1 face1 numF2 face2", __FILE__, OCC25202, group); theCommands.Add ("OCC7570", "OCC7570 shape", __FILE__, OCC7570, group); diff --git a/src/QANCollection/QANCollection_Stl.cxx b/src/QANCollection/QANCollection_Stl.cxx index 3c1332bae4..a4b94e2f92 100644 --- a/src/QANCollection/QANCollection_Stl.cxx +++ b/src/QANCollection/QANCollection_Stl.cxx @@ -26,20 +26,7 @@ #include #include #include - -#ifdef HAVE_TBB - // On Windows, function TryEnterCriticalSection has appeared in Windows NT - // and is surrounded by #ifdef in MS VC++ 7.1 headers. - // Thus to use it we need to define appropriate macro saying that we will - // run on Windows NT 4.0 at least - #if ((defined(_WIN32) || defined(__WIN32__)) && !defined(_WIN32_WINNT)) - #define _WIN32_WINNT 0x0501 - #endif - - #include - #include -#endif - +#include #include #include #include @@ -343,8 +330,6 @@ Standard_Boolean TestSort() return aResult; } -#ifdef HAVE_TBB - template struct Invoker { @@ -355,19 +340,19 @@ struct Invoker }; //======================================================================= -//function : TestTBB +//function : TestParallel //purpose : //======================================================================= template -Standard_Boolean TestTBB() +Standard_Boolean TestParallel() { StlType* aVector (NULL); CollectionType* aCollec (NULL); CollectionFiller::Perform (&aVector, &aCollec); - tbb::parallel_for_each (aVector->begin(), aVector->end(), Invoker()); - tbb::parallel_for_each (aCollec->begin(), aCollec->end(), Invoker()); + OSD_Parallel::ForEach(aVector->begin(), aVector->end(), Invoker()); + OSD_Parallel::ForEach(aCollec->begin(), aCollec->end(), Invoker()); typename StlType::iterator aVecIter = aVector->begin(); typename CollectionType::iterator aColIter = aCollec->begin(); @@ -392,18 +377,18 @@ Standard_Boolean TestTBB() } //======================================================================= -//function : TestDataMapTBB +//function : TestDataMapParallel //purpose : //======================================================================= template -Standard_Boolean TestDataMapTBB() +Standard_Boolean TestDataMapParallel() { CollectionType* aCollec1 (NULL); CollectionType* aCollec2 (NULL); MapFiller::Perform (&aCollec1, &aCollec2); - tbb::parallel_for_each (aCollec1->begin(), aCollec1->end(), Invoker()); + OSD_Parallel::ForEach(aCollec1->begin(), aCollec1->end(), Invoker()); // create OCCT-style iterator typename CollectionType::Iterator aOccIter (*aCollec2); @@ -430,8 +415,6 @@ Standard_Boolean TestDataMapTBB() return aResult; } -#endif - //======================================================================= //function : TestMapIteration //purpose : @@ -605,18 +588,14 @@ static Standard_Integer QANListStlIterator (Draw_Interpretor&, Standard_Integer, std::cout << "NCollection_List Replace: " << (aResult ? "SUCCESS" : "FAIL") << std::endl; -#ifdef HAVE_TBB - - aResult = TestTBB, std::list >(); - std::cout << "NCollection_List TBB: " << + aResult = TestParallel< NCollection_List, std::list >(); + std::cout << "NCollection_List Parallel: " << (aResult ? "SUCCESS" : "FAIL") << std::endl; - aResult = TestTBB, std::list >(); - std::cout << "NCollection_List TBB: " << + aResult = TestParallel, std::list >(); + std::cout << "NCollection_List Parallel: " << (aResult ? "SUCCESS" : "FAIL") << std::endl; -#endif - return 0; } @@ -682,18 +661,14 @@ static Standard_Integer QANDataMapStlIterator (Draw_Interpretor&, Standard_Integ std::cout << "NCollection_DataMap Iteration: " << (aResult ? "SUCCESS" : "FAIL") << std::endl; -#ifdef HAVE_TBB - - aResult = TestDataMapTBB, Standard_Integer>(); - std::cout << "NCollection_DataMap TBB: " << + aResult = TestDataMapParallel, Standard_Integer>(); + std::cout << "NCollection_DataMap Parallel: " << (aResult ? "SUCCESS" : "FAIL") << std::endl; - aResult = TestDataMapTBB, Standard_Real>(); - std::cout << "NCollection_DataMap TBB: " << + aResult = TestDataMapParallel, Standard_Real>(); + std::cout << "NCollection_DataMap Parallel: " << (aResult ? "SUCCESS" : "FAIL") << std::endl; -#endif - return 0; } @@ -716,18 +691,14 @@ static Standard_Integer QANIndexedDataMapStlIterator (Draw_Interpretor&, Standar std::cout << "NCollection_IndexedDataMap Iteration: " << (aResult ? "SUCCESS" : "FAIL") << std::endl; -#ifdef HAVE_TBB - - aResult = TestDataMapTBB, Standard_Integer>(); - std::cout << "NCollection_IndexedDataMap TBB: " << + aResult = TestDataMapParallel, Standard_Integer>(); + std::cout << "NCollection_IndexedDataMap Parallel: " << (aResult ? "SUCCESS" : "FAIL") << std::endl; - aResult = TestDataMapTBB, Standard_Real>(); - std::cout << "NCollection_IndexedDataMap TBB: " << + aResult = TestDataMapParallel, Standard_Real>(); + std::cout << "NCollection_IndexedDataMap Parallel: " << (aResult ? "SUCCESS" : "FAIL") << std::endl; -#endif - return 0; } @@ -774,18 +745,14 @@ static Standard_Integer QANSequenceStlIterator (Draw_Interpretor&, Standard_Inte std::cout << "NCollection_Sequence Reverse: " << (aResult ? "SUCCESS" : "FAIL") << std::endl; -#ifdef HAVE_TBB - - aResult = TestTBB, std::list >(); - std::cout << "NCollection_Sequence TBB: " << + aResult = TestParallel, std::list >(); + std::cout << "NCollection_Sequence Parallel: " << (aResult ? "SUCCESS" : "FAIL") << std::endl; - aResult = TestTBB, std::list >(); - std::cout << "NCollection_Sequence TBB: " << + aResult = TestParallel, std::list >(); + std::cout << "NCollection_Sequence Parallel: " << (aResult ? "SUCCESS" : "FAIL") << std::endl; -#endif - return 0; } @@ -841,18 +808,14 @@ static Standard_Integer QANVectorStlIterator (Draw_Interpretor&, Standard_Intege std::cout << "NCollection_Vector Sort: " << (aResult ? "SUCCESS" : "FAIL") << std::endl; -#ifdef HAVE_TBB - - aResult = TestTBB, std::vector >(); - std::cout << "NCollection_Vector TBB: " << + aResult = TestParallel, std::vector >(); + std::cout << "NCollection_Vector Parallel: " << (aResult ? "SUCCESS" : "FAIL") << std::endl; - aResult = TestTBB, std::vector >(); - std::cout << "NCollection_Vector TBB: " << + aResult = TestParallel, std::vector >(); + std::cout << "NCollection_Vector Parallel: " << (aResult ? "SUCCESS" : "FAIL") << std::endl; -#endif - return 0; } @@ -908,18 +871,14 @@ static Standard_Integer QANArray1StlIterator (Draw_Interpretor&, Standard_Intege std::cout << "NCollection_Array1 Sort: " << (aResult ? "SUCCESS" : "FAIL") << std::endl; -#ifdef HAVE_TBB - - aResult = TestTBB, std::vector >(); - std::cout << "NCollection_Array1 TBB: " << + aResult = TestParallel, std::vector >(); + std::cout << "NCollection_Array1 Parallel: " << (aResult ? "SUCCESS" : "FAIL") << std::endl; - aResult = TestTBB, std::vector >(); - std::cout << "NCollection_Array1 TBB: " << + aResult = TestParallel, std::vector >(); + std::cout << "NCollection_Array1 Parallel: " << (aResult ? "SUCCESS" : "FAIL") << std::endl; -#endif - return 0; } -- 2.39.5