add-enable-openmp
authorDebian Science Maintainers <debian-science-maintainers@lists.alioth.debian.org>
Fri, 6 May 2011 13:52:41 +0000 (14:52 +0100)
committerAdam C. Powell, IV <hazelsct@debian.org>
Fri, 6 May 2011 13:52:41 +0000 (14:52 +0100)
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

ros/adm/make/TKMesh/Makefile.am
ros/configure.in
ros/src/BRepMesh/BRepMesh_FastDiscret.cxx
ros/src/BRepMesh/BRepMesh_IncrementalMesh.cxx

index 841f74780b8606b152e297c0293589239c519422..3998f8c1de6d8a1c53a6ffb81886f68993da30ff 100644 (file)
@@ -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 \
index fa5fdf4a8ecd793bf4d95de04570d7b9dd888e9f..d5aeac7ccf52be96643ab949e8219b59bdd1d539 100644 (file)
@@ -563,6 +563,10 @@ fi
 
 fi
 
+: ${enable_openmp=no}
+AC_OPENMP
+AM_CONDITIONAL( ENABLE_OPENMP, [test "xyes" = "x$enable_openmp"] )
+
 #---------------------------------------------------------------------
 #
 # Check for TBB Libraries
index 4a0488593283dc69b41757e188ada8404eb4aaa3..018994ac45684faa3c819363d2c5137e133ef97c 100644 (file)
@@ -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<TopoDS_Face>::iterator it(aFaces.begin()); it != aFaces.end(); it++)
-    Process (*it);
+  }
+  else
+    for (std::vector<TopoDS_Face>::iterator it(aFaces.begin()); it != aFaces.end(); it++)
+      Process (*it);
 }
 
 
index a95cab8e161e173259d3714b61099a8d5545e75a..c13329a04e94b5ffd93bffb43f48f960a2fb5457 100644 (file)
@@ -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<TopoDS_Face>::iterator it(aFaces.begin()); it != aFaces.end(); it++)
-    myMesh->Process (*it);
+  }
+  else
+    for (std::vector<TopoDS_Face>::iterator it(aFaces.begin()); it != aFaces.end(); it++)
+      myMesh->Process (*it);
 
   // maillage des edges non contenues dans les faces :
   Standard_Real f, l, defedge;