From: pkv Date: Tue, 22 Oct 2013 09:13:38 +0000 (+0400) Subject: 0024157: Parallelization of assembly part of BO X-Git-Tag: V6_7_0_beta~42 X-Git-Url: http://git.dev.opencascade.org/gitweb/?p=occt.git;a=commitdiff_plain;h=796a784d3682657071d98baa22be949a1b978f6f 0024157: Parallelization of assembly part of BO New metod was implemented to class BOPAlgo_Builder - method: void BOPAlgo_Builder::SetRunParallel(const Standard_Boolean theFlag) The method sets the flag of parallel processing if is true the parallel processing is switched on if is false the parallel processing is switched off - method: Standard_Boolean BOPAlgo_Builder::RunParallel()const The method returns the flag of parallel processing Class BOPTest was changed - static function: Standard_Integer bbuild(Draw_Interpretor& di, Standard_Integer n, const char** a) The optional parameters [ -s -t ] have been added to the command line of the command 'bbuild': bbuild r [-s -t] -s : builds the result using serial procesing -t : show the wall time --- diff --git a/src/BOPAlgo/BOPAlgo_Builder.cdl b/src/BOPAlgo/BOPAlgo_Builder.cdl index 79dd265489..4914f7a439 100644 --- a/src/BOPAlgo/BOPAlgo_Builder.cdl +++ b/src/BOPAlgo/BOPAlgo_Builder.cdl @@ -106,15 +106,24 @@ is ---Purpose: Returns true if the shape theS has been deleted. returns Boolean from Standard is redefined; - + + SetRunParallel(me:out; + theFlag:Boolean from Standard); + ---Purpose: Set the flag of parallel processing + -- if is true the parallel processing is switched on + -- if is false the parallel processing is switched off + -- + RunParallel(me) + returns Boolean from Standard; + ---Purpose: Returns the flag of parallel processing -- -- Debug -- Images(me) returns DataMapOfShapeListOfShape from BOPCol; ---C++: return const & - - + + -- -- -- protected methods -- @@ -241,6 +250,8 @@ fields -- mySplits : DataMapOfShapeListOfShape from BOPCol is protected; myOrigins : DataMapOfShapeShape from BOPCol is protected; - + -- + myRunParallel : Boolean from Standard is protected; + -- end Builder; diff --git a/src/BOPAlgo/BOPAlgo_Builder.cxx b/src/BOPAlgo/BOPAlgo_Builder.cxx index 8c15237ce4..4ab91e1050 100644 --- a/src/BOPAlgo/BOPAlgo_Builder.cxx +++ b/src/BOPAlgo/BOPAlgo_Builder.cxx @@ -34,7 +34,7 @@ //function : //purpose : //======================================================================= - BOPAlgo_Builder::BOPAlgo_Builder() +BOPAlgo_Builder::BOPAlgo_Builder() : BOPAlgo_BuilderShape(), myArguments(myAllocator), @@ -46,14 +46,16 @@ myImages(100, myAllocator), myShapesSD(100, myAllocator), mySplits(100, myAllocator), - myOrigins(100, myAllocator) + myOrigins(100, myAllocator), + myRunParallel(Standard_False) { } //======================================================================= //function : //purpose : //======================================================================= - BOPAlgo_Builder::BOPAlgo_Builder(const Handle(NCollection_BaseAllocator)& theAllocator) +BOPAlgo_Builder::BOPAlgo_Builder + (const Handle(NCollection_BaseAllocator)& theAllocator) : BOPAlgo_BuilderShape(theAllocator), myArguments(myAllocator), @@ -65,14 +67,15 @@ myImages(100, myAllocator), myShapesSD(100, myAllocator), mySplits(100, myAllocator), - myOrigins(100, myAllocator) + myOrigins(100, myAllocator), + myRunParallel(Standard_False) { } //======================================================================= //function : ~ //purpose : //======================================================================= - BOPAlgo_Builder::~BOPAlgo_Builder() +BOPAlgo_Builder::~BOPAlgo_Builder() { if (myEntryPoint==1) { if (myPaveFiller) { @@ -85,7 +88,7 @@ //function : Clear //purpose : //======================================================================= - void BOPAlgo_Builder::Clear() +void BOPAlgo_Builder::Clear() { myArguments.Clear(); myMapFence.Clear(); @@ -95,10 +98,26 @@ myOrigins.Clear(); } //======================================================================= +//function : SetRunParallel +//purpose : +//======================================================================= +void BOPAlgo_Builder::SetRunParallel(const Standard_Boolean theFlag) +{ + myRunParallel=theFlag; +} +//======================================================================= +//function : RunParallel +//purpose : +//======================================================================= +Standard_Boolean BOPAlgo_Builder::RunParallel()const +{ + return myRunParallel; +} +//======================================================================= //function : AddArgument //purpose : //======================================================================= - void BOPAlgo_Builder::AddArgument(const TopoDS_Shape& theShape) +void BOPAlgo_Builder::AddArgument(const TopoDS_Shape& theShape) { if (myMapFence.Add(theShape)) { myArguments.Append(theShape); @@ -108,7 +127,7 @@ //function : Arguments //purpose : //======================================================================= - const BOPCol_ListOfShape& BOPAlgo_Builder::Arguments()const +const BOPCol_ListOfShape& BOPAlgo_Builder::Arguments()const { return myArguments; } @@ -116,7 +135,7 @@ //function : Images //purpose : //======================================================================= - const BOPCol_DataMapOfShapeListOfShape& BOPAlgo_Builder::Images()const +const BOPCol_DataMapOfShapeListOfShape& BOPAlgo_Builder::Images()const { return myImages; } @@ -124,7 +143,7 @@ //function : Origins //purpose : //======================================================================= - const BOPCol_DataMapOfShapeShape& BOPAlgo_Builder::Origins()const +const BOPCol_DataMapOfShapeShape& BOPAlgo_Builder::Origins()const { return myOrigins; } @@ -133,7 +152,7 @@ //function : ShapesSd //purpose : //======================================================================= - const BOPCol_DataMapOfShapeShape& BOPAlgo_Builder::ShapesSD()const +const BOPCol_DataMapOfShapeShape& BOPAlgo_Builder::ShapesSD()const { return myShapesSD; } @@ -141,7 +160,7 @@ //function : Splits //purpose : //======================================================================= - const BOPCol_DataMapOfShapeListOfShape& BOPAlgo_Builder::Splits()const +const BOPCol_DataMapOfShapeListOfShape& BOPAlgo_Builder::Splits()const { return mySplits; } @@ -149,7 +168,7 @@ //function : PPaveFiller //purpose : //======================================================================= - BOPAlgo_PPaveFiller BOPAlgo_Builder::PPaveFiller() +BOPAlgo_PPaveFiller BOPAlgo_Builder::PPaveFiller() { return myPaveFiller; } @@ -157,7 +176,7 @@ //function : PDS //purpose : //======================================================================= - BOPDS_PDS BOPAlgo_Builder::PDS() +BOPDS_PDS BOPAlgo_Builder::PDS() { return myDS; } @@ -165,7 +184,7 @@ // function: CheckData // purpose: //======================================================================= - void BOPAlgo_Builder::CheckData() +void BOPAlgo_Builder::CheckData() { Standard_Integer aNb; // @@ -193,7 +212,7 @@ //function : Prepare //purpose : //======================================================================= - void BOPAlgo_Builder::Prepare() +void BOPAlgo_Builder::Prepare() { myErrorStatus=0; // @@ -209,7 +228,7 @@ //function : Perform //purpose : //======================================================================= - void BOPAlgo_Builder::Perform() +void BOPAlgo_Builder::Perform() { myErrorStatus=0; // @@ -235,7 +254,7 @@ //function : PerformWithFiller //purpose : //======================================================================= - void BOPAlgo_Builder::PerformWithFiller(const BOPAlgo_PaveFiller& theFiller) +void BOPAlgo_Builder::PerformWithFiller(const BOPAlgo_PaveFiller& theFiller) { myEntryPoint=0; PerformInternal(theFiller); @@ -244,7 +263,7 @@ //function : PerformInternal //purpose : //======================================================================= - void BOPAlgo_Builder::PerformInternal(const BOPAlgo_PaveFiller& theFiller) +void BOPAlgo_Builder::PerformInternal(const BOPAlgo_PaveFiller& theFiller) { myErrorStatus=0; // @@ -366,7 +385,7 @@ //function : PostTreat //purpose : //======================================================================= - void BOPAlgo_Builder::PostTreat() +void BOPAlgo_Builder::PostTreat() { //BRepLib::SameParameter(myShape, 1.e-7, Standard_True); BOPTools_AlgoTools::CorrectTolerances(myShape, 0.05); diff --git a/src/BOPAlgo/BOPAlgo_Builder_2.cxx b/src/BOPAlgo/BOPAlgo_Builder_2.cxx index 026990b060..341ea4fca5 100644 --- a/src/BOPAlgo/BOPAlgo_Builder_2.cxx +++ b/src/BOPAlgo/BOPAlgo_Builder_2.cxx @@ -263,8 +263,7 @@ void BOPAlgo_Builder::BuildSplitFaces() aNbBF=aVBF.Extent(); // //=================================================== - bRunParallel=Standard_True; - BOPAlgo_BuilderFaceCnt::Perform(bRunParallel, aVBF); + BOPAlgo_BuilderFaceCnt::Perform(myRunParallel, aVBF); //=================================================== // for (k=0; k<(Standard_Integer)aNbBF; ++k) { @@ -422,7 +421,7 @@ void BOPAlgo_Builder::FillSameDomainFaces() // aIDMSS.Clear(); // - Standard_Boolean bRunParallel, bFlagSD; + Standard_Boolean bFlagSD; Standard_Integer aNbVPSB, aNbVVS, aNbF, aNbF1; BOPAlgo_VectorOfPairOfShapeBoolean aVPSB; // @@ -446,8 +445,7 @@ void BOPAlgo_Builder::FillSameDomainFaces() } } //==================================================== - bRunParallel=Standard_True; - BOPAlgo_BuilderSDFaceCnt::Perform(bRunParallel, aVPSB); + BOPAlgo_BuilderSDFaceCnt::Perform(myRunParallel, aVPSB); //==================================================== aAllocator=new NCollection_IncAllocator(); BOPCol_IndexedDataMapOfShapeListOfShape aDMSLS(100, aAllocator); diff --git a/src/BOPTest/BOPTest_PartitionCommands.cxx b/src/BOPTest/BOPTest_PartitionCommands.cxx index b15a4a4e61..7ec2d0473b 100644 --- a/src/BOPTest/BOPTest_PartitionCommands.cxx +++ b/src/BOPTest/BOPTest_PartitionCommands.cxx @@ -20,6 +20,7 @@ #include #include +#include #include @@ -39,6 +40,73 @@ #include // +#ifdef HAVE_TBB +#include +//======================================================================= +//class : BOPTime_Chronometer +//purpose : +//======================================================================= +class BOPTime_Chronometer { + public: + BOPTime_Chronometer() { + } + // + ~BOPTime_Chronometer() { + } + // + void Start() { + myT0 = tick_count::now(); + } + // + void Stop() { + myTime=(tick_count::now() - myT0).seconds(); + } + // + double Time() const{ + return myTime; + }; + // + protected: + tick_count myT0; + double myTime; +}; +//////////////////////////////////////////////////////////////////////// +#else +#include +//======================================================================= +//class : BOPTime_Chronometer +//purpose : +//======================================================================= +class BOPTime_Chronometer { + public: + BOPTime_Chronometer() { + } + // + ~BOPTime_Chronometer() { + } + // + void Start() { + myChronometer.Reset(); + myChronometer.Start(); + } + // + void Stop() { + myChronometer.Stop(); + myChronometer.Show(myTime); + } + // + double Time() const{ + return myTime; + }; + // + protected: + OSD_Chronometer myChronometer; + double myTime; +}; +#endif + + + static Standard_Integer bfillds (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**); @@ -56,7 +124,7 @@ static Standard_Integer bclear (Draw_Interpretor&, Standard_Integer, const cha const char* g = "Partition commands"; // Commands theCommands.Add("bfillds" , "use bfillds" , __FILE__, bfillds , g); - theCommands.Add("bbuild" , "use bbuild r" , __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("bclear" , "use bclear" , __FILE__, bclear, g); } @@ -127,15 +195,14 @@ Standard_Integer bfillds(Draw_Interpretor& di, Standard_Integer n, const char** // return 0; } - //======================================================================= //function : bbuild //purpose : //======================================================================= Standard_Integer bbuild(Draw_Interpretor& di, Standard_Integer n, const char** a) { - if (n!=2) { - di << " Use bbuild r\n"; + if (n<2) { + di << " use bbuild r [-s -t]\n"; return 0; } // @@ -145,9 +212,14 @@ Standard_Integer bbuild(Draw_Interpretor& di, Standard_Integer n, const char** a return 0; } // - char buf[32]; - Standard_Integer iErr; + char buf[128]; + Standard_Boolean bRunParallel, bShowTime; + Standard_Integer i, iErr; + + BOPTime_Chronometer aChrono; BOPCol_ListIteratorOfListOfShape aIt; + // + // BOPAlgo_PaveFiller& aPF=BOPTest_Objects::PaveFiller(); // @@ -168,7 +240,22 @@ Standard_Integer bbuild(Draw_Interpretor& di, Standard_Integer n, const char** a aBuilder.AddArgument(aS); } // - aBuilder.PerformWithFiller(aPF); + bShowTime=Standard_False; + bRunParallel=Standard_True; + for (i=2; i