1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-08-09 13:22:24 +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_ListOfInteger.hxx>
#include <BOPCol_NCVector.hxx>
#include <BOPCol_TBB.hxx>
#include <BOPCol_Parallel.hxx>
//
#include <BOPTools.hxx>
#include <BOPTools_CoupleOfShape.hxx>
@@ -247,13 +247,13 @@ class BOPAlgo_FaceSolid : public BOPAlgo_Algo {
typedef BOPCol_NCVector
<BOPAlgo_FaceSolid> BOPAlgo_VectorOfFaceSolid;
//
typedef BOPCol_TBBContextFunctor
typedef BOPCol_ContextFunctor
<BOPAlgo_FaceSolid,
BOPAlgo_VectorOfFaceSolid,
Handle(IntTools_Context),
IntTools_Context> BOPAlgo_FaceSolidFunctor;
//
typedef BOPCol_TBBContextCnt
typedef BOPCol_ContextCnt
<BOPAlgo_FaceSolidFunctor,
BOPAlgo_VectorOfFaceSolid,
Handle(IntTools_Context)> BOPAlgo_FaceSolidCnt;

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -28,7 +28,7 @@
#include <BOPCol_IndexedMapOfShape.hxx>
#include <BOPCol_MapOfShape.hxx>
#include <BOPCol_IndexedDataMapOfShapeListOfShape.hxx>
#include <BOPCol_TBB.hxx>
#include <BOPCol_Parallel.hxx>
#include <BOPCol_NCVector.hxx>
#include <BOPTools.hxx>
@@ -262,56 +262,47 @@ typedef BOPCol_NCVector<BOPTools_ConnexityBlock> \
//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<Standard_Size>& 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<Standard_Size>(0,aNbVCB), aWSF);
}
else {
aWSF.operator()(flexible_range<Standard_Size>(0,aNbVCB));
}
OSD_Parallel::For(0, aNbVCB, aWSF, !bRunParallel);
}
//
};
//=======================================================================
//function : MakeWires