1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-08-04 13:13:25 +03:00

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.
This commit is contained in:
msv
2015-02-05 15:49:35 +03:00
committed by bugmaster
parent a61133c8c7
commit c7b59798ca
34 changed files with 837 additions and 683 deletions

View File

@@ -62,7 +62,7 @@
#include <BOPCol_BoxBndTree.hxx> #include <BOPCol_BoxBndTree.hxx>
#include <BOPCol_ListOfInteger.hxx> #include <BOPCol_ListOfInteger.hxx>
#include <BOPCol_NCVector.hxx> #include <BOPCol_NCVector.hxx>
#include <BOPCol_TBB.hxx> #include <BOPCol_Parallel.hxx>
// //
#include <BOPTools.hxx> #include <BOPTools.hxx>
#include <BOPTools_CoupleOfShape.hxx> #include <BOPTools_CoupleOfShape.hxx>
@@ -247,13 +247,13 @@ class BOPAlgo_FaceSolid : public BOPAlgo_Algo {
typedef BOPCol_NCVector typedef BOPCol_NCVector
<BOPAlgo_FaceSolid> BOPAlgo_VectorOfFaceSolid; <BOPAlgo_FaceSolid> BOPAlgo_VectorOfFaceSolid;
// //
typedef BOPCol_TBBContextFunctor typedef BOPCol_ContextFunctor
<BOPAlgo_FaceSolid, <BOPAlgo_FaceSolid,
BOPAlgo_VectorOfFaceSolid, BOPAlgo_VectorOfFaceSolid,
Handle(IntTools_Context), Handle(IntTools_Context),
IntTools_Context> BOPAlgo_FaceSolidFunctor; IntTools_Context> BOPAlgo_FaceSolidFunctor;
// //
typedef BOPCol_TBBContextCnt typedef BOPCol_ContextCnt
<BOPAlgo_FaceSolidFunctor, <BOPAlgo_FaceSolidFunctor,
BOPAlgo_VectorOfFaceSolid, BOPAlgo_VectorOfFaceSolid,
Handle(IntTools_Context)> BOPAlgo_FaceSolidCnt; Handle(IntTools_Context)> BOPAlgo_FaceSolidCnt;

View File

@@ -36,7 +36,7 @@
#include <BOPCol_DataMapOfIntegerListOfShape.hxx> #include <BOPCol_DataMapOfIntegerListOfShape.hxx>
#include <BOPCol_DataMapOfShapeShape.hxx> #include <BOPCol_DataMapOfShapeShape.hxx>
#include <BOPCol_NCVector.hxx> #include <BOPCol_NCVector.hxx>
#include <BOPCol_TBB.hxx> #include <BOPCol_Parallel.hxx>
// //
#include <IntTools_Context.hxx> #include <IntTools_Context.hxx>
// //
@@ -138,13 +138,13 @@ class BOPAlgo_PairOfShapeBoolean : public BOPAlgo_Algo {
typedef BOPCol_NCVector<BOPAlgo_PairOfShapeBoolean> \ typedef BOPCol_NCVector<BOPAlgo_PairOfShapeBoolean> \
BOPAlgo_VectorOfPairOfShapeBoolean; BOPAlgo_VectorOfPairOfShapeBoolean;
// //
typedef BOPCol_TBBContextFunctor typedef BOPCol_ContextFunctor
<BOPAlgo_PairOfShapeBoolean, <BOPAlgo_PairOfShapeBoolean,
BOPAlgo_VectorOfPairOfShapeBoolean, BOPAlgo_VectorOfPairOfShapeBoolean,
Handle(IntTools_Context), Handle(IntTools_Context),
IntTools_Context> BOPCol_BuilderSDFaceFunctor; IntTools_Context> BOPCol_BuilderSDFaceFunctor;
// //
typedef BOPCol_TBBContextCnt typedef BOPCol_ContextCnt
<BOPCol_BuilderSDFaceFunctor, <BOPCol_BuilderSDFaceFunctor,
BOPAlgo_VectorOfPairOfShapeBoolean, BOPAlgo_VectorOfPairOfShapeBoolean,
Handle(IntTools_Context)> BOPAlgo_BuilderSDFaceCnt; Handle(IntTools_Context)> BOPAlgo_BuilderSDFaceCnt;
@@ -154,11 +154,11 @@ typedef BOPCol_TBBContextCnt
// //
typedef BOPCol_NCVector<BOPAlgo_BuilderFace> BOPAlgo_VectorOfBuilderFace; typedef BOPCol_NCVector<BOPAlgo_BuilderFace> BOPAlgo_VectorOfBuilderFace;
// //
typedef BOPCol_TBBFunctor typedef BOPCol_Functor
<BOPAlgo_BuilderFace, <BOPAlgo_BuilderFace,
BOPAlgo_VectorOfBuilderFace> BOPAlgo_BuilderFaceFunctor; BOPAlgo_VectorOfBuilderFace> BOPAlgo_BuilderFaceFunctor;
// //
typedef BOPCol_TBBCnt typedef BOPCol_Cnt
<BOPAlgo_BuilderFaceFunctor, <BOPAlgo_BuilderFaceFunctor,
BOPAlgo_VectorOfBuilderFace> BOPAlgo_BuilderFaceCnt; BOPAlgo_VectorOfBuilderFace> BOPAlgo_BuilderFaceCnt;
// //
@@ -223,13 +223,13 @@ class BOPAlgo_VFI : public BOPAlgo_Algo {
// //
typedef BOPCol_NCVector<BOPAlgo_VFI> BOPAlgo_VectorOfVFI; typedef BOPCol_NCVector<BOPAlgo_VFI> BOPAlgo_VectorOfVFI;
// //
typedef BOPCol_TBBContextFunctor typedef BOPCol_ContextFunctor
<BOPAlgo_VFI, <BOPAlgo_VFI,
BOPAlgo_VectorOfVFI, BOPAlgo_VectorOfVFI,
Handle(IntTools_Context), Handle(IntTools_Context),
IntTools_Context> BOPAlgo_VFIFunctor; IntTools_Context> BOPAlgo_VFIFunctor;
// //
typedef BOPCol_TBBContextCnt typedef BOPCol_ContextCnt
<BOPAlgo_VFIFunctor, <BOPAlgo_VFIFunctor,
BOPAlgo_VectorOfVFI, BOPAlgo_VectorOfVFI,
Handle(IntTools_Context)> BOPAlgo_VFICnt; Handle(IntTools_Context)> BOPAlgo_VFICnt;

View File

@@ -52,7 +52,7 @@
#include <BOPCol_ListOfInteger.hxx> #include <BOPCol_ListOfInteger.hxx>
#include <BOPCol_DataMapOfIntegerShape.hxx> #include <BOPCol_DataMapOfIntegerShape.hxx>
#include <BOPCol_NCVector.hxx> #include <BOPCol_NCVector.hxx>
#include <BOPCol_TBB.hxx> #include <BOPCol_Parallel.hxx>
// //
#include <IntTools_Context.hxx> #include <IntTools_Context.hxx>
// //
@@ -84,11 +84,11 @@ static
typedef BOPCol_NCVector typedef BOPCol_NCVector
<BOPAlgo_BuilderSolid> BOPAlgo_VectorOfBuilderSolid; <BOPAlgo_BuilderSolid> BOPAlgo_VectorOfBuilderSolid;
// //
typedef BOPCol_TBBFunctor typedef BOPCol_Functor
<BOPAlgo_BuilderSolid, <BOPAlgo_BuilderSolid,
BOPAlgo_VectorOfBuilderSolid> BOPAlgo_BuilderSolidFunctor; BOPAlgo_VectorOfBuilderSolid> BOPAlgo_BuilderSolidFunctor;
// //
typedef BOPCol_TBBCnt typedef BOPCol_Cnt
<BOPAlgo_BuilderSolidFunctor, <BOPAlgo_BuilderSolidFunctor,
BOPAlgo_VectorOfBuilderSolid> BOPAlgo_BuilderSolidCnt; BOPAlgo_VectorOfBuilderSolid> BOPAlgo_BuilderSolidCnt;
// //

View File

@@ -22,7 +22,7 @@
#include <BRep_Tool.hxx> #include <BRep_Tool.hxx>
#include <BOPCol_NCVector.hxx> #include <BOPCol_NCVector.hxx>
#include <BOPCol_TBB.hxx> #include <BOPCol_Parallel.hxx>
#include <IntTools_Context.hxx> #include <IntTools_Context.hxx>
@@ -118,13 +118,13 @@ class BOPAlgo_VertexEdge : public BOPAlgo_Algo {
typedef BOPCol_NCVector typedef BOPCol_NCVector
<BOPAlgo_VertexEdge> BOPAlgo_VectorOfVertexEdge; <BOPAlgo_VertexEdge> BOPAlgo_VectorOfVertexEdge;
// //
typedef BOPCol_TBBContextFunctor typedef BOPCol_ContextFunctor
<BOPAlgo_VertexEdge, <BOPAlgo_VertexEdge,
BOPAlgo_VectorOfVertexEdge, BOPAlgo_VectorOfVertexEdge,
Handle(IntTools_Context), Handle(IntTools_Context),
IntTools_Context> BOPAlgo_VertexEdgeFunctor; IntTools_Context> BOPAlgo_VertexEdgeFunctor;
// //
typedef BOPCol_TBBContextCnt typedef BOPCol_ContextCnt
<BOPAlgo_VertexEdgeFunctor, <BOPAlgo_VertexEdgeFunctor,
BOPAlgo_VectorOfVertexEdge, BOPAlgo_VectorOfVertexEdge,
Handle(IntTools_Context)> BOPAlgo_VertexEdgeCnt; Handle(IntTools_Context)> BOPAlgo_VertexEdgeCnt;

View File

@@ -47,7 +47,7 @@
#include <BOPCol_IndexedDataMapOfShapeBox.hxx> #include <BOPCol_IndexedDataMapOfShapeBox.hxx>
#include <BOPCol_BoxBndTree.hxx> #include <BOPCol_BoxBndTree.hxx>
#include <BOPCol_NCVector.hxx> #include <BOPCol_NCVector.hxx>
#include <BOPCol_TBB.hxx> #include <BOPCol_Parallel.hxx>
// //
#include <IntTools_Context.hxx> #include <IntTools_Context.hxx>
#include <IntTools_ShrunkRange.hxx> #include <IntTools_ShrunkRange.hxx>
@@ -116,11 +116,11 @@ class BOPAlgo_EdgeEdge :
typedef BOPCol_NCVector typedef BOPCol_NCVector
<BOPAlgo_EdgeEdge> BOPAlgo_VectorOfEdgeEdge; <BOPAlgo_EdgeEdge> BOPAlgo_VectorOfEdgeEdge;
// //
typedef BOPCol_TBBFunctor typedef BOPCol_Functor
<BOPAlgo_EdgeEdge, <BOPAlgo_EdgeEdge,
BOPAlgo_VectorOfEdgeEdge> BOPAlgo_EdgeEdgeFunctor; BOPAlgo_VectorOfEdgeEdge> BOPAlgo_EdgeEdgeFunctor;
// //
typedef BOPCol_TBBCnt typedef BOPCol_Cnt
<BOPAlgo_EdgeEdgeFunctor, <BOPAlgo_EdgeEdgeFunctor,
BOPAlgo_VectorOfEdgeEdge> BOPAlgo_EdgeEdgeCnt; BOPAlgo_VectorOfEdgeEdge> BOPAlgo_EdgeEdgeCnt;
// //
@@ -163,11 +163,11 @@ class BOPAlgo_TNV : public BOPCol_BoxBndTreeSelector{
typedef BOPCol_NCVector typedef BOPCol_NCVector
<BOPAlgo_TNV> BOPAlgo_VectorOfTNV; <BOPAlgo_TNV> BOPAlgo_VectorOfTNV;
// //
typedef BOPCol_TBBFunctor typedef BOPCol_Functor
<BOPAlgo_TNV, <BOPAlgo_TNV,
BOPAlgo_VectorOfTNV> BOPAlgo_TNVFunctor; BOPAlgo_VectorOfTNV> BOPAlgo_TNVFunctor;
// //
typedef BOPCol_TBBCnt typedef BOPCol_Cnt
<BOPAlgo_TNVFunctor, <BOPAlgo_TNVFunctor,
BOPAlgo_VectorOfTNV> BOPAlgo_TNVCnt; BOPAlgo_VectorOfTNV> BOPAlgo_TNVCnt;
///////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////
@@ -254,13 +254,13 @@ class BOPAlgo_PVE {
typedef BOPCol_NCVector typedef BOPCol_NCVector
<BOPAlgo_PVE> BOPAlgo_VectorOfPVE; <BOPAlgo_PVE> BOPAlgo_VectorOfPVE;
// //
typedef BOPCol_TBBContextFunctor typedef BOPCol_ContextFunctor
<BOPAlgo_PVE, <BOPAlgo_PVE,
BOPAlgo_VectorOfPVE, BOPAlgo_VectorOfPVE,
Handle(IntTools_Context), Handle(IntTools_Context),
IntTools_Context> BOPAlgo_PVEFunctor; IntTools_Context> BOPAlgo_PVEFunctor;
// //
typedef BOPCol_TBBContextCnt typedef BOPCol_ContextCnt
<BOPAlgo_PVEFunctor, <BOPAlgo_PVEFunctor,
BOPAlgo_VectorOfPVE, BOPAlgo_VectorOfPVE,
Handle(IntTools_Context)> BOPAlgo_PVECnt; Handle(IntTools_Context)> BOPAlgo_PVECnt;

View File

@@ -27,7 +27,7 @@
// //
#include <BOPCol_MapOfInteger.hxx> #include <BOPCol_MapOfInteger.hxx>
#include <BOPCol_NCVector.hxx> #include <BOPCol_NCVector.hxx>
#include <BOPCol_TBB.hxx> #include <BOPCol_Parallel.hxx>
// //
#include <IntTools_Context.hxx> #include <IntTools_Context.hxx>
// //
@@ -125,13 +125,13 @@ class BOPAlgo_VertexFace : public BOPAlgo_Algo {
typedef BOPCol_NCVector<BOPAlgo_VertexFace> typedef BOPCol_NCVector<BOPAlgo_VertexFace>
BOPAlgo_VectorOfVertexFace; BOPAlgo_VectorOfVertexFace;
// //
typedef BOPCol_TBBContextFunctor typedef BOPCol_ContextFunctor
<BOPAlgo_VertexFace, <BOPAlgo_VertexFace,
BOPAlgo_VectorOfVertexFace, BOPAlgo_VectorOfVertexFace,
Handle(IntTools_Context), Handle(IntTools_Context),
IntTools_Context> BOPAlgo_VertexFaceFunctor; IntTools_Context> BOPAlgo_VertexFaceFunctor;
// //
typedef BOPCol_TBBContextCnt typedef BOPCol_ContextCnt
<BOPAlgo_VertexFaceFunctor, <BOPAlgo_VertexFaceFunctor,
BOPAlgo_VectorOfVertexFace, BOPAlgo_VectorOfVertexFace,
Handle(IntTools_Context)> BOPAlgo_VertexFaceCnt; Handle(IntTools_Context)> BOPAlgo_VertexFaceCnt;

View File

@@ -38,7 +38,7 @@
// //
#include <BOPCol_MapOfInteger.hxx> #include <BOPCol_MapOfInteger.hxx>
#include <BOPCol_NCVector.hxx> #include <BOPCol_NCVector.hxx>
#include <BOPCol_TBB.hxx> #include <BOPCol_Parallel.hxx>
// //
#include <IntTools_Context.hxx> #include <IntTools_Context.hxx>
#include <IntTools_Tools.hxx> #include <IntTools_Tools.hxx>
@@ -119,13 +119,13 @@ class BOPAlgo_EdgeFace :
//======================================================================= //=======================================================================
typedef BOPCol_NCVector<BOPAlgo_EdgeFace> BOPAlgo_VectorOfEdgeFace; typedef BOPCol_NCVector<BOPAlgo_EdgeFace> BOPAlgo_VectorOfEdgeFace;
// //
typedef BOPCol_TBBContextFunctor typedef BOPCol_ContextFunctor
<BOPAlgo_EdgeFace, <BOPAlgo_EdgeFace,
BOPAlgo_VectorOfEdgeFace, BOPAlgo_VectorOfEdgeFace,
Handle(IntTools_Context), Handle(IntTools_Context),
IntTools_Context> BOPAlgo_EdgeFaceFunctor; IntTools_Context> BOPAlgo_EdgeFaceFunctor;
// //
typedef BOPCol_TBBContextCnt typedef BOPCol_ContextCnt
<BOPAlgo_EdgeFaceFunctor, <BOPAlgo_EdgeFaceFunctor,
BOPAlgo_VectorOfEdgeFace, BOPAlgo_VectorOfEdgeFace,
Handle(IntTools_Context)> BOPAlgo_EdgeFaceCnt; Handle(IntTools_Context)> BOPAlgo_EdgeFaceCnt;

View File

@@ -69,7 +69,7 @@
#include <BOPCol_IndexedMapOfInteger.hxx> #include <BOPCol_IndexedMapOfInteger.hxx>
#include <BOPCol_DataMapOfIntegerReal.hxx> #include <BOPCol_DataMapOfIntegerReal.hxx>
#include <BOPCol_NCVector.hxx> #include <BOPCol_NCVector.hxx>
#include <BOPCol_TBB.hxx> #include <BOPCol_Parallel.hxx>
#include <BOPDS_Interf.hxx> #include <BOPDS_Interf.hxx>
#include <BOPDS_Iterator.hxx> #include <BOPDS_Iterator.hxx>
@@ -168,11 +168,11 @@ class BOPAlgo_FaceFace :
typedef BOPCol_NCVector typedef BOPCol_NCVector
<BOPAlgo_FaceFace> BOPAlgo_VectorOfFaceFace; <BOPAlgo_FaceFace> BOPAlgo_VectorOfFaceFace;
// //
typedef BOPCol_TBBFunctor typedef BOPCol_Functor
<BOPAlgo_FaceFace, <BOPAlgo_FaceFace,
BOPAlgo_VectorOfFaceFace> BOPAlgo_FaceFaceFunctor; BOPAlgo_VectorOfFaceFace> BOPAlgo_FaceFaceFunctor;
// //
typedef BOPCol_TBBCnt typedef BOPCol_Cnt
<BOPAlgo_FaceFaceFunctor, <BOPAlgo_FaceFaceFunctor,
BOPAlgo_VectorOfFaceFace> BOPAlgo_FaceFaceCnt; BOPAlgo_VectorOfFaceFace> BOPAlgo_FaceFaceCnt;
///////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////

View File

@@ -41,7 +41,7 @@
#include <Geom2d_Curve.hxx> #include <Geom2d_Curve.hxx>
#include <BOPCol_NCVector.hxx> #include <BOPCol_NCVector.hxx>
#include <BOPCol_TBB.hxx> #include <BOPCol_Parallel.hxx>
#include <BOPCol_MapOfShape.hxx> #include <BOPCol_MapOfShape.hxx>
#include <BOPDS_VectorOfListOfPaveBlock.hxx> #include <BOPDS_VectorOfListOfPaveBlock.hxx>
@@ -153,11 +153,11 @@ class BOPAlgo_SplitEdge : public BOPAlgo_Algo {
typedef BOPCol_NCVector typedef BOPCol_NCVector
<BOPAlgo_SplitEdge> BOPAlgo_VectorOfSplitEdge; <BOPAlgo_SplitEdge> BOPAlgo_VectorOfSplitEdge;
// //
typedef BOPCol_TBBFunctor typedef BOPCol_Functor
<BOPAlgo_SplitEdge, <BOPAlgo_SplitEdge,
BOPAlgo_VectorOfSplitEdge> BOPAlgo_SplitEdgeFunctor; BOPAlgo_VectorOfSplitEdge> BOPAlgo_SplitEdgeFunctor;
// //
typedef BOPCol_TBBCnt typedef BOPCol_Cnt
<BOPAlgo_SplitEdgeFunctor, <BOPAlgo_SplitEdgeFunctor,
BOPAlgo_VectorOfSplitEdge> BOPAlgo_SplitEdgeCnt; BOPAlgo_VectorOfSplitEdge> BOPAlgo_SplitEdgeCnt;
// //
@@ -220,11 +220,11 @@ class BOPAlgo_MPC : public BOPAlgo_Algo {
typedef BOPCol_NCVector typedef BOPCol_NCVector
<BOPAlgo_MPC> BOPAlgo_VectorOfMPC; <BOPAlgo_MPC> BOPAlgo_VectorOfMPC;
// //
typedef BOPCol_TBBFunctor typedef BOPCol_Functor
<BOPAlgo_MPC, <BOPAlgo_MPC,
BOPAlgo_VectorOfMPC> BOPAlgo_MPCFunctor; BOPAlgo_VectorOfMPC> BOPAlgo_MPCFunctor;
// //
typedef BOPCol_TBBCnt typedef BOPCol_Cnt
<BOPAlgo_MPCFunctor, <BOPAlgo_MPCFunctor,
BOPAlgo_VectorOfMPC> BOPAlgo_MPCCnt; BOPAlgo_VectorOfMPC> BOPAlgo_MPCCnt;
// //
@@ -260,11 +260,11 @@ class BOPAlgo_BPC {
typedef BOPCol_NCVector typedef BOPCol_NCVector
<BOPAlgo_BPC> BOPAlgo_VectorOfBPC; <BOPAlgo_BPC> BOPAlgo_VectorOfBPC;
// //
typedef BOPCol_TBBFunctor typedef BOPCol_Functor
<BOPAlgo_BPC, <BOPAlgo_BPC,
BOPAlgo_VectorOfBPC> BOPAlgo_BPCFunctor; BOPAlgo_VectorOfBPC> BOPAlgo_BPCFunctor;
// //
typedef BOPCol_TBBCnt typedef BOPCol_Cnt
<BOPAlgo_BPCFunctor, <BOPAlgo_BPCFunctor,
BOPAlgo_VectorOfBPC> BOPAlgo_BPCCnt; BOPAlgo_VectorOfBPC> BOPAlgo_BPCCnt;
// //

View File

@@ -21,7 +21,7 @@
#include <BOPCol_NCVector.hxx> #include <BOPCol_NCVector.hxx>
#include <BOPCol_MapOfInteger.hxx> #include <BOPCol_MapOfInteger.hxx>
#include <BOPCol_TBB.hxx> #include <BOPCol_Parallel.hxx>
#include <BOPDS_ShapeInfo.hxx> #include <BOPDS_ShapeInfo.hxx>
#include <BOPDS_PaveBlock.hxx> #include <BOPDS_PaveBlock.hxx>
@@ -75,13 +75,13 @@ class BOPAlgo_ShrunkRange : public IntTools_ShrunkRange {
typedef BOPCol_NCVector typedef BOPCol_NCVector
<BOPAlgo_ShrunkRange> BOPAlgo_VectorOfShrunkRange; <BOPAlgo_ShrunkRange> BOPAlgo_VectorOfShrunkRange;
// //
typedef BOPCol_TBBContextFunctor typedef BOPCol_ContextFunctor
<BOPAlgo_ShrunkRange, <BOPAlgo_ShrunkRange,
BOPAlgo_VectorOfShrunkRange, BOPAlgo_VectorOfShrunkRange,
Handle(IntTools_Context), Handle(IntTools_Context),
IntTools_Context> BOPAlgo_ShrunkRangeFunctor; IntTools_Context> BOPAlgo_ShrunkRangeFunctor;
// //
typedef BOPCol_TBBContextCnt typedef BOPCol_ContextCnt
<BOPAlgo_ShrunkRangeFunctor, <BOPAlgo_ShrunkRangeFunctor,
BOPAlgo_VectorOfShrunkRange, BOPAlgo_VectorOfShrunkRange,
Handle(IntTools_Context)> BOPAlgo_ShrunkRangeCnt; Handle(IntTools_Context)> BOPAlgo_ShrunkRangeCnt;

View File

@@ -25,7 +25,7 @@
#include <BRep_Builder.hxx> #include <BRep_Builder.hxx>
#include <TopExp_Explorer.hxx> #include <TopExp_Explorer.hxx>
// //
#include <BOPCol_TBB.hxx> #include <BOPCol_Parallel.hxx>
#include <BOPCol_IndexedMapOfShape.hxx> #include <BOPCol_IndexedMapOfShape.hxx>
#include <BOPCol_MapOfShape.hxx> #include <BOPCol_MapOfShape.hxx>
#include <BOPCol_MapOfOrientedShape.hxx> #include <BOPCol_MapOfOrientedShape.hxx>
@@ -77,11 +77,11 @@ class BOPAlgo_CBK {
typedef BOPCol_NCVector typedef BOPCol_NCVector
<BOPAlgo_CBK> BOPAlgo_VectorOfCBK; <BOPAlgo_CBK> BOPAlgo_VectorOfCBK;
// //
typedef BOPCol_TBBFunctor typedef BOPCol_Functor
<BOPAlgo_CBK, <BOPAlgo_CBK,
BOPAlgo_VectorOfCBK> BOPAlgo_CBKFunctor; BOPAlgo_VectorOfCBK> BOPAlgo_CBKFunctor;
// //
typedef BOPCol_TBBCnt typedef BOPCol_Cnt
<BOPAlgo_CBKFunctor, <BOPAlgo_CBKFunctor,
BOPAlgo_VectorOfCBK> BOPAlgo_CBKCnt; BOPAlgo_VectorOfCBK> BOPAlgo_CBKCnt;
// //

View File

@@ -28,7 +28,7 @@
#include <BOPCol_IndexedMapOfShape.hxx> #include <BOPCol_IndexedMapOfShape.hxx>
#include <BOPCol_MapOfShape.hxx> #include <BOPCol_MapOfShape.hxx>
#include <BOPCol_IndexedDataMapOfShapeListOfShape.hxx> #include <BOPCol_IndexedDataMapOfShapeListOfShape.hxx>
#include <BOPCol_TBB.hxx> #include <BOPCol_Parallel.hxx>
#include <BOPCol_NCVector.hxx> #include <BOPCol_NCVector.hxx>
#include <BOPTools.hxx> #include <BOPTools.hxx>
@@ -262,56 +262,47 @@ typedef BOPCol_NCVector<BOPTools_ConnexityBlock> \
//class : WireSplitterFunctor //class : WireSplitterFunctor
//purpose : //purpose :
//======================================================================= //=======================================================================
class BOPAlgo_WireSplitterFunctor { class BOPAlgo_WireSplitterFunctor
protected: {
protected:
TopoDS_Face myFace; TopoDS_Face myFace;
BOPTools_VectorOfConnexityBlock* myPVCB; BOPTools_VectorOfConnexityBlock* myPVCB;
//
public: public:
// //
BOPAlgo_WireSplitterFunctor(const TopoDS_Face& aF, BOPAlgo_WireSplitterFunctor(const TopoDS_Face& aF,
BOPTools_VectorOfConnexityBlock& aVCB) BOPTools_VectorOfConnexityBlock& aVCB)
: myFace(aF), myPVCB(&aVCB) { : myFace(aF), myPVCB(&aVCB)
{
} }
// //
void operator()( const flexible_range<Standard_Size>& aBR ) const{ void operator()( const Standard_Integer& theIndex ) const
Standard_Size i, iBeg, iEnd; {
// BOPTools_VectorOfConnexityBlock& aVCB = *myPVCB;
BOPTools_VectorOfConnexityBlock& aVCB=*myPVCB; BOPTools_ConnexityBlock& aCB = aVCB(theIndex);
// BOPAlgo_WireSplitter::SplitBlock(myFace, aCB);
iBeg=aBR.begin();
iEnd=aBR.end();
for(i=iBeg; i!=iEnd; ++i) {
BOPTools_ConnexityBlock& aCB=aVCB((Standard_Integer)i);
//
BOPAlgo_WireSplitter::SplitBlock(myFace, aCB);
}
} }
}; };
//======================================================================= //=======================================================================
//class : BOPAlgo_WireSplitterCnt //class : BOPAlgo_WireSplitterCnt
//purpose : //purpose :
//======================================================================= //=======================================================================
class BOPAlgo_WireSplitterCnt { class BOPAlgo_WireSplitterCnt
public: {
public:
//------------------------------- //-------------------------------
// Perform // Perform
Standard_EXPORT Standard_EXPORT
static void Perform(const Standard_Boolean bRunParallel, static void Perform(const Standard_Boolean bRunParallel,
const TopoDS_Face& aF, const TopoDS_Face& aF,
BOPTools_VectorOfConnexityBlock& aVCB) { BOPTools_VectorOfConnexityBlock& aVCB)
{
// //
BOPAlgo_WireSplitterFunctor aWSF(aF, aVCB); BOPAlgo_WireSplitterFunctor aWSF(aF, aVCB);
Standard_Size aNbVCB=aVCB.Extent(); Standard_Size aNbVCB = aVCB.Extent();
// //
if (bRunParallel) { OSD_Parallel::For(0, aNbVCB, aWSF, !bRunParallel);
flexible_for(flexible_range<Standard_Size>(0,aNbVCB), aWSF);
}
else {
aWSF.operator()(flexible_range<Standard_Size>(0,aNbVCB));
}
} }
//
}; };
//======================================================================= //=======================================================================
//function : MakeWires //function : MakeWires

View File

@@ -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 <Standard_Macro.hxx>
#include <Standard_NotImplemented.hxx>
#include <OSD_Parallel.hxx>
#include <NCollection_DataMap.hxx>
//
// 1. Implementation of Functors/Starters
//
// 1.1. Pure version
//
//=======================================================================
//class : BOPCol_Functor
//purpose :
//=======================================================================
template <class TypeSolver, class TypeSolverVector>
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 TypeFunctor, class TypeSolverVector>
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 TypeSolver, class TypeSolverVector,
class TypeContext, typename TN>
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<Standard_Address>(theKey), Upper);
}
static Standard_Boolean IsEqual(const Standard_ThreadId theKey1,
const Standard_ThreadId theKey2)
{
return theKey1 == theKey2;
}
};
typedef NCollection_DataMap<Standard_ThreadId, TypeContext, Hasher> 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 TypeFunctor, class TypeSolverVector, class TypeContext>
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

View File

@@ -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 <Standard_Macro.hxx>
#include <Standard_NotImplemented.hxx>
#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 <tbb/tbb.h>
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 Type> 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<typename Range, typename Body>
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 TypeSolver,
class TypeSolverVector> class BOPCol_TBBFunctor {
public:
BOPCol_TBBFunctor(TypeSolverVector& aV)
: myPV(&aV) {
}
//
~BOPCol_TBBFunctor() {
}
//
void operator()( const flexible_range<Standard_Integer>& 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 TypeFunctor,
class TypeSolverVector> 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<Standard_Integer>(0,aNb), aFunctor);
}
//
catch( captured_exception& ) {
Standard_NotImplemented::Raise("");
}
catch( ... ) {
Standard_NotImplemented::Raise("");
}
#else // not HAVE_TBB
flexible_for(flexible_range<Standard_Integer>(0,aNb), aFunctor);
#endif
}
else {
aFunctor.operator()(flexible_range<Standard_Integer>(0,aNb));
}
}
};
//
// 2.2. Context dependent version
//
//=======================================================================
//class : BOPCol_TBBContextFunctor
//purpose :
//=======================================================================
template <class TypeSolver,
class TypeSolverVector,
class TypeContext,
typename TN> class BOPCol_TBBContextFunctor {
public:
BOPCol_TBBContextFunctor(TypeSolverVector& aV)
: myPV(&aV) {
}
//
~BOPCol_TBBContextFunctor() {
}
//
void SetContext(TypeContext& aCtx) {
myContext=aCtx;
}
//
void operator()( const flexible_range<Standard_Integer>& 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 TypeFunctor,
class TypeSolverVector,
class TypeContext> 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<Standard_Integer>(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<Standard_Integer>(0,aNb), aFunctor);
#endif
}
else {
aFunctor.SetContext(aCtx);
aFunctor.operator()(flexible_range<Standard_Integer>(0,aNb));
}
}
};
#endif

View File

@@ -28,7 +28,7 @@ BOPCol_SequenceOfReal.hxx
BOPCol_DataMapOfIntegerShape.hxx BOPCol_DataMapOfIntegerShape.hxx
BOPCol_IndexedDataMapOfIntegerListOfInteger.hxx BOPCol_IndexedDataMapOfIntegerListOfInteger.hxx
BOPCol_IndexedDataMapOfShapeInteger.hxx BOPCol_IndexedDataMapOfShapeInteger.hxx
BOPCol_TBB.hxx BOPCol_Parallel.hxx
BOPCol_NCVector.hxx BOPCol_NCVector.hxx
BOPCol_BoxBndTree.hxx BOPCol_BoxBndTree.hxx

View File

@@ -25,7 +25,7 @@
#include <TopoDS_Shape.hxx> #include <TopoDS_Shape.hxx>
// //
#include <BOPCol_NCVector.hxx> #include <BOPCol_NCVector.hxx>
#include <BOPCol_TBB.hxx> #include <BOPCol_Parallel.hxx>
#include <BOPCol_BoxBndTree.hxx> #include <BOPCol_BoxBndTree.hxx>
// //
#include <BOPDS_IndexRange.hxx> #include <BOPDS_IndexRange.hxx>
@@ -70,8 +70,8 @@ class BOPDS_TSR : public BOPCol_BoxBndTreeSelector{
// //
//======================================================================= //=======================================================================
typedef BOPCol_NCVector <BOPDS_TSR> BOPDS_VectorOfTSR; typedef BOPCol_NCVector <BOPDS_TSR> BOPDS_VectorOfTSR;
typedef BOPCol_TBBFunctor <BOPDS_TSR,BOPDS_VectorOfTSR> BOPDS_TSRFunctor; typedef BOPCol_Functor <BOPDS_TSR,BOPDS_VectorOfTSR> BOPDS_TSRFunctor;
typedef BOPCol_TBBCnt <BOPDS_TSRFunctor, BOPDS_VectorOfTSR> BOPDS_TSRCnt; typedef BOPCol_Cnt <BOPDS_TSRFunctor, BOPDS_VectorOfTSR> BOPDS_TSRCnt;
///////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////

View File

@@ -41,10 +41,9 @@
#include <BOPAlgo_CheckerSI.hxx> #include <BOPAlgo_CheckerSI.hxx>
#include <BOPAlgo_ArgumentAnalyzer.hxx> #include <BOPAlgo_ArgumentAnalyzer.hxx>
#include <BOPAlgo_CheckResult.hxx> #include <BOPAlgo_CheckResult.hxx>
#include <BOPTools_AlgoTools.hxx> #include <BOPTools_AlgoTools.hxx>
#include <BOPTest_Chronometer.hxx> #include <OSD_Timer.hxx>
#include <BOPTest_Objects.hxx> #include <BOPTest_Objects.hxx>
// //
@@ -204,7 +203,7 @@ Standard_Integer bopcheck (Draw_Interpretor& di,
if (!strcmp(a[i], "-t")) { if (!strcmp(a[i], "-t")) {
bShowTime=Standard_True; bShowTime=Standard_True;
} }
} }
// //
//aLevel = (n==3) ? Draw::Atoi(a[2]) : aNbInterfTypes-1; //aLevel = (n==3) ? Draw::Atoi(a[2]) : aNbInterfTypes-1;
//------------------------------------------------------------------- //-------------------------------------------------------------------
@@ -218,7 +217,6 @@ Standard_Integer bopcheck (Draw_Interpretor& di,
BOPAlgo_CheckerSI aChecker; BOPAlgo_CheckerSI aChecker;
BOPCol_ListOfShape aLS; BOPCol_ListOfShape aLS;
BOPDS_MapIteratorMapOfPassKey aItMPK; BOPDS_MapIteratorMapOfPassKey aItMPK;
BOPTest_Chronometer aChrono;
// //
if (aLevel < (aNbInterfTypes-1)) { if (aLevel < (aNbInterfTypes-1)) {
di << "Info:\nThe level of check is set to " di << "Info:\nThe level of check is set to "
@@ -239,11 +237,13 @@ Standard_Integer bopcheck (Draw_Interpretor& di,
aChecker.SetRunParallel(bRunParallel); aChecker.SetRunParallel(bRunParallel);
aChecker.SetFuzzyValue(aTol); aChecker.SetFuzzyValue(aTol);
// //
aChrono.Start(); OSD_Timer aTimer;
aTimer.Start();
// //
aChecker.Perform(); aChecker.Perform();
// //
aChrono.Stop(); aTimer.Stop();
aTimer.Show();
// //
iErr=aChecker.ErrorStatus(); iErr=aChecker.ErrorStatus();
// //
@@ -316,11 +316,9 @@ Standard_Integer bopcheck (Draw_Interpretor& di,
if (!iCnt) { if (!iCnt) {
di << " This shape seems to be OK." << "\n"; di << " This shape seems to be OK." << "\n";
} }
if (bShowTime) { if (bShowTime)
Standard_Real aTime; {
// Sprintf(buf, " Tps: %7.2lf\n", aTimer.ElapsedTime());
aTime=aChrono.Time();
Sprintf(buf, " Tps: %7.2lf\n", aTime);
di << buf; di << buf;
} }
return 0; return 0;

View File

@@ -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 <OSD_Timer.hxx>
//=======================================================================
//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

View File

@@ -35,7 +35,7 @@
#include <BOPTest_DrawableShape.hxx> #include <BOPTest_DrawableShape.hxx>
#include <BOPTest_Objects.hxx> #include <BOPTest_Objects.hxx>
#include <BOPTest_Chronometer.hxx> #include <OSD_Timer.hxx>
static Standard_Integer bfillds (Draw_Interpretor&, Standard_Integer, const char**); static Standard_Integer bfillds (Draw_Interpretor&, Standard_Integer, const char**);
static Standard_Integer bbuild (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; Standard_Real aTol;
BOPCol_ListIteratorOfListOfShape aIt; BOPCol_ListIteratorOfListOfShape aIt;
BOPCol_ListOfShape aLC; BOPCol_ListOfShape aLC;
BOPTest_Chronometer aChrono;
BOPCol_ListOfShape& aLS=BOPTest_Objects::Shapes(); BOPCol_ListOfShape& aLS=BOPTest_Objects::Shapes();
aNbS=aLS.Extent(); aNbS=aLS.Extent();
if (!aNbS) { if (!aNbS) {
@@ -94,7 +92,7 @@ Standard_Integer bfillds(Draw_Interpretor& di,
if (!strcmp(a[i], "-t")) { if (!strcmp(a[i], "-t")) {
bShowTime=Standard_True; bShowTime=Standard_True;
} }
} }
// //
BOPCol_ListOfShape& aLT=BOPTest_Objects::Tools(); BOPCol_ListOfShape& aLT=BOPTest_Objects::Tools();
// //
@@ -107,7 +105,7 @@ Standard_Integer bfillds(Draw_Interpretor& di,
aIt.Initialize(aLT); aIt.Initialize(aLT);
for (; aIt.More(); aIt.Next()) { for (; aIt.More(); aIt.Next()) {
const TopoDS_Shape& aS=aIt.Value(); const TopoDS_Shape& aS=aIt.Value();
aLC.Append(aS); aLC.Append(aS);
} }
// //
BOPAlgo_PaveFiller& aPF=BOPTest_Objects::PaveFiller(); BOPAlgo_PaveFiller& aPF=BOPTest_Objects::PaveFiller();
@@ -116,7 +114,8 @@ Standard_Integer bfillds(Draw_Interpretor& di,
aPF.SetRunParallel(bRunParallel); aPF.SetRunParallel(bRunParallel);
aPF.SetFuzzyValue(aTol); aPF.SetFuzzyValue(aTol);
// //
aChrono.Start(); OSD_Timer aTimer;
aTimer.Start();
// //
aPF.Perform(); aPF.Perform();
iErr=aPF.ErrorStatus(); iErr=aPF.ErrorStatus();
@@ -126,13 +125,12 @@ Standard_Integer bfillds(Draw_Interpretor& di,
return 0; return 0;
} }
// //
aChrono.Stop(); aTimer.Stop();
aTimer.Show();
// //
if (bShowTime) { if (bShowTime)
Standard_Real aTime; {
// Sprintf(buf, " Tps: %7.2lf\n", aTimer.ElapsedTime());
aTime=aChrono.Time();
Sprintf(buf, " Tps: %7.2lf\n", aTime);
di << buf; di << buf;
} }
// //
@@ -161,7 +159,6 @@ Standard_Integer bbuild(Draw_Interpretor& di,
Standard_Boolean bRunParallel, bShowTime; Standard_Boolean bRunParallel, bShowTime;
Standard_Integer i, iErr; Standard_Integer i, iErr;
BOPTest_Chronometer aChrono;
BOPCol_ListIteratorOfListOfShape aIt; BOPCol_ListIteratorOfListOfShape aIt;
// //
BOPAlgo_PaveFiller& aPF=BOPTest_Objects::PaveFiller(); BOPAlgo_PaveFiller& aPF=BOPTest_Objects::PaveFiller();
@@ -193,7 +190,8 @@ Standard_Integer bbuild(Draw_Interpretor& di,
aBuilder.SetRunParallel(bRunParallel); aBuilder.SetRunParallel(bRunParallel);
// //
// //
aChrono.Start(); OSD_Timer aTimer;
aTimer.Start();
// //
aBuilder.PerformWithFiller(aPF); aBuilder.PerformWithFiller(aPF);
iErr=aBuilder.ErrorStatus(); iErr=aBuilder.ErrorStatus();
@@ -203,13 +201,12 @@ Standard_Integer bbuild(Draw_Interpretor& di,
return 0; return 0;
} }
// //
aChrono.Stop(); aTimer.Stop();
aTimer.Show();
// //
if (bShowTime) { if (bShowTime)
Standard_Real aTime; {
// Sprintf(buf, " Tps: %7.2lf\n", aTimer.ElapsedTime());
aTime=aChrono.Time();
Sprintf(buf, " Tps: %7.2lf\n", aTime);
di << buf; di << buf;
} }
// //
@@ -246,7 +243,6 @@ Standard_Integer bbop(Draw_Interpretor& di,
Standard_Integer iErr, iOp, i; Standard_Integer iErr, iOp, i;
BOPAlgo_Operation aOp; BOPAlgo_Operation aOp;
BOPCol_ListIteratorOfListOfShape aIt; BOPCol_ListIteratorOfListOfShape aIt;
BOPTest_Chronometer aChrono;
// //
iOp=Draw::Atoi(a[2]); iOp=Draw::Atoi(a[2]);
if (iOp<0 || iOp>4) { if (iOp<0 || iOp>4) {
@@ -306,7 +302,8 @@ Standard_Integer bbop(Draw_Interpretor& di,
// //
pBuilder->SetRunParallel(bRunParallel); pBuilder->SetRunParallel(bRunParallel);
// //
aChrono.Start(); OSD_Timer aTimer;
aTimer.Start();
// //
pBuilder->PerformWithFiller(aPF); pBuilder->PerformWithFiller(aPF);
iErr=pBuilder->ErrorStatus(); iErr=pBuilder->ErrorStatus();
@@ -316,13 +313,11 @@ Standard_Integer bbop(Draw_Interpretor& di,
return 0; return 0;
} }
// //
aChrono.Stop(); aTimer.Stop();
aTimer.Show();
// //
if (bShowTime) { if (bShowTime) {
Standard_Real aTime; Sprintf(buf, " Tps: %7.2lf\n", aTimer.ElapsedTime());
//
aTime=aChrono.Time();
Sprintf(buf, " Tps: %7.2lf\n", aTime);
di << buf; di << buf;
} }
// //

View File

@@ -6,4 +6,3 @@ BOPTest_TolerCommands.cxx
BOPTest_ObjCommands.cxx BOPTest_ObjCommands.cxx
BOPTest_APICommands.cxx BOPTest_APICommands.cxx
BOPTest_OptionCommands.cxx BOPTest_OptionCommands.cxx
BOPTest_Chronometer.hxx

View File

@@ -80,7 +80,7 @@
#include <IntTools_Tools.hxx> #include <IntTools_Tools.hxx>
// //
#include <BOPCol_NCVector.hxx> #include <BOPCol_NCVector.hxx>
#include <BOPCol_TBB.hxx> #include <BOPCol_Parallel.hxx>
#include <BRepLib_CheckCurveOnSurface.hxx> #include <BRepLib_CheckCurveOnSurface.hxx>
static static
@@ -158,11 +158,11 @@ class BOPTools_CPC {
//======================================================================= //=======================================================================
typedef BOPCol_NCVector<BOPTools_CPC> BOPTools_VectorOfCPC; typedef BOPCol_NCVector<BOPTools_CPC> BOPTools_VectorOfCPC;
// //
typedef BOPCol_TBBFunctor typedef BOPCol_Functor
<BOPTools_CPC, <BOPTools_CPC,
BOPTools_VectorOfCPC> BOPTools_CPCFunctor; BOPTools_VectorOfCPC> BOPTools_CPCFunctor;
// //
typedef BOPCol_TBBCnt typedef BOPCol_Cnt
<BOPTools_CPCFunctor, <BOPTools_CPCFunctor,
BOPTools_VectorOfCPC> BOPTools_CPCCnt; BOPTools_VectorOfCPC> BOPTools_CPCCnt;
// //
@@ -192,11 +192,11 @@ class BOPTools_CWT {
//======================================================================= //=======================================================================
typedef BOPCol_NCVector<BOPTools_CWT> BOPTools_VectorOfCWT; typedef BOPCol_NCVector<BOPTools_CWT> BOPTools_VectorOfCWT;
// //
typedef BOPCol_TBBFunctor typedef BOPCol_Functor
<BOPTools_CWT, <BOPTools_CWT,
BOPTools_VectorOfCWT> BOPTools_CWTFunctor; BOPTools_VectorOfCWT> BOPTools_CWTFunctor;
// //
typedef BOPCol_TBBCnt typedef BOPCol_Cnt
<BOPTools_CWTFunctor, <BOPTools_CWTFunctor,
BOPTools_VectorOfCWT> BOPTools_CWTCnt; BOPTools_VectorOfCWT> BOPTools_CWTCnt;
// //
@@ -237,11 +237,11 @@ class BOPTools_CDT {
//======================================================================= //=======================================================================
typedef BOPCol_NCVector<BOPTools_CDT> BOPTools_VectorOfCDT; typedef BOPCol_NCVector<BOPTools_CDT> BOPTools_VectorOfCDT;
// //
typedef BOPCol_TBBFunctor typedef BOPCol_Functor
<BOPTools_CDT, <BOPTools_CDT,
BOPTools_VectorOfCDT> BOPTools_CDTFunctor; BOPTools_VectorOfCDT> BOPTools_CDTFunctor;
// //
typedef BOPCol_TBBCnt typedef BOPCol_Cnt
<BOPTools_CDTFunctor, <BOPTools_CDTFunctor,
BOPTools_VectorOfCDT> BOPTools_CDTCnt; BOPTools_VectorOfCDT> BOPTools_CDTCnt;
// //
@@ -272,11 +272,11 @@ class BOPTools_CVT {
//======================================================================= //=======================================================================
typedef BOPCol_NCVector<BOPTools_CVT> BOPTools_VectorOfCVT; typedef BOPCol_NCVector<BOPTools_CVT> BOPTools_VectorOfCVT;
// //
typedef BOPCol_TBBFunctor typedef BOPCol_Functor
<BOPTools_CVT, <BOPTools_CVT,
BOPTools_VectorOfCVT> BOPTools_CVTFunctor; BOPTools_VectorOfCVT> BOPTools_CVTFunctor;
// //
typedef BOPCol_TBBCnt typedef BOPCol_Cnt
<BOPTools_CVTFunctor, <BOPTools_CVTFunctor,
BOPTools_VectorOfCVT> BOPTools_CVTCnt; BOPTools_VectorOfCVT> BOPTools_CVTCnt;
// //
@@ -306,17 +306,17 @@ class BOPTools_CET {
//======================================================================= //=======================================================================
typedef BOPCol_NCVector<BOPTools_CET> BOPTools_VectorOfCET; typedef BOPCol_NCVector<BOPTools_CET> BOPTools_VectorOfCET;
// //
typedef BOPCol_TBBFunctor typedef BOPCol_Functor
<BOPTools_CET, <BOPTools_CET,
BOPTools_VectorOfCET> BOPTools_CETFunctor; BOPTools_VectorOfCET> BOPTools_CETFunctor;
// //
typedef BOPCol_TBBCnt typedef BOPCol_Cnt
<BOPTools_CETFunctor, <BOPTools_CETFunctor,
BOPTools_VectorOfCET> BOPTools_CETCnt; BOPTools_VectorOfCET> BOPTools_CETCnt;
// //
// //
//======================================================================= //=======================================================================
// //
//======================================================================= //=======================================================================
// Function : CorrectTolerances // Function : CorrectTolerances
// purpose : // purpose :
@@ -1063,6 +1063,6 @@ Standard_Boolean BOPTools_AlgoTools::ComputeTolerance
// //
theMaxDist = aCS.MaxDistance(); theMaxDist = aCS.MaxDistance();
theMaxPar = aCS.MaxParameter(); theMaxPar = aCS.MaxParameter();
// //
return Standard_True; return Standard_True;
} }

View File

@@ -62,6 +62,8 @@
#include <TopExp.hxx> #include <TopExp.hxx>
#include <TopExp_Explorer.hxx> #include <TopExp_Explorer.hxx>
#include <OSD_Parallel.hxx>
#include <Standard_ErrorHandler.hxx> #include <Standard_ErrorHandler.hxx>
#include <Standard_Failure.hxx> #include <Standard_Failure.hxx>
#include <NCollection_IncAllocator.hxx> #include <NCollection_IncAllocator.hxx>
@@ -71,11 +73,6 @@
#include <vector> #include <vector>
#ifdef HAVE_TBB
// paralleling using Intel TBB
#include <tbb/parallel_for_each.h>
#endif
#define UVDEFLECTION 1.e-05 #define UVDEFLECTION 1.e-05
IMPLEMENT_STANDARD_HANDLE (BRepMesh_FastDiscret, Standard_Transient) IMPLEMENT_STANDARD_HANDLE (BRepMesh_FastDiscret, Standard_Transient)
@@ -176,20 +173,7 @@ void BRepMesh_FastDiscret::Perform(const TopoDS_Shape& theShape)
aFaces.push_back(aFace); aFaces.push_back(aFace);
} }
#ifdef HAVE_TBB OSD_Parallel::ForEach(aFaces.begin(), aFaces.end(), *this, !myInParallel);
if ( myInParallel )
{
tbb::parallel_for_each(aFaces.begin(), aFaces.end(), *this);
}
else
{
#endif
std::vector<TopoDS_Face>::const_iterator anIt(aFaces.begin());
for (; anIt != aFaces.end(); anIt++)
Process(*anIt);
#ifdef HAVE_TBB
}
#endif
} }

View File

@@ -16,6 +16,7 @@
#include <BRepMesh_IncrementalMesh.hxx> #include <BRepMesh_IncrementalMesh.hxx>
#include <OSD_Parallel.hxx>
#include <Precision.hxx> #include <Precision.hxx>
#include <Standard_ErrorHandler.hxx> #include <Standard_ErrorHandler.hxx>
@@ -52,11 +53,6 @@
#include <GCPnts_TangentialDeflection.hxx> #include <GCPnts_TangentialDeflection.hxx>
#ifdef HAVE_TBB
// paralleling using Intel TBB
#include <tbb/parallel_for_each.h>
#endif
namespace namespace
{ {
//! Default flag to control parallelization for BRepMesh_IncrementalMesh //! Default flag to control parallelization for BRepMesh_IncrementalMesh
@@ -223,19 +219,7 @@ void BRepMesh_IncrementalMesh::update()
update(aFaceIt.Value()); update(aFaceIt.Value());
// Mesh faces // Mesh faces
#ifdef HAVE_TBB OSD_Parallel::ForEach(myFaces.begin(), myFaces.end(), *myMesh, !myInParallel);
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
commit(); commit();
clear(); clear();
@@ -577,12 +561,7 @@ Standard_Integer BRepMesh_IncrementalMesh::Discret(
//======================================================================= //=======================================================================
Standard_Boolean BRepMesh_IncrementalMesh::IsParallelDefault() Standard_Boolean BRepMesh_IncrementalMesh::IsParallelDefault()
{ {
#ifdef HAVE_TBB
return IS_IN_PARALLEL; return IS_IN_PARALLEL;
#else
// no alternative parallelization yet - flag has no meaning
return Standard_False;
#endif
} }
//======================================================================= //=======================================================================

View File

@@ -30,12 +30,8 @@
#include <BRepMesh_DataStructureOfDelaun.hxx> #include <BRepMesh_DataStructureOfDelaun.hxx>
#include <BRepMesh_Classifier.hxx> #include <BRepMesh_Classifier.hxx>
#include <BRepMesh_WireInterferenceChecker.hxx> #include <BRepMesh_WireInterferenceChecker.hxx>
#include <OSD_Parallel.hxx>
#ifdef HAVE_TBB
// paralleling using Intel TBB
#include <tbb/parallel_for.h>
#include <tbb/blocked_range.h>
#endif
//======================================================================= //=======================================================================
//function : Selector::Constructor //function : Selector::Constructor
@@ -196,27 +192,18 @@ void BRepMesh_WireChecker::ReCompute(BRepMesh::HClassifier& theClassifier)
BRepMesh::Array1OfSegmentsTree aWiresBiPoints(1, aNbWires); BRepMesh::Array1OfSegmentsTree aWiresBiPoints(1, aNbWires);
fillSegmentsTree(aDWires, aWiresBiPoints); fillSegmentsTree(aDWires, aWiresBiPoints);
#ifdef HAVE_TBB
Standard_Mutex aWireMutex;
BRepMesh_WireInterferenceChecker aIntChecker(aWiresBiPoints,
&myStatus, &aWireMutex);
if (myIsInParallel && aNbWires > 1) if (myIsInParallel && aNbWires > 1)
{ {
// check wires in parallel threads using TBB // Check wires in parallel threads.
tbb::parallel_for(tbb::blocked_range<Standard_Integer>(1, aNbWires + 1), Standard_Mutex aWireMutex;
aIntChecker); BRepMesh_WireInterferenceChecker aIntChecker(aWiresBiPoints, &myStatus, &aWireMutex);
OSD_Parallel::For(1, aNbWires + 1, aIntChecker);
} }
else else
{ {
#else
BRepMesh_WireInterferenceChecker aIntChecker(aWiresBiPoints, &myStatus); BRepMesh_WireInterferenceChecker aIntChecker(aWiresBiPoints, &myStatus);
#endif OSD_Parallel::For(1, aNbWires + 1, aIntChecker, Standard_True);
for (Standard_Integer i = 1; i <= aNbWires; ++i)
aIntChecker(i);
#ifdef HAVE_TBB
} }
#endif
if (myStatus == BRepMesh_SelfIntersectingWire) if (myStatus == BRepMesh_SelfIntersectingWire)
return; return;

View File

@@ -20,7 +20,6 @@
// TODO: remove this variable after implementation of LoopChecker2d. // TODO: remove this variable after implementation of LoopChecker2d.
static const Standard_Real MIN_LOOP_S = 2 * M_PI * 2.E-5; static const Standard_Real MIN_LOOP_S = 2 * M_PI * 2.E-5;
#ifdef HAVE_TBB
//======================================================================= //=======================================================================
//function : Constructor //function : Constructor
//purpose : //purpose :
@@ -35,30 +34,6 @@ BRepMesh_WireInterferenceChecker::BRepMesh_WireInterferenceChecker(
{ {
} }
//=======================================================================
//function : Checker's body
//purpose :
//=======================================================================
void BRepMesh_WireInterferenceChecker::operator ()(
const tbb::blocked_range<Standard_Integer>& 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 //function : Checker's body
//purpose : //purpose :
@@ -75,11 +50,9 @@ void BRepMesh_WireInterferenceChecker::operator ()(
for (Standard_Integer aWireIt = theWireId; aWireIt <= myWires.Upper(); ++aWireIt) 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) if (*myStatus == BRepMesh_SelfIntersectingWire)
return; return;
#endif
const Standard_Boolean isSelfIntCheck = (aWireIt == theWireId); const Standard_Boolean isSelfIntCheck = (aWireIt == theWireId);
const BRepMesh::SegmentsTree& aWireSegTree2 = const BRepMesh::SegmentsTree& aWireSegTree2 =
@@ -93,11 +66,9 @@ void BRepMesh_WireInterferenceChecker::operator ()(
Standard_Integer aSegmentId1 = aWireSegments1->Lower(); Standard_Integer aSegmentId1 = aWireSegments1->Lower();
for (; aSegmentId1 <= aWireSegments1->Upper(); ++aSegmentId1) for (; aSegmentId1 <= aWireSegments1->Upper(); ++aSegmentId1)
{ {
#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) if (*myStatus == BRepMesh_SelfIntersectingWire)
return; return;
#endif
aSelector.Clear(); aSelector.Clear();
aSelector.SetBox(aWireBoxTree1->FindNode(aSegmentId1).Bnd()); aSelector.SetBox(aWireBoxTree1->FindNode(aSegmentId1).Bnd());
@@ -112,11 +83,9 @@ void BRepMesh_WireInterferenceChecker::operator ()(
const Standard_Integer aSelectedNb = aSelector.IndicesNb(); const Standard_Integer aSelectedNb = aSelector.IndicesNb();
for (Standard_Integer aBndIt = 0; aBndIt < aSelectedNb; ++aBndIt) for (Standard_Integer aBndIt = 0; aBndIt < aSelectedNb; ++aBndIt)
{ {
#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) if (*myStatus == BRepMesh_SelfIntersectingWire)
return; return;
#endif
const Standard_Integer aSegmentId2 = aSelected(aBndIt); const Standard_Integer aSegmentId2 = aSelected(aBndIt);
const BRepMesh::Segment& aSegment2 = aWireSegments2->Value(aSegmentId2); const BRepMesh::Segment& aSegment2 = aWireSegments2->Value(aSegmentId2);
@@ -154,10 +123,9 @@ void BRepMesh_WireInterferenceChecker::operator ()(
continue; continue;
} }
#ifdef HAVE_TBB
Standard_Mutex::Sentry aSentry(myMutex); Standard_Mutex::Sentry aSentry(myMutex);
#endif
*myStatus = BRepMesh_SelfIntersectingWire; *myStatus = BRepMesh_SelfIntersectingWire;
return; return;
} }
} }

View File

@@ -21,11 +21,6 @@
#include <BRepMesh_WireChecker.hxx> #include <BRepMesh_WireChecker.hxx>
#include <BRepMesh_Status.hxx> #include <BRepMesh_Status.hxx>
#ifdef HAVE_TBB
// paralleling using Intel TBB
#include <tbb/blocked_range.h>
#endif
//! Auxilary class implementing functionality for //! Auxilary class implementing functionality for
//! checking interference between two discretized wires. //! checking interference between two discretized wires.
class BRepMesh_WireInterferenceChecker class BRepMesh_WireInterferenceChecker
@@ -43,7 +38,6 @@ public:
Same Same
}; };
#ifdef HAVE_TBB
//! Constructor //! Constructor
//! @param theWires wires that should be checked. //! @param theWires wires that should be checked.
//! @param theStatus shared flag to set status of the check. //! @param theStatus shared flag to set status of the check.
@@ -51,19 +45,7 @@ public:
BRepMesh_WireInterferenceChecker( BRepMesh_WireInterferenceChecker(
const BRepMesh::Array1OfSegmentsTree& theWires, const BRepMesh::Array1OfSegmentsTree& theWires,
BRepMesh_Status* theStatus, BRepMesh_Status* theStatus,
Standard_Mutex* theMutex); Standard_Mutex* theMutex = NULL);
//! Checker's body.
//! @param theWireRange range of wires to be checked.
void operator ()(const tbb::blocked_range<Standard_Integer>& 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
//! Checker's body. //! Checker's body.
//! @param theWireId Id of discretized wire to be checked. //! @param theWireId Id of discretized wire to be checked.
@@ -79,10 +61,7 @@ private:
private: private:
const BRepMesh::Array1OfSegmentsTree& myWires; const BRepMesh::Array1OfSegmentsTree& myWires;
BRepMesh_Status* myStatus; BRepMesh_Status* myStatus;
#ifdef HAVE_TBB
Standard_Mutex* myMutex; Standard_Mutex* myMutex;
#endif
}; };
#endif #endif

View File

@@ -83,7 +83,6 @@ void MeshTest::PluginCommands(Draw_Interpretor& theCommands)
__FILE__, mpparallel, g); __FILE__, mpparallel, g);
theCommands.Add("triarea","shape [eps] (computes triangles and surface area)",__FILE__, triarea, 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); theCommands.Add("tricheck", "shape (checks triangulation of shape)", __FILE__, tricheck, g);
} }
//======================================================================= //=======================================================================

View File

@@ -0,0 +1 @@
CSF_TBB

View File

@@ -17,5 +17,7 @@ OSD_MAllocHook.cxx
OSD_MAllocHook.hxx OSD_MAllocHook.hxx
OSD_MemInfo.hxx OSD_MemInfo.hxx
OSD_MemInfo.cxx OSD_MemInfo.cxx
OSD_Parallel.hxx
OSD_Parallel.cxx
OSD_OpenFile.hxx OSD_OpenFile.hxx
OSD_OpenFile.cxx OSD_OpenFile.cxx

93
src/OSD/OSD_Parallel.cxx Normal file
View File

@@ -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 <OSD_Parallel.hxx>
#ifdef _WIN32
#include <windows.h>
#include <process.h>
#else
#include <sys/types.h>
#ifdef __sun
#include <sys/processor.h>
#include <sys/procset.h>
#else
#include <sched.h>
#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;
}

298
src/OSD/OSD_Parallel.hxx Normal file
View File

@@ -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 <OSD_Thread.hxx>
#include <Standard_Mutex.hxx>
#include <Standard_NotImplemented.hxx>
#include <Standard_Atomic.hxx>
#include <NCollection_Array1.hxx>
#ifdef HAVE_TBB
#include <tbb/parallel_for.h>
#include <tbb/parallel_for_each.h>
#include <tbb/blocked_range.h>
#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 <typename Value>
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 <typename Functor, typename InputIterator>
class Task
{
public: //! @name public methods
//! Constructor.
Task(const Functor& thePerformer, Range<InputIterator>& 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<Functor, InputIterator>& aTask =
*( static_cast< Task<Functor, InputIterator>* >(theTask) );
const Range<InputIterator>& aData( aTask.myRange );
typename Range<InputIterator>::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<Functor, InputIterator>& aTask =
*( static_cast< Task<Functor, Standard_Integer>* >(theTask) );
const Range<Standard_Integer>& 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<InputIterator>& 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 <typename InputIterator, typename Functor>
static void ForEach( InputIterator theBegin,
InputIterator theEnd,
const Functor& theFunctor,
const Standard_Boolean isForceSingleThreadExecution
= Standard_False );
//! Simple primitive for parallelization of "for" loops.
template <typename Functor>
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<Standard_Integer>::It() const
{
return Standard_Atomic_Increment( reinterpret_cast<volatile int*>(&myIt) ) - 1;
}
//=======================================================================
//function : ParallelForEach
//purpose :
//=======================================================================
template <typename InputIterator, typename Functor>
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<InputIterator> aData(theBegin, theEnd);
Task<Functor, InputIterator> aTask(theFunctor, aData);
const Standard_Integer aNbThreads = OSD_Parallel::NbLogicalProcessors();
NCollection_Array1<OSD_Thread> aThreads(0, aNbThreads - 1);
for ( Standard_Integer i = 0; i < aNbThreads; ++i )
{
OSD_Thread& aThread = aThreads(i);
aThread.SetFunction(&Task<Functor, InputIterator>::RunWithIterator);
aThread.Run(&aTask);
}
for ( Standard_Integer i = 0; i < aNbThreads; ++i )
aThreads(i).Wait();
}
#endif
}
//=======================================================================
//function : ParallelFor
//purpose :
//=======================================================================
template <typename Functor>
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<Standard_Integer> aData(theBegin, theEnd);
Task<Functor, Standard_Integer> aTask(theFunctor, aData);
const Standard_Integer aNbThreads = OSD_Parallel::NbLogicalProcessors();
NCollection_Array1<OSD_Thread> aThreads(0, aNbThreads - 1);
for ( Standard_Integer i = 0; i < aNbThreads; ++i )
{
OSD_Thread& aThread = aThreads(i);
aThread.SetFunction(&Task<Functor, Standard_Integer>::RunWithIndex);
aThread.Run(&aTask);
}
for ( Standard_Integer i = 0; i < aNbThreads; ++i )
aThreads(i).Wait();
}
#endif
}
#endif

View File

@@ -13,17 +13,8 @@
// Alternatively, this file may be used under the terms of Open CASCADE // Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement. // commercial license or contractual agreement.
#ifdef HAVE_TBB #include <Standard_Assert.hxx>
// On Windows, function TryEnterCriticalSection has appeared in Windows NT #include <OSD_Parallel.hxx>
// 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 <tbb/tbb.h>
#endif
#include <OpenGl_SceneGeometry.hxx> #include <OpenGl_SceneGeometry.hxx>
@@ -208,8 +199,6 @@ void OpenGl_RaytraceGeometry::Clear()
Materials.swap (anEmptyMaterials); Materials.swap (anEmptyMaterials);
} }
#ifdef HAVE_TBB
struct OpenGL_BVHParallelBuilder struct OpenGL_BVHParallelBuilder
{ {
BVH_ObjectSet<Standard_ShortReal, 3>* Set; BVH_ObjectSet<Standard_ShortReal, 3>* Set;
@@ -220,23 +209,16 @@ struct OpenGL_BVHParallelBuilder
// //
} }
void operator() (const tbb::blocked_range<size_t>& theRange) const void operator() (const Standard_Integer theObjectIdx) const
{ {
for (size_t anObjectIdx = theRange.begin(); anObjectIdx != theRange.end(); ++anObjectIdx) OpenGl_TriangleSet* aTriangleSet = dynamic_cast<OpenGl_TriangleSet*> (
{ Set->Objects().ChangeValue (static_cast<Standard_Integer> (theObjectIdx)).operator->());
OpenGl_TriangleSet* aTriangleSet = dynamic_cast<OpenGl_TriangleSet*> (
Set->Objects().ChangeValue (static_cast<Standard_Integer> (anObjectIdx)).operator->());
if (aTriangleSet != NULL) if (aTriangleSet != NULL)
{ aTriangleSet->BVH();
aTriangleSet->BVH();
}
}
} }
}; };
#endif
// ======================================================================= // =======================================================================
// function : ProcessAcceleration // function : ProcessAcceleration
// purpose : Performs post-processing of high-level BVH // purpose : Performs post-processing of high-level BVH
@@ -254,12 +236,7 @@ Standard_Boolean OpenGl_RaytraceGeometry::ProcessAcceleration()
aTimer.Start(); aTimer.Start();
#endif #endif
#ifdef HAVE_TBB OSD_Parallel::For(0, Size(), OpenGL_BVHParallelBuilder(this));
// If Intel TBB is available, perform the preliminary
// construction of bottom-level scene BVHs
tbb::parallel_for (tbb::blocked_range<size_t> (0, Size()),
OpenGL_BVHParallelBuilder (this));
#endif
myBottomLevelTreeDepth = 0; myBottomLevelTreeDepth = 0;

View File

@@ -39,8 +39,9 @@
#include <cstdio> #include <cstdio>
#include <cmath> #include <cmath>
#include <iostream> #include <iostream>
#include <OSD_PerfMeter.hxx>
#include <OSD_Timer.hxx> #include <OSD_Timer.hxx>
#include <OSD_Parallel.hxx>
#include <OSD_PerfMeter.hxx>
#include <BRepPrimAPI_MakeBox.hxx> #include <BRepPrimAPI_MakeBox.hxx>
#include <BRepPrimAPI_MakeSphere.hxx> #include <BRepPrimAPI_MakeSphere.hxx>
#include <BRepAlgo_Cut.hxx> #include <BRepAlgo_Cut.hxx>
@@ -157,32 +158,23 @@ static Standard_Integer OCC23237 (Draw_Interpretor& di, Standard_Integer /*argc*
return 0; return 0;
} }
#ifdef HAVE_TBB
#include <tbb/blocked_range.h>
#include <tbb/parallel_for.h>
class IncrementerDecrementer class IncrementerDecrementer
{ {
public: public:
IncrementerDecrementer (Standard_Integer* theVal, Standard_Boolean thePositive) : myVal (theVal), myPositive (thePositive) IncrementerDecrementer (Standard_Integer* theVal, Standard_Boolean thePositive) : myVal (theVal), myPositive (thePositive)
{} {}
void operator() (const tbb::blocked_range<size_t>& r) const void operator() (const size_t) const
{ {
if (myPositive) if ( myPositive )
for (size_t i = r.begin(); i != r.end(); ++i) Standard_Atomic_Increment(myVal);
Standard_Atomic_Increment (myVal); else
else Standard_Atomic_Decrement(myVal);
for (size_t i = r.begin(); i != r.end(); ++i)
Standard_Atomic_Decrement (myVal);
} }
private: private:
Standard_Integer* myVal; 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*/) static Standard_Integer OCC22980 (Draw_Interpretor& di, Standard_Integer /*argc*/, const char ** /*argv*/)
{ {
int aSum = 0; 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 const int N = 1 << 24; //big enough to ensure concurrency
//increment //increment
tbb::parallel_for (tbb::blocked_range<size_t> (0, N), IncrementerDecrementer (&aSum, true)); OSD_Parallel::For(0, N, IncrementerDecrementer (&aSum, true));
QCOMPARE (aSum, N); QCOMPARE (aSum, N);
//decrement //decrement
tbb::parallel_for (tbb::blocked_range<size_t> (0, N), IncrementerDecrementer (&aSum, false)); OSD_Parallel::For(0, N, IncrementerDecrementer (&aSum, false));
QCOMPARE (aSum, 0); QCOMPARE (aSum, 0);
return 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 <TDocStd_Application.hxx> #include <TDocStd_Application.hxx>
#include <XCAFApp_Application.hxx> #include <XCAFApp_Application.hxx>
#include <TDocStd_Document.hxx> #include <TDocStd_Document.hxx>
@@ -2902,6 +2884,92 @@ static Standard_Integer OCC25340 (Draw_Interpretor& /*theDI*/,
return 0; return 0;
} }
//=======================================================================
//function : OCC24826
//purpose :
//=======================================================================
class ParallelTest_Saxpy
{
public:
typedef NCollection_Array1<Standard_Real> 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<Standard_Real> aX (0, aLength - 1);
NCollection_Array1<Standard_Real> 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 <GeomAPI_IntSS.hxx> #include <GeomAPI_IntSS.hxx>
@@ -3328,6 +3396,7 @@ void QABugs::Commands_19(Draw_Interpretor& theCommands) {
__FILE__, OCC24925, group); __FILE__, OCC24925, group);
theCommands.Add ("OCC23010", "OCC23010 STEP_file", __FILE__, OCC23010, group); theCommands.Add ("OCC23010", "OCC23010 STEP_file", __FILE__, OCC23010, group);
theCommands.Add ("OCC25043", "OCC25043 shape", __FILE__, OCC25043, 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 ("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 ("OCC25202", "OCC25202 res shape numF1 face1 numF2 face2", __FILE__, OCC25202, group);
theCommands.Add ("OCC7570", "OCC7570 shape", __FILE__, OCC7570, group); theCommands.Add ("OCC7570", "OCC7570 shape", __FILE__, OCC7570, group);

View File

@@ -26,20 +26,7 @@
#include <NCollection_IndexedDataMap.hxx> #include <NCollection_IndexedDataMap.hxx>
#include <Standard_Assert.hxx> #include <Standard_Assert.hxx>
#include <OSD_Timer.hxx> #include <OSD_Timer.hxx>
#include <OSD_Parallel.hxx>
#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 <tbb/tbb.h>
#include <tbb/parallel_for.h>
#endif
#include <algorithm> #include <algorithm>
#include <list> #include <list>
#include <set> #include <set>
@@ -343,8 +330,6 @@ Standard_Boolean TestSort()
return aResult; return aResult;
} }
#ifdef HAVE_TBB
template <typename T> template <typename T>
struct Invoker struct Invoker
{ {
@@ -355,19 +340,19 @@ struct Invoker
}; };
//======================================================================= //=======================================================================
//function : TestTBB //function : TestParallel
//purpose : //purpose :
//======================================================================= //=======================================================================
template<class CollectionType, class StlType> template<class CollectionType, class StlType>
Standard_Boolean TestTBB() Standard_Boolean TestParallel()
{ {
StlType* aVector (NULL); StlType* aVector (NULL);
CollectionType* aCollec (NULL); CollectionType* aCollec (NULL);
CollectionFiller<CollectionType, StlType>::Perform (&aVector, &aCollec); CollectionFiller<CollectionType, StlType>::Perform (&aVector, &aCollec);
tbb::parallel_for_each (aVector->begin(), aVector->end(), Invoker<typename StlType::value_type>()); OSD_Parallel::ForEach(aVector->begin(), aVector->end(), Invoker<typename StlType::value_type>());
tbb::parallel_for_each (aCollec->begin(), aCollec->end(), Invoker<typename CollectionType::value_type>()); OSD_Parallel::ForEach(aCollec->begin(), aCollec->end(), Invoker<typename CollectionType::value_type>());
typename StlType::iterator aVecIter = aVector->begin(); typename StlType::iterator aVecIter = aVector->begin();
typename CollectionType::iterator aColIter = aCollec->begin(); typename CollectionType::iterator aColIter = aCollec->begin();
@@ -392,18 +377,18 @@ Standard_Boolean TestTBB()
} }
//======================================================================= //=======================================================================
//function : TestDataMapTBB //function : TestDataMapParallel
//purpose : //purpose :
//======================================================================= //=======================================================================
template<class CollectionType, class T> template<class CollectionType, class T>
Standard_Boolean TestDataMapTBB() Standard_Boolean TestDataMapParallel()
{ {
CollectionType* aCollec1 (NULL); CollectionType* aCollec1 (NULL);
CollectionType* aCollec2 (NULL); CollectionType* aCollec2 (NULL);
MapFiller<CollectionType, T>::Perform (&aCollec1, &aCollec2); MapFiller<CollectionType, T>::Perform (&aCollec1, &aCollec2);
tbb::parallel_for_each (aCollec1->begin(), aCollec1->end(), Invoker<T>()); OSD_Parallel::ForEach(aCollec1->begin(), aCollec1->end(), Invoker<T>());
// create OCCT-style iterator // create OCCT-style iterator
typename CollectionType::Iterator aOccIter (*aCollec2); typename CollectionType::Iterator aOccIter (*aCollec2);
@@ -430,8 +415,6 @@ Standard_Boolean TestDataMapTBB()
return aResult; return aResult;
} }
#endif
//======================================================================= //=======================================================================
//function : TestMapIteration //function : TestMapIteration
//purpose : //purpose :
@@ -605,18 +588,14 @@ static Standard_Integer QANListStlIterator (Draw_Interpretor&, Standard_Integer,
std::cout << "NCollection_List<double> Replace: " << std::cout << "NCollection_List<double> Replace: " <<
(aResult ? "SUCCESS" : "FAIL") << std::endl; (aResult ? "SUCCESS" : "FAIL") << std::endl;
#ifdef HAVE_TBB aResult = TestParallel< NCollection_List<int>, std::list<int> >();
std::cout << "NCollection_List<int> Parallel: " <<
aResult = TestTBB<NCollection_List<int>, std::list<int> >();
std::cout << "NCollection_List<int> TBB: " <<
(aResult ? "SUCCESS" : "FAIL") << std::endl; (aResult ? "SUCCESS" : "FAIL") << std::endl;
aResult = TestTBB<NCollection_List<double>, std::list<double> >(); aResult = TestParallel<NCollection_List<double>, std::list<double> >();
std::cout << "NCollection_List<double> TBB: " << std::cout << "NCollection_List<double> Parallel: " <<
(aResult ? "SUCCESS" : "FAIL") << std::endl; (aResult ? "SUCCESS" : "FAIL") << std::endl;
#endif
return 0; return 0;
} }
@@ -682,18 +661,14 @@ static Standard_Integer QANDataMapStlIterator (Draw_Interpretor&, Standard_Integ
std::cout << "NCollection_DataMap<double> Iteration: " << std::cout << "NCollection_DataMap<double> Iteration: " <<
(aResult ? "SUCCESS" : "FAIL") << std::endl; (aResult ? "SUCCESS" : "FAIL") << std::endl;
#ifdef HAVE_TBB aResult = TestDataMapParallel<NCollection_DataMap<Standard_Integer, Standard_Integer>, Standard_Integer>();
std::cout << "NCollection_DataMap<int> Parallel: " <<
aResult = TestDataMapTBB<NCollection_DataMap<Standard_Integer, Standard_Integer>, Standard_Integer>();
std::cout << "NCollection_DataMap<int> TBB: " <<
(aResult ? "SUCCESS" : "FAIL") << std::endl; (aResult ? "SUCCESS" : "FAIL") << std::endl;
aResult = TestDataMapTBB<NCollection_DataMap<Standard_Real, Standard_Real>, Standard_Real>(); aResult = TestDataMapParallel<NCollection_DataMap<Standard_Real, Standard_Real>, Standard_Real>();
std::cout << "NCollection_DataMap<double> TBB: " << std::cout << "NCollection_DataMap<double> Parallel: " <<
(aResult ? "SUCCESS" : "FAIL") << std::endl; (aResult ? "SUCCESS" : "FAIL") << std::endl;
#endif
return 0; return 0;
} }
@@ -716,18 +691,14 @@ static Standard_Integer QANIndexedDataMapStlIterator (Draw_Interpretor&, Standar
std::cout << "NCollection_IndexedDataMap<double> Iteration: " << std::cout << "NCollection_IndexedDataMap<double> Iteration: " <<
(aResult ? "SUCCESS" : "FAIL") << std::endl; (aResult ? "SUCCESS" : "FAIL") << std::endl;
#ifdef HAVE_TBB aResult = TestDataMapParallel<NCollection_IndexedDataMap<Standard_Integer, Standard_Integer>, Standard_Integer>();
std::cout << "NCollection_IndexedDataMap<int> Parallel: " <<
aResult = TestDataMapTBB<NCollection_IndexedDataMap<Standard_Integer, Standard_Integer>, Standard_Integer>();
std::cout << "NCollection_IndexedDataMap<int> TBB: " <<
(aResult ? "SUCCESS" : "FAIL") << std::endl; (aResult ? "SUCCESS" : "FAIL") << std::endl;
aResult = TestDataMapTBB<NCollection_IndexedDataMap<Standard_Real, Standard_Real>, Standard_Real>(); aResult = TestDataMapParallel<NCollection_IndexedDataMap<Standard_Real, Standard_Real>, Standard_Real>();
std::cout << "NCollection_IndexedDataMap<double> TBB: " << std::cout << "NCollection_IndexedDataMap<double> Parallel: " <<
(aResult ? "SUCCESS" : "FAIL") << std::endl; (aResult ? "SUCCESS" : "FAIL") << std::endl;
#endif
return 0; return 0;
} }
@@ -774,18 +745,14 @@ static Standard_Integer QANSequenceStlIterator (Draw_Interpretor&, Standard_Inte
std::cout << "NCollection_Sequence<double> Reverse: " << std::cout << "NCollection_Sequence<double> Reverse: " <<
(aResult ? "SUCCESS" : "FAIL") << std::endl; (aResult ? "SUCCESS" : "FAIL") << std::endl;
#ifdef HAVE_TBB aResult = TestParallel<NCollection_Sequence<int>, std::list<int> >();
std::cout << "NCollection_Sequence<int> Parallel: " <<
aResult = TestTBB<NCollection_Sequence<int>, std::list<int> >();
std::cout << "NCollection_Sequence<int> TBB: " <<
(aResult ? "SUCCESS" : "FAIL") << std::endl; (aResult ? "SUCCESS" : "FAIL") << std::endl;
aResult = TestTBB<NCollection_Sequence<double>, std::list<double> >(); aResult = TestParallel<NCollection_Sequence<double>, std::list<double> >();
std::cout << "NCollection_Sequence<double> TBB: " << std::cout << "NCollection_Sequence<double> Parallel: " <<
(aResult ? "SUCCESS" : "FAIL") << std::endl; (aResult ? "SUCCESS" : "FAIL") << std::endl;
#endif
return 0; return 0;
} }
@@ -841,18 +808,14 @@ static Standard_Integer QANVectorStlIterator (Draw_Interpretor&, Standard_Intege
std::cout << "NCollection_Vector<double> Sort: " << std::cout << "NCollection_Vector<double> Sort: " <<
(aResult ? "SUCCESS" : "FAIL") << std::endl; (aResult ? "SUCCESS" : "FAIL") << std::endl;
#ifdef HAVE_TBB aResult = TestParallel<NCollection_Vector<int>, std::vector<int> >();
std::cout << "NCollection_Vector<int> Parallel: " <<
aResult = TestTBB<NCollection_Vector<int>, std::vector<int> >();
std::cout << "NCollection_Vector<int> TBB: " <<
(aResult ? "SUCCESS" : "FAIL") << std::endl; (aResult ? "SUCCESS" : "FAIL") << std::endl;
aResult = TestTBB<NCollection_Vector<double>, std::vector<double> >(); aResult = TestParallel<NCollection_Vector<double>, std::vector<double> >();
std::cout << "NCollection_Vector<double> TBB: " << std::cout << "NCollection_Vector<double> Parallel: " <<
(aResult ? "SUCCESS" : "FAIL") << std::endl; (aResult ? "SUCCESS" : "FAIL") << std::endl;
#endif
return 0; return 0;
} }
@@ -908,18 +871,14 @@ static Standard_Integer QANArray1StlIterator (Draw_Interpretor&, Standard_Intege
std::cout << "NCollection_Array1<double> Sort: " << std::cout << "NCollection_Array1<double> Sort: " <<
(aResult ? "SUCCESS" : "FAIL") << std::endl; (aResult ? "SUCCESS" : "FAIL") << std::endl;
#ifdef HAVE_TBB aResult = TestParallel<NCollection_Array1<int>, std::vector<int> >();
std::cout << "NCollection_Array1<int> Parallel: " <<
aResult = TestTBB<NCollection_Array1<int>, std::vector<int> >();
std::cout << "NCollection_Array1<int> TBB: " <<
(aResult ? "SUCCESS" : "FAIL") << std::endl; (aResult ? "SUCCESS" : "FAIL") << std::endl;
aResult = TestTBB<NCollection_Array1<double>, std::vector<double> >(); aResult = TestParallel<NCollection_Array1<double>, std::vector<double> >();
std::cout << "NCollection_Array1<double> TBB: " << std::cout << "NCollection_Array1<double> Parallel: " <<
(aResult ? "SUCCESS" : "FAIL") << std::endl; (aResult ? "SUCCESS" : "FAIL") << std::endl;
#endif
return 0; return 0;
} }