1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-08-29 14:00:49 +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

@@ -13,17 +13,8 @@
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#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_WINNT)
#define _WIN32_WINNT 0x0501
#endif
#include <tbb/tbb.h>
#endif
#include <Standard_Assert.hxx>
#include <OSD_Parallel.hxx>
#include <OpenGl_SceneGeometry.hxx>
@@ -208,8 +199,6 @@ void OpenGl_RaytraceGeometry::Clear()
Materials.swap (anEmptyMaterials);
}
#ifdef HAVE_TBB
struct OpenGL_BVHParallelBuilder
{
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> (anObjectIdx)).operator->());
OpenGl_TriangleSet* aTriangleSet = dynamic_cast<OpenGl_TriangleSet*> (
Set->Objects().ChangeValue (static_cast<Standard_Integer> (theObjectIdx)).operator->());
if (aTriangleSet != NULL)
{
aTriangleSet->BVH();
}
}
if (aTriangleSet != NULL)
aTriangleSet->BVH();
}
};
#endif
// =======================================================================
// function : ProcessAcceleration
// purpose : Performs post-processing of high-level BVH
@@ -254,12 +236,7 @@ Standard_Boolean OpenGl_RaytraceGeometry::ProcessAcceleration()
aTimer.Start();
#endif
#ifdef HAVE_TBB
// 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
OSD_Parallel::For(0, Size(), OpenGL_BVHParallelBuilder(this));
myBottomLevelTreeDepth = 0;