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

0024639: Parallelization FillDS part of BO

Edge/Edge Interferences

Changes:
1. class BOPAlgo_PaveFiller
  - method:
void BOPAlgo_PaveFiller::PerformEE()
the chages provides the parallel computations of
Edge/Edge interferences.

   - auxiliary classes:
    BOPAlgo_EdgeEdge
    BOPAlgo_EdgeEdgeFunctor
    BOPAlgo_EdgeEdgeCnt
have been added.
The classes are auxiliary classes to provide the parallel computations
of Edge/Edge interferences.

2. class BOPTest
-method:
void BOPTest::PartitionCommands(Draw_Interpretor& theCommands)
- static function:
Standard_Integer bfillds(Draw_Interpretor& di,
                         Standard_Integer n,
                         const char** a)
The syntax of the command "bfillds" has been changed.
> bfillds [-s -t]
options:
-s - launch the algorithm in sequential mode
-t - display CPU time

Test case for issue CR24639
This commit is contained in:
pkv 2014-03-06 15:05:58 +04:00 committed by abv
parent decdfc9499
commit a942f2da6a
4 changed files with 406 additions and 182 deletions

View File

@ -45,6 +45,8 @@
#include <BOPCol_DataMapOfIntegerShape.hxx> #include <BOPCol_DataMapOfIntegerShape.hxx>
#include <BOPCol_IndexedDataMapOfShapeBox.hxx> #include <BOPCol_IndexedDataMapOfShapeBox.hxx>
#include <BOPCol_BoxBndTree.hxx> #include <BOPCol_BoxBndTree.hxx>
#include <BOPCol_NCVector.hxx>
#include <BOPCol_TBB.hxx>
// //
#include <BOPInt_Context.hxx> #include <BOPInt_Context.hxx>
#include <BOPInt_ShrunkRange.hxx> #include <BOPInt_ShrunkRange.hxx>
@ -62,23 +64,101 @@
// //
#include <BOPAlgo_Tools.hxx> #include <BOPAlgo_Tools.hxx>
//=======================================================================
//class : BOPAlgo_EdgeEdge
//purpose :
//=======================================================================
class BOPAlgo_EdgeEdge : public IntTools_EdgeEdge {
public:
BOPAlgo_EdgeEdge()
: IntTools_EdgeEdge() {
};
//
~BOPAlgo_EdgeEdge(){
};
//
void SetPaveBlock1(const Handle(BOPDS_PaveBlock)& aPB) {
myPB1=aPB;
}
//
Handle(BOPDS_PaveBlock)& PaveBlock1() {
return myPB1;
}
//
void SetPaveBlock2(const Handle(BOPDS_PaveBlock)& aPB) {
myPB2=aPB;
}
//
Handle(BOPDS_PaveBlock)& PaveBlock2() {
return myPB2;
}
//
protected:
Handle(BOPDS_PaveBlock) myPB1;
Handle(BOPDS_PaveBlock) myPB2;
};
//
typedef BOPCol_NCVector<BOPAlgo_EdgeEdge> BOPAlgo_VectorOfEdgeEdge;
//
//
//=======================================================================
//class : BOPAlgo_EdgeEdgeFunctor
//purpose :
//=======================================================================
class BOPAlgo_EdgeEdgeFunctor {
protected:
BOPAlgo_VectorOfEdgeEdge* myPVEE;
//
public:
//
BOPAlgo_EdgeEdgeFunctor(BOPAlgo_VectorOfEdgeEdge& aVEE)
: myPVEE(&aVEE) {
}
//
void operator()( const flexible_range<Standard_Size>& aBR ) const{
Standard_Size i, iBeg, iEnd;
//
BOPAlgo_VectorOfEdgeEdge& aVEE=*myPVEE;
//
iBeg=aBR.begin();
iEnd=aBR.end();
for(i=iBeg; i!=iEnd; ++i) {
BOPAlgo_EdgeEdge& aEE=aVEE(i);
//
aEE.Perform();
}
}
};
//=======================================================================
//class : BOPAlgo_EdgeEdgeCnt
//purpose :
//=======================================================================
class BOPAlgo_EdgeEdgeCnt {
public:
//-------------------------------
// Perform
Standard_EXPORT
static void Perform(const Standard_Boolean bRunParallel,
BOPAlgo_VectorOfEdgeEdge& aVEdgeEdge) {
//
BOPAlgo_EdgeEdgeFunctor aEEF(aVEdgeEdge);
Standard_Size aNbEE=aVEdgeEdge.Extent();
//
if (bRunParallel) {
flexible_for(flexible_range<Standard_Size>(0,aNbEE), aEEF);
}
else {
aEEF.operator()(flexible_range<Standard_Size>(0,aNbEE));
}
}
};
//======================================================================= //=======================================================================
// function: PerformEE // function: PerformEE
// purpose: // purpose:
//======================================================================= //=======================================================================
void BOPAlgo_PaveFiller::PerformEE() void BOPAlgo_PaveFiller::PerformEE()
{ {
Standard_Boolean bJustAdd; Standard_Integer iSize;
Standard_Integer i, iX, iSize, nE1, nE2;
Standard_Integer aNbCPrts;
Standard_Real aTS11, aTS12, aTS21, aTS22,
aT11, aT12, aT21, aT22;
TopAbs_ShapeEnum aType;
BOPDS_ListIteratorOfListOfPaveBlock aIt1, aIt2;
Handle(NCollection_IncAllocator) aAllocator;
BOPDS_MapOfPaveBlock aMPBToUpdate;
BOPDS_MapIteratorOfMapOfPaveBlock aItPB;
// //
myErrorStatus=0; myErrorStatus=0;
// //
@ -88,8 +168,17 @@ void BOPAlgo_PaveFiller::PerformEE()
return; return;
} }
// //
Standard_Boolean bJustAdd;
Standard_Integer i, iX, nE1, nE2, aNbCPrts, k, aNbFdgeEdge;
Standard_Real aTS11, aTS12, aTS21, aTS22, aT11, aT12, aT21, aT22;
TopAbs_ShapeEnum aType;
BOPDS_ListIteratorOfListOfPaveBlock aIt1, aIt2;
Handle(NCollection_IncAllocator) aAllocator;
BOPDS_MapOfPaveBlock aMPBToUpdate;
BOPAlgo_VectorOfEdgeEdge aVEdgeEdge;
BOPDS_MapIteratorOfMapOfPaveBlock aItPB;
//
//-----------------------------------------------------scope f //-----------------------------------------------------scope f
aAllocator=new NCollection_IncAllocator();
BOPDS_IndexedDataMapOfPaveBlockListOfPaveBlock aMPBLPB(100, aAllocator); BOPDS_IndexedDataMapOfPaveBlockListOfPaveBlock aMPBLPB(100, aAllocator);
BOPDS_IndexedDataMapOfShapeCoupleOfPaveBlocks aMVCPB(100, aAllocator); BOPDS_IndexedDataMapOfShapeCoupleOfPaveBlocks aMVCPB(100, aAllocator);
// //
@ -149,19 +238,45 @@ void BOPAlgo_PaveFiller::PerformEE()
continue; continue;
} }
// //
IntTools_EdgeEdge anEdgeEdge;
//
aPB1->Range(aT11, aT12); aPB1->Range(aT11, aT12);
aPB2->Range(aT21, aT22); aPB2->Range(aT21, aT22);
// //
BOPAlgo_EdgeEdge& anEdgeEdge=aVEdgeEdge.Append1();
//
anEdgeEdge.SetPaveBlock1(aPB1);
anEdgeEdge.SetPaveBlock2(aPB2);
//
anEdgeEdge.SetEdge1(aE1, aT11, aT12); anEdgeEdge.SetEdge1(aE1, aT11, aT12);
anEdgeEdge.SetEdge2(aE2, aT21, aT22); anEdgeEdge.SetEdge2(aE2, aT21, aT22);
}//for (; aIt2.More(); aIt2.Next()) {
}//for (; aIt1.More(); aIt1.Next()) {
}//for (; myIterator->More(); myIterator->Next()) {
// //
anEdgeEdge.Perform(); aNbFdgeEdge=aVEdgeEdge.Extent();
//======================================================
BOPAlgo_EdgeEdgeCnt::Perform(myRunParallel, aVEdgeEdge);
//======================================================
//
for (k=0; k < aNbFdgeEdge; ++k) {
Bnd_Box aBB1, aBB2;
//
BOPAlgo_EdgeEdge& anEdgeEdge=aVEdgeEdge(k);
if (!anEdgeEdge.IsDone()) { if (!anEdgeEdge.IsDone()) {
continue; continue;
} }
// //
//--------------------------------------------
Handle(BOPDS_PaveBlock)& aPB1=anEdgeEdge.PaveBlock1();
nE1=aPB1->OriginalEdge();
aPB1->Range(aT11, aT12);
aPB1->ShrunkData(aTS11, aTS12, aBB1);
//
Handle(BOPDS_PaveBlock)& aPB2=anEdgeEdge.PaveBlock2();
nE2=aPB2->OriginalEdge();
aPB2->Range(aT21, aT22);
aPB2->ShrunkData(aTS21, aTS22, aBB2);
//
//--------------------------------------------
IntTools_Range aR11(aT11, aTS11), aR12(aTS12, aT12), IntTools_Range aR11(aT11, aTS11), aR12(aTS12, aT12),
aR21(aT21, aTS21), aR22(aTS22, aT22); aR21(aT21, aTS21), aR22(aTS22, aT22);
// //
@ -169,6 +284,10 @@ void BOPAlgo_PaveFiller::PerformEE()
aNbCPrts=aCPrts.Length(); aNbCPrts=aCPrts.Length();
for (i=1; i<=aNbCPrts; ++i) { for (i=1; i<=aNbCPrts; ++i) {
const IntTools_CommonPrt& aCPart=aCPrts(i); const IntTools_CommonPrt& aCPart=aCPrts(i);
//
const TopoDS_Edge& aE1=aCPart.Edge1();
const TopoDS_Edge& aE2=aCPart.Edge2();
//
aType=aCPart.Type(); aType=aCPart.Type();
switch (aType) { switch (aType) {
case TopAbs_VERTEX: { case TopAbs_VERTEX: {
@ -196,8 +315,10 @@ void BOPAlgo_PaveFiller::PerformEE()
aPB1->Indices(nV[0], nV[1]); aPB1->Indices(nV[0], nV[1]);
aPB2->Indices(nV[2], nV[3]); aPB2->Indices(nV[2], nV[3]);
// //
if((bIsOnPave[0] && bIsOnPave[2]) || (bIsOnPave[0] && bIsOnPave[3]) || if((bIsOnPave[0] && bIsOnPave[2]) ||
(bIsOnPave[1] && bIsOnPave[2]) || (bIsOnPave[1] && bIsOnPave[3])) { (bIsOnPave[0] && bIsOnPave[3]) ||
(bIsOnPave[1] && bIsOnPave[2]) ||
(bIsOnPave[1] && bIsOnPave[3])) {
continue; continue;
} }
// //
@ -300,11 +421,7 @@ void BOPAlgo_PaveFiller::PerformEE()
break; break;
}//switch (aType) { }//switch (aType) {
}//for (i=1; i<=aNbCPrts; i++) { }//for (i=1; i<=aNbCPrts; i++) {
// -----------t }//for (k=0; k < aNbFdgeEdge; ++k) {
//
}// for (; aIt2.More(); aIt2.Next()) {
}// for (; aIt1.More(); aIt1.Next()) {
}
// //
//========================================= //=========================================
// post treatment // post treatment
@ -327,7 +444,6 @@ void BOPAlgo_PaveFiller::PerformEE()
aMPBLPB.Clear(); aMPBLPB.Clear();
aMVCPB.Clear(); aMVCPB.Clear();
aMPBToUpdate.Clear(); aMPBToUpdate.Clear();
aAllocator.Nullify();
} }
//======================================================================= //=======================================================================
//function : PerformVertices //function : PerformVertices

