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

0025748: Parallel version of progress indicator

Progress indication mechanism is refactored to support incrementing progress within multithreaded algorithms.

The class Message_ProgressIndicator is only an interface to the user application.
It accumulates the progress provided by progress scopes.
The counter is protected by mutex for thread-safety.

The new class Message_ProgressScope replacing Message_ProgressSentry should be used to advance the progress.
The scopes are nested to each other to reflect the nested nature of operations.
The new class Message_ProgressRange should be used to pass the progress to sub-scopes.

All OCCT algorithms involving progress indication have been updated to new API.

Improvements in Draw_ProgressIndicator:
- Separate console mode has been added in order to make possible to put the progress into std::cout instead
  or in addition to the draw interpreter, instead of trigger option "-tclOutput".
- Treatment of Ctrl-Break signal has been added.
  Now any operation can be aborted by Ctrl-C or Ctrl-Break keystroke.

Added new test case 'perf fclasses progr_par' for testing of parallel work of the progress.
This commit is contained in:
msv
2020-07-10 14:19:31 +03:00
committed by abv
parent 99289bed0a
commit 7e785937b3
271 changed files with 3701 additions and 3149 deletions

View File

@@ -18,10 +18,10 @@
#include <GeomTools.hxx>
#include <gp_Ax3.hxx>
#include <gp_Vec.hxx>
#include <Message_ProgressSentry.hxx>
#include <Precision.hxx>
#include <Standard_OutOfRange.hxx>
#include <Standard_Stream.hxx>
#include <Message_ProgressScope.hxx>
#include <TopLoc_Location.hxx>
#include <TopTools_LocationSet.hxx>
@@ -171,8 +171,7 @@ void TopTools_LocationSet::Dump(Standard_OStream& OS) const
//purpose :
//=======================================================================
void TopTools_LocationSet::Write (Standard_OStream& OS,
const Handle(Message_ProgressIndicator) &theProgress) const
void TopTools_LocationSet::Write(Standard_OStream& OS, const Message_ProgressRange& theProgress) const
{
std::streamsize prec = OS.precision(15);
@@ -181,7 +180,7 @@ void TopTools_LocationSet::Write (Standard_OStream& OS,
OS << "Locations " << nbLoc << "\n";
//OCC19559
Message_ProgressSentry PS(theProgress, "Locations", 0, nbLoc, 1);
Message_ProgressScope PS(theProgress, "Locations", nbLoc);
for (i = 1; i <= nbLoc && PS.More(); i++, PS.Next()) {
TopLoc_Location L = myMap(i);
@@ -246,7 +245,7 @@ static void ReadTrsf(gp_Trsf& T,
//purpose :
//=======================================================================
void TopTools_LocationSet::Read (Standard_IStream& IS, const Handle(Message_ProgressIndicator) &theProgress)
void TopTools_LocationSet::Read(Standard_IStream& IS, const Message_ProgressRange& theProgress)
{
myMap.Clear();
@@ -266,7 +265,7 @@ void TopTools_LocationSet::Read (Standard_IStream& IS, const Handle(Message_Pro
gp_Trsf T;
//OCC19559
Message_ProgressSentry PS(theProgress, "Locations", 0, nbLoc, 1);
Message_ProgressScope PS(theProgress, "Locations", nbLoc);
for (i = 1; i <= nbLoc&& PS.More(); i++, PS.Next()) {
Standard_Integer typLoc;
IS >> typLoc;

View File

@@ -25,7 +25,7 @@
#include <Standard_Integer.hxx>
#include <Standard_OStream.hxx>
#include <Standard_IStream.hxx>
#include <Message_ProgressIndicator.hxx>
#include <Message_ProgressRange.hxx>
class Standard_OutOfRange;
class TopLoc_Location;
@@ -38,7 +38,7 @@ class TopLoc_Location;
//!
//! It can create Locations.
//!
//! It can be written and read from a stream.
//! It can be write and read from a stream.
class TopTools_LocationSet
{
public:
@@ -68,12 +68,12 @@ public:
//! Writes the content of me on the stream <OS> in a
//! format that can be read back by Read.
Standard_EXPORT void Write (Standard_OStream& OS,
const Handle(Message_ProgressIndicator)& theProgress = NULL) const;
const Message_ProgressRange& theProgress = Message_ProgressRange()) const;
//! Reads the content of me from the stream <IS>. me
//! is first cleared.
Standard_EXPORT void Read (Standard_IStream& IS,
const Handle(Message_ProgressIndicator)& theProgress = NULL);
const Message_ProgressRange& theProgress = Message_ProgressRange());
private:

View File

@@ -22,8 +22,7 @@
// authentification we cut last '\r' in the line (which will
// be present if file is in DOS coding)
#include <Message_ProgressIndicator.hxx>
#include <Message_ProgressSentry.hxx>
#include <Message_ProgressScope.hxx>
#include <TCollection_AsciiString.hxx>
#include <TopoDS_Iterator.hxx>
#include <TopoDS_Shape.hxx>
@@ -443,8 +442,7 @@ void TopTools_ShapeSet::Dump(Standard_OStream& OS)const
//purpose :
//=======================================================================
void TopTools_ShapeSet::Write (Standard_OStream& OS,
const Handle(Message_ProgressIndicator) &theProgress)
void TopTools_ShapeSet::Write(Standard_OStream& OS, const Message_ProgressRange& theProgress)
{
// always use C locale for writing shapes
std::locale anOldLocale = OS.imbue (std::locale::classic());
@@ -461,20 +459,28 @@ void TopTools_ShapeSet::Write (Standard_OStream& OS,
//-----------------------------------------
// write the locations
//-----------------------------------------
Message_ProgressSentry aPS(theProgress, "Writing Shapes", 0, 3, 1);
myLocations.Write(OS, theProgress);
if (!aPS.More())
Message_ProgressScope aPS(theProgress, "Writing", 100);
myLocations.Write(OS, aPS.Next(10));
if (aPS.UserBreak()) {
OS << "Interrupted by the user\n";
OS.imbue (anOldLocale);
return;
aPS.Next();
}
//-----------------------------------------
// write the geometry
//-----------------------------------------
WriteGeometry(OS, theProgress);
if (!aPS.More())
WriteGeometry(OS, aPS.Next(75));
if (aPS.UserBreak()) {
OS << "Interrupted by the user\n";
OS.imbue(anOldLocale);
return;
aPS.Next();
}
//-----------------------------------------
// write the shapes
@@ -485,9 +491,8 @@ void TopTools_ShapeSet::Write (Standard_OStream& OS,
OS << "\nTShapes " << nbShapes << "\n";
// subshapes are written first
//OCC19559
Message_ProgressSentry aPSinner(theProgress, "Shapes", 0, nbShapes, 1);
for (i = 1; i <= nbShapes && aPSinner.More(); i++, aPSinner.Next()) {
Message_ProgressScope aPS1 (aPS.Next(15), "Shapes", nbShapes);
for (i = 1; i <= nbShapes && aPS1.More(); i++, aPS1.Next()) {
const TopoDS_Shape& S = myShapes(i);
// Type
@@ -528,7 +533,10 @@ void TopTools_ShapeSet::Write (Standard_OStream& OS,
OS << "\n";
OS.precision(prec);
OS.imbue (anOldLocale);
}
if (aPS.UserBreak())
OS << "Interrupted by the user\n";
}
//=======================================================================
//function : ReadShapeEnum
@@ -575,7 +583,7 @@ static TopAbs_ShapeEnum ReadShapeEnum(Standard_IStream& IS)
//purpose :
//=======================================================================
void TopTools_ShapeSet::Read (Standard_IStream& IS, const Handle(Message_ProgressIndicator) &theProgress)
void TopTools_ShapeSet::Read(Standard_IStream& IS, const Message_ProgressRange& theProgress)
{
// always use C locale for reading shapes
std::locale anOldLocale = IS.imbue (std::locale::classic());
@@ -611,19 +619,27 @@ void TopTools_ShapeSet::Read (Standard_IStream& IS, const Handle(Message_Progre
// read the locations
//-----------------------------------------
//OCC19559
Message_ProgressSentry aPS(theProgress, "Reading", 0, 10, 3);
myLocations.Read(IS, theProgress);
if (!aPS.More())
Message_ProgressScope aPS(theProgress, "Reading", 100);
myLocations.Read(IS, aPS.Next(10));
if (aPS.UserBreak()) {
std::cout << "Interrupted by the user"<<std::endl;
// on remet le LC_NUMERIC a la precedente valeur
IS.imbue (anOldLocale);
return;
aPS.Next();
}
//-----------------------------------------
// read the geometry
//-----------------------------------------
ReadGeometry(IS, theProgress);
if (!aPS.More())
ReadGeometry(IS, aPS.Next(75));
if (aPS.UserBreak()) {
std::cout << "Interrupted by the user"<<std::endl;
IS.imbue(anOldLocale);
return;
aPS.Next();
}
//-----------------------------------------
// read the shapes
@@ -642,9 +658,8 @@ void TopTools_ShapeSet::Read (Standard_IStream& IS, const Handle(Message_Progre
IS >> nbShapes;
//OCC19559
Message_ProgressSentry PS(theProgress, "Shapes", 0, nbShapes, 1);
for (i = 1; i <= nbShapes && PS.More(); i++, PS.Next() ) {
Message_ProgressScope aPS1 (aPS.Next(15), "Shapes", nbShapes);
for (i = 1; i <= nbShapes && aPS1.More(); i++, aPS1.Next() ) {
TopoDS_Shape S;
//Read type and create empty shape.
@@ -683,8 +698,12 @@ void TopTools_ShapeSet::Read (Standard_IStream& IS, const Handle(Message_Progre
myShapes.Add(S);
}
// on remet le LC_NUMERIC a la precedente valeur
IS.imbue (anOldLocale);
if (aPS.UserBreak())
std::cout << "Interrupted by the user" << std::endl;
}
//=======================================================================
@@ -710,7 +729,8 @@ void TopTools_ShapeSet::Dump(const TopoDS_Shape& S,
//purpose :
//=======================================================================
void TopTools_ShapeSet::Write (const TopoDS_Shape& S, Standard_OStream& OS)const
void TopTools_ShapeSet::Write(const TopoDS_Shape& S,
Standard_OStream& OS)const
{
if (S.IsNull()) OS << "*";
else {
@@ -725,7 +745,8 @@ void TopTools_ShapeSet::Write (const TopoDS_Shape& S, Standard_OStream& OS)cons
//purpose :
//=======================================================================
void TopTools_ShapeSet::Read (TopoDS_Shape& S, Standard_IStream& IS)const
void TopTools_ShapeSet::Read(TopoDS_Shape& S,
Standard_IStream& IS)const
{
Read(S,IS,myShapes.Extent());
}
@@ -799,8 +820,7 @@ void TopTools_ShapeSet::DumpGeometry(Standard_OStream&) const
//purpose :
//=======================================================================
void TopTools_ShapeSet::WriteGeometry (Standard_OStream&,
const Handle(Message_ProgressIndicator) &)
void TopTools_ShapeSet::WriteGeometry(Standard_OStream&, const Message_ProgressRange&)
{
}
@@ -810,8 +830,7 @@ void TopTools_ShapeSet::WriteGeometry (Standard_OStream&,
//purpose :
//=======================================================================
void TopTools_ShapeSet::ReadGeometry (Standard_IStream&,
const Handle(Message_ProgressIndicator) &)
void TopTools_ShapeSet::ReadGeometry(Standard_IStream&, const Message_ProgressRange&)
{
}
@@ -832,7 +851,8 @@ void TopTools_ShapeSet::DumpGeometry(const TopoDS_Shape&,
//purpose :
//=======================================================================
void TopTools_ShapeSet::WriteGeometry (const TopoDS_Shape&, Standard_OStream&)const
void TopTools_ShapeSet::WriteGeometry(const TopoDS_Shape&,
Standard_OStream&)const
{
}
@@ -842,7 +862,9 @@ void TopTools_ShapeSet::WriteGeometry (const TopoDS_Shape&, Standard_OStream&)c
//purpose :
//=======================================================================
void TopTools_ShapeSet::ReadGeometry (const TopAbs_ShapeEnum, Standard_IStream&, TopoDS_Shape&)
void TopTools_ShapeSet::ReadGeometry(const TopAbs_ShapeEnum,
Standard_IStream& ,
TopoDS_Shape&)
{
}

View File

@@ -34,7 +34,7 @@ class TCollection_AsciiString;
//! A ShapeSets contains a Shape and all its
//! sub-shapes and locations. It can be dumped, written
//! sub-shapes and locations. It can be dump, write
//! and read.
//!
//! Methods to handle the geometry can be redefined.
@@ -44,6 +44,7 @@ public:
DEFINE_STANDARD_ALLOC
//! Builds an empty ShapeSet.
Standard_EXPORT TopTools_ShapeSet();
@@ -108,9 +109,8 @@ public:
//! Write the type.
//! calls WriteGeometry(S).
//! Write the flags, the subshapes.
Standard_EXPORT virtual void Write
(Standard_OStream& OS,
const Handle(Message_ProgressIndicator) &theProgress = NULL);
Standard_EXPORT virtual void Write (Standard_OStream& OS,
const Message_ProgressRange& theProgress = Message_ProgressRange());
//! Reads the content of me from the stream <IS>. me
//! is first cleared.
@@ -124,9 +124,8 @@ public:
//! Reads the type.
//! calls ReadGeometry(T,S).
//! Reads the flag, the subshapes.
Standard_EXPORT virtual void Read
(Standard_IStream& IS,
const Handle(Message_ProgressIndicator) &theProgress = NULL);
Standard_EXPORT virtual void Read (Standard_IStream& IS,
const Message_ProgressRange& theProgress = Message_ProgressRange());
//! Dumps on <OS> the shape <S>. Dumps the
//! orientation, the index of the TShape and the index
@@ -149,14 +148,12 @@ public:
//! Writes the geometry of me on the stream <OS> in a
//! format that can be read back by Read.
Standard_EXPORT virtual void WriteGeometry
(Standard_OStream& OS,
const Handle(Message_ProgressIndicator) &theProgress = NULL);
Standard_EXPORT virtual void WriteGeometry (Standard_OStream& OS,
const Message_ProgressRange& theProgress = Message_ProgressRange());
//! Reads the geometry of me from the stream <IS>.
Standard_EXPORT virtual void ReadGeometry
(Standard_IStream& IS,
const Handle(Message_ProgressIndicator) &theProgress = NULL);
Standard_EXPORT virtual void ReadGeometry (Standard_IStream& IS,
const Message_ProgressRange& theProgress = Message_ProgressRange());
//! Dumps the geometry of <S> on the stream <OS>.
Standard_EXPORT virtual void DumpGeometry (const TopoDS_Shape& S, Standard_OStream& OS) const;
@@ -185,14 +182,16 @@ public:
Standard_EXPORT Standard_Integer NbShapes() const;
private:
//! Reads from <IS> a shape and returns it in S.
//! <NbShapes> is the number of tshapes in the set.
Standard_EXPORT void Read (TopoDS_Shape& S, Standard_IStream& IS, const Standard_Integer NbShapes) const;
TopTools_IndexedMapOfShape myShapes;
TopTools_LocationSet myLocations;
Standard_Integer myFormatNb;
};
#endif // _TopTools_ShapeSet_HeaderFile