From: Debian Science Maintainers Date: Fri, 6 May 2011 13:52:41 +0000 (+0100) Subject: add-enable-openmp X-Git-Tag: archive/raspbian/7.3.0+dfsg1-4+rpi1~1^2^2~5 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=89b5a0fd26e60223c7ddb76111734f489f091543;p=opencascade.git add-enable-openmp Add a new configure option: --enable-openmp When this option is set, loops which are parallelized upstream with tbb are parallelized with openmp. Due to a bug in libtool (it removes -fopenmp flag when linking), a workaround is provided, but works only with GNU gcc. Submitted upstream: http://www.opencascade.org/org/forum/thread_20105/ Gbp-Pq: Topic submitted Gbp-Pq: Name add-enable-openmp.patch --- diff --git a/ros/adm/make/TKMesh/Makefile.am b/ros/adm/make/TKMesh/Makefile.am index 841f74780..3998f8c1d 100644 --- a/ros/adm/make/TKMesh/Makefile.am +++ b/ros/adm/make/TKMesh/Makefile.am @@ -24,6 +24,8 @@ INCLUDES = $(STLPort_INCLUDES) $(CSF_TBB_INCLUDES) \ lib_LTLIBRARIES=libTKMesh.la +libTKMesh_la_CXXFLAGS = $(OPENMP_CXXFLAGS) + libTKMesh_la_LIBADD = \ ../TKMath/libTKMath.la \ ../TKernel/libTKernel.la \ @@ -35,6 +37,12 @@ libTKMesh_la_LIBADD = \ ../TKTopAlgo/libTKTopAlgo.la \ $(STLPort_LIB) $(CSF_TBB_LIB) +# Work around an annoying bug in libtool, it removes -fopenmp flag when linking. +# The downside is that --enable-openmp can be used only with GNU gcc +if ENABLE_OPENMP +libTKMesh_la_LIBADD += -lgomp +endif + libTKMesh_la_SOURCES = \ @top_srcdir@/drv/BRepMesh/BRepMesh_Array1OfBiPoint_0.cxx \ @top_srcdir@/drv/BRepMesh/BRepMesh_Array1OfVertexOfDelaun_0.cxx \ diff --git a/ros/configure.in b/ros/configure.in index fa5fdf4a8..d5aeac7cc 100644 --- a/ros/configure.in +++ b/ros/configure.in @@ -563,6 +563,10 @@ fi fi +: ${enable_openmp=no} +AC_OPENMP +AM_CONDITIONAL( ENABLE_OPENMP, [test "xyes" = "x$enable_openmp"] ) + #--------------------------------------------------------------------- # # Check for TBB Libraries diff --git a/ros/src/BRepMesh/BRepMesh_FastDiscret.cxx b/ros/src/BRepMesh/BRepMesh_FastDiscret.cxx index 4a0488593..018994ac4 100644 --- a/ros/src/BRepMesh/BRepMesh_FastDiscret.cxx +++ b/ros/src/BRepMesh/BRepMesh_FastDiscret.cxx @@ -186,13 +186,20 @@ void BRepMesh_FastDiscret::Perform(const TopoDS_Shape& shape) } // mesh faces in parallel threads using TBB -#ifdef HAVE_TBB if (Standard::IsReentrant()) + { +#ifdef HAVE_TBB tbb::parallel_for_each (aFaces.begin(), aFaces.end(), *this); - else +#else + int i, n = aFaces.size(); +#pragma omp parallel for private(i) + for (i = 0; i < n; ++i) + Process (aFaces[i]); #endif - for (std::vector::iterator it(aFaces.begin()); it != aFaces.end(); it++) - Process (*it); + } + else + for (std::vector::iterator it(aFaces.begin()); it != aFaces.end(); it++) + Process (*it); } diff --git a/ros/src/BRepMesh/BRepMesh_IncrementalMesh.cxx b/ros/src/BRepMesh/BRepMesh_IncrementalMesh.cxx index a95cab8e1..c13329a04 100644 --- a/ros/src/BRepMesh/BRepMesh_IncrementalMesh.cxx +++ b/ros/src/BRepMesh/BRepMesh_IncrementalMesh.cxx @@ -216,13 +216,20 @@ void BRepMesh_IncrementalMesh::Update(const TopoDS_Shape& S) } // mesh faces in parallel threads using TBB -#ifdef HAVE_TBB if (Standard::IsReentrant()) + { +#ifdef HAVE_TBB tbb::parallel_for_each (aFaces.begin(), aFaces.end(), *myMesh.operator->()); - else +#else + int i, n = aFaces.size(); +#pragma omp parallel for private(i) + for (i = 0; i < n; ++i) + myMesh->Process (aFaces[i]); #endif - for (std::vector::iterator it(aFaces.begin()); it != aFaces.end(); it++) - myMesh->Process (*it); + } + else + for (std::vector::iterator it(aFaces.begin()); it != aFaces.end(); it++) + myMesh->Process (*it); // maillage des edges non contenues dans les faces : Standard_Real f, l, defedge;