View File

@ -587,6 +587,7 @@ void BOPAlgo_PaveFiller::MakeBlocks()
} }
// //
// 2 Fuse shapes // 2 Fuse shapes
aPF.SetRunParallel(myRunParallel);
aPF.SetArguments(aLS); aPF.SetArguments(aLS);
aPF.Perform(); aPF.Perform();
iErr=aPF.ErrorStatus(); iErr=aPF.ErrorStatus();

View File

@ -3,8 +3,8 @@
// //
// This file is part of Open CASCADE Technology software library. // This file is part of Open CASCADE Technology software library.
// //
// This library is free software; you can redistribute it and/or modify it under // This library is free software; you can redistribute it and / or modify it
// the terms of the GNU Lesser General Public License version 2.1 as published // under the terms of the GNU Lesser General Public version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file // 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 // 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. // distribution for complete text of the license and disclaimer of any warranty.
@ -100,12 +100,11 @@ class BOPTime_Chronometer {
}; };
#endif #endif
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**);
static Standard_Integer bbop (Draw_Interpretor&, Standard_Integer, const char**); static Standard_Integer bbop (Draw_Interpretor&, Standard_Integer, const char**);
static Standard_Integer bclear (Draw_Interpretor&, Standard_Integer, const char**); static Standard_Integer bclear (Draw_Interpretor&, Standard_Integer, const char**);
//======================================================================= //=======================================================================
//function : PartitionCommands //function : PartitionCommands
//purpose : //purpose :
@ -118,7 +117,7 @@ static Standard_Integer bclear (Draw_Interpretor&, Standard_Integer, const cha
// Chapter's name // Chapter's name
const char* g = "Partition commands"; const char* g = "Partition commands";
// Commands // Commands
theCommands.Add("bfillds" , "use bfillds" , __FILE__, bfillds , g); theCommands.Add("bfillds" , "use bfillds [-s -t]" , __FILE__, bfillds, g);
theCommands.Add("bbuild" , "use bbuild r [-s -t]", __FILE__, bbuild, g); theCommands.Add("bbuild" , "use bbuild r [-s -t]", __FILE__, bbuild, g);
theCommands.Add("bbop" , "use bbop r op" , __FILE__, bbop, g); theCommands.Add("bbop" , "use bbop r op" , __FILE__, bbop, g);
theCommands.Add("bclear" , "use bclear" , __FILE__, bclear, g); theCommands.Add("bclear" , "use bclear" , __FILE__, bclear, g);
@ -128,7 +127,9 @@ static Standard_Integer bclear (Draw_Interpretor&, Standard_Integer, const cha
//function : bclear //function : bclear
//purpose : //purpose :
//======================================================================= //=======================================================================
Standard_Integer bclear(Draw_Interpretor& di, Standard_Integer n, const char** ) Standard_Integer bclear(Draw_Interpretor& di,
Standard_Integer n,
const char** )
{ {
if (n!=1) { if (n!=1) {
di << " use bclear\n"; di << " use bclear\n";
@ -142,17 +143,21 @@ Standard_Integer bclear(Draw_Interpretor& di, Standard_Integer n, const char** )
//function : bfillds //function : bfillds
//purpose : //purpose :
//======================================================================= //=======================================================================
Standard_Integer bfillds(Draw_Interpretor& di, Standard_Integer n, const char** ) Standard_Integer bfillds(Draw_Interpretor& di,
Standard_Integer n,
const char** a)
{ {
if (n!=1) { if (n>3) {
di << " Use bfillds\n"; di << " use bfillds [-s -t]\n";
return 0; return 0;
} }
// //
char buf[32]; char buf[32];
Standard_Integer aNbS, iErr; Standard_Boolean bRunParallel, bShowTime;
Standard_Integer i, aNbS, iErr;
BOPCol_ListIteratorOfListOfShape aIt; BOPCol_ListIteratorOfListOfShape aIt;
BOPCol_ListOfShape aLC; BOPCol_ListOfShape aLC;
BOPTime_Chronometer aChrono;
BOPCol_ListOfShape& aLS=BOPTest_Objects::Shapes(); BOPCol_ListOfShape& aLS=BOPTest_Objects::Shapes();
aNbS=aLS.Extent(); aNbS=aLS.Extent();
@ -161,6 +166,17 @@ Standard_Integer bfillds(Draw_Interpretor& di, Standard_Integer n, const char**
return 0; return 0;
} }
// //
bShowTime=Standard_False;
bRunParallel=Standard_True;
for (i=1; i<n; ++i) {
if (!strcmp(a[i], "-s")) {
bRunParallel=Standard_False;
}
else if (!strcmp(a[i], "-t")) {
bShowTime=Standard_True;
}
}
//
BOPCol_ListOfShape& aLT=BOPTest_Objects::Tools(); BOPCol_ListOfShape& aLT=BOPTest_Objects::Tools();
// //
aIt.Initialize(aLS); aIt.Initialize(aLS);
@ -178,6 +194,9 @@ Standard_Integer bfillds(Draw_Interpretor& di, Standard_Integer n, const char**
BOPAlgo_PaveFiller& aPF=BOPTest_Objects::PaveFiller(); BOPAlgo_PaveFiller& aPF=BOPTest_Objects::PaveFiller();
// //
aPF.SetArguments(aLC); aPF.SetArguments(aLC);
aPF.SetRunParallel(bRunParallel);
//
aChrono.Start();
// //
aPF.Perform(); aPF.Perform();
iErr=aPF.ErrorStatus(); iErr=aPF.ErrorStatus();
@ -187,13 +206,25 @@ Standard_Integer bfillds(Draw_Interpretor& di, Standard_Integer n, const char**
return 0; return 0;
} }
// //
aChrono.Stop();
//
if (bShowTime) {
Standard_Real aTime;
//
aTime=aChrono.Time();
Sprintf(buf, " Tps: %7.2lf\n", aTime);
di << buf;
}
//
return 0; return 0;
} }
//======================================================================= //=======================================================================
//function : bbuild //function : bbuild
//purpose : //purpose :
//======================================================================= //=======================================================================
Standard_Integer bbuild(Draw_Interpretor& di, Standard_Integer n, const char** a) Standard_Integer bbuild(Draw_Interpretor& di,
Standard_Integer n,
const char** a)
{ {
if (n<2) { if (n<2) {
di << " use bbuild r [-s -t]\n"; di << " use bbuild r [-s -t]\n";
@ -212,8 +243,6 @@ Standard_Integer bbuild(Draw_Interpretor& di, Standard_Integer n, const char** a
BOPTime_Chronometer aChrono; BOPTime_Chronometer aChrono;
BOPCol_ListIteratorOfListOfShape aIt; BOPCol_ListIteratorOfListOfShape aIt;
//
// //
BOPAlgo_PaveFiller& aPF=BOPTest_Objects::PaveFiller(); BOPAlgo_PaveFiller& aPF=BOPTest_Objects::PaveFiller();
// //
@ -281,7 +310,9 @@ Standard_Integer bbuild(Draw_Interpretor& di, Standard_Integer n, const char** a
//function : bbop //function : bbop
//purpose : //purpose :
//======================================================================= //=======================================================================
Standard_Integer bbop(Draw_Interpretor& di, Standard_Integer n, const char** a) Standard_Integer bbop(Draw_Interpretor& di,
Standard_Integer n,
const char** a)
{ {
if (n!=3) { if (n!=3) {
di << " use bbop r op\n"; di << " use bbop r op\n";

View File

@ -0,0 +1,76 @@
puts "========="
puts "OCC24639"
puts "========="
puts ""
###########################################################
# Parallelization FillDS part of BO
###########################################################
set N 5
set dC 1.
set aC [expr $N + $dC]
#------------------------------------------
# z
vertex v1 0 0 0
vertex v2 0 0 $aC
edge ez v1 v2
set qz {}
for {set i 0} {$i < $N} {incr i} {
for {set j 0} {$j < $N} {incr j} {
tcopy ez ez_${i}_{$j}
ttranslate ez_${i}_{$j} [expr $i + ${dC}] [expr $j + $dC] 0.
lappend qz ez_${i}_{$j}
}
}
eval compound $qz bz
#------------------------------------------
# x
vertex v1 0. 0. 0.
vertex v2 $aC 0. 0.
edge ex v1 v2
set qx {}
for {set i 0} {$i < $N} {incr i} {
for {set j 0} {$j < $N} {incr j} {
tcopy ex ex_${i}_{$j}
ttranslate ex_${i}_{$j} 0. [expr $i + $dC] [expr $j + $dC]
lappend qx ex_${i}_{$j}
}
}
eval compound $qx bx
#------------------------------------------
# y
vertex v1 0. 0. 0.
vertex v2 0. $aC 0.
edge ey v1 v2
set qy {}
for {set i 0} {$i < $N} {incr i} {
for {set j 0} {$j < $N} {incr j} {
tcopy ey ey_${i}_{$j}
ttranslate ey_${i}_{$j} [expr $i + $dC] 0. [expr $j + $dC]
lappend qy ey_${i}_{$j}
}
}
eval compound $qy by
nurbsconvert bx bx
nurbsconvert by by
nurbsconvert bz bz
# add the arguments
bclearobjects
bcleartools
baddcompound bx
baddcompound by
baddcompound bz
# intersection step
bfillds -t
# intersection step
bfillds -t -s