]> OCCT Git - occt.git/commitdiff
0033117: migration to intel oneTBB 2021.5.0 (c++20 ready).
authorddzama <ddzama@opencascade.com>
Thu, 25 Aug 2022 11:04:35 +0000 (14:04 +0300)
committerddzama <ddzama@opencascade.com>
Tue, 13 Sep 2022 07:50:34 +0000 (10:50 +0300)
MSVC 2022/c++20.

After employed c++20 language standard errors of compilation in intel oneTBB occurred.
To get rid of compilation errors proposed moving on actual (2021.5.0) intel oneTBB occ products and occt.

After migration errors of compilation of TKernal and TMath have been occured...
...Error occured if using c++20 standard with new oneTBB 2021.5.0.
The error was:
   Error C2672 'tbb::v1::parallel_for_each': no matching overloaded function found TKernel
   could be 'void tbb::detail::d2::parallel_for_each(Iterator,Iterator,const Body &)' TKernel
   'tbb::detail::d2::parallel_for_each': the associated constraints are not satisfied TKernel
Note, that if we use c++14 or c++17, all ok, error does not occures.

Affected projects: TKernal, TMath
Affected files: src/OSD/OSD_Parallel.hxx, src/OSD/OSD_Parallel_Threads.cxx
Affected classes: class OSD_Parallel, OSD_Parallel::UniversalIterator, OSD_Parallel::FunctorInterface, OSD_Parallel::FunctorWrapperIter, OSD_Parallel:;FunctorWrapperInt.

Additionally, taked into account different names of tbb main library on windows/linux.
On Windows, they are tbb12.lib/tbb12.dll. On Linux, it is libtbb.so.
Therefore, we have to taking into account this fact in all project generator files (cmake and others).

12 files changed:
CMakeLists.txt
adm/cmake/occt_csf.cmake
adm/cmake/tbb.cmake
adm/genconfdeps.tcl
adm/genproj.tcl
adm/qmake/OccToolkit.pri
adm/templates/custom.build.bat.in
dox/build/build_3rdparty/building_3rdparty.md
dox/introduction/introduction.md
samples/qt/IESample/IESample.pro
src/OSD/OSD_Parallel.hxx
src/OSD/OSD_Parallel_Threads.cxx

index fd17283f775dc1701c5e650e92635bf1e73a7ff8..2c47a14f05dac35a46325c6e93ce2c0b48f48e1a 100644 (file)
@@ -26,6 +26,16 @@ else ()
 endif()
 set (CMAKE_CXX_STANDARD_REQUIRED ON)
 
+# TBB
+# There are differences between naming of main intel oneTBB library under Windows and Linux/Mac.
+# Under Windows it called `tbb12` (files tbb12.lib/tbb12.dll), but under Linux it called `tbb` (file libtbb.so).
+# Therefore, we make here global variable with kernel oneTBB library name: TBB_MAIN_LIBRARY_NAME.
+if (WIN32)
+  set(TBB_MAIN_LIBRARY_NAME "TBB12")
+else()
+  set(TBB_MAIN_LIBRARY_NAME "TBB")
+endif()
+
 # macro: include patched file if it exists
 macro (OCCT_INCLUDE_CMAKE_FILE BEING_INCLUDED_FILE)
   if (BUILD_PATCH AND EXISTS "${BUILD_PATCH}/${BEING_INCLUDED_FILE}.cmake")
@@ -733,14 +743,14 @@ if (NOT DEFINED ANDROID AND CAN_USE_TBB)
     add_definitions (-DHAVE_TBB)
     OCCT_INCLUDE_CMAKE_FILE ("adm/cmake/tbb")
   else()
-    OCCT_CHECK_AND_UNSET_GROUP ("3RDPARTY_TBB")
+    OCCT_CHECK_AND_UNSET_GROUP ("3RDPARTY_${TBB_MAIN_LIBRARY_NAME}")
     OCCT_CHECK_AND_UNSET_GROUP ("3RDPARTY_TBBMALLOC")
     OCCT_CHECK_AND_UNSET ("INSTALL_TBB")
   endif()
 else()
   OCCT_CHECK_AND_UNSET ("USE_TBB")
 
-  OCCT_CHECK_AND_UNSET_GROUP ("3RDPARTY_TBB")
+  OCCT_CHECK_AND_UNSET_GROUP ("3RDPARTY_${TBB_MAIN_LIBRARY_NAME}")
   OCCT_CHECK_AND_UNSET_GROUP ("3RDPARTY_TBBMALLOC")
   OCCT_CHECK_AND_UNSET ("INSTALL_TBB")
 endif()
index bee8ba78d9ebcaec81a7760cb34ec6d6b5e38e5a..cd29f49721bb59705f621ccb0ebf3022bd1a3be1 100644 (file)
@@ -12,7 +12,9 @@ endif()
 
 # TBB
 if (USE_TBB)
-  set (CSF_TBB "tbb tbbmalloc")
+  set (TBB_MAIN_LIBRARY_NAME_LOWERCASE "")
+  string (TOLOWER "${TBB_MAIN_LIBRARY_NAME}" TBB_MAIN_LIBRARY_NAME_LOWERCASE)
+  set (CSF_TBB "${TBB_MAIN_LIBRARY_NAME_LOWERCASE} tbbmalloc")
 else()
   set (CSF_TBB)
 endif()
index 670fa4d338ca944e31d163d29764e4f02b9b0da2..8f52cf809d4da09031082d11223318232f43bcee 100644 (file)
@@ -286,9 +286,9 @@ endmacro()
   else()
     # the library directory for using by the executable
     if (WIN32)
-      set (USED_3RDPARTY_TBB_DIR ${3RDPARTY_TBB_DLL_DIR})
+      set (USED_3RDPARTY_TBB_DIR ${3RDPARTY_${TBB_MAIN_LIBRARY_NAME}_DLL_DIR})
     else()
-      set (USED_3RDPARTY_TBB_DIR ${3RDPARTY_TBB_LIBRARY_DIR})
+      set (USED_3RDPARTY_TBB_DIR ${3RDPARTY_${TBB_MAIN_LIBRARY_NAME}_LIBRARY_DIR})
     endif()
   endif()
 #endif()
index 1ffb65afdb94890a249ab27ab62861ae6003df8d..5a787bda1fb054ad6e1569e461409374374c9681 100644 (file)
@@ -759,6 +759,10 @@ proc wokdep:SearchTBB {theErrInc theErrLib32 theErrLib64 theErrBin32 theErrBin64
     }
 
     set aTbbLibPath [wokdep:SearchLib "tbb" "$anArchIter"]
+    set aTbbMainLibName "tbb"
+    if { "$::tcl_platform(platform)" == "windows" } {
+      set aTbbMainLibName "tbb12"
+    }
     if { "$aTbbLibPath" == "" } {
       set aPath [wokdep:Preferred [glob -nocomplain -directory "$::PRODUCTS_PATH" -type d *{tbb}*] $aVcLib "$anArchIter" ]
       set aTbbLibPath [wokdep:SearchLib "tbb" "$anArchIter" "$aPath/lib/$aSubDir/$aVcLib"]
@@ -775,19 +779,19 @@ proc wokdep:SearchTBB {theErrInc theErrLib32 theErrLib64 theErrBin32 theErrBin64
         lappend ::CSF_OPT_LIB$anArchIter "$aPath/lib/$aSubDir/$aVcLib"
       }
       if { "$aTbbLibPath" == "" } {
-        lappend anErrLib$anArchIter "Error: '${::SYS_LIB_PREFIX}tbb.${::SYS_LIB_SUFFIX}' not found (Intel TBB)"
+        lappend anErrLib$anArchIter "Error: '${::SYS_LIB_PREFIX}$aTbbMainLibName.${::SYS_LIB_SUFFIX}' not found (Intel TBB)"
         if { "$::ARCH" == "$anArchIter"} { set isFound "false" }
       }
     }
     if { "$::tcl_platform(platform)" == "windows" } {
-      set aTbbDllPath [wokdep:SearchBin "tbb.dll" "$anArchIter"]
+      set aTbbDllPath [wokdep:SearchBin "$aTbbMainLibName.dll" "$anArchIter"]
       if { "$aTbbDllPath" == "" } {
         set aPath [wokdep:Preferred [glob -nocomplain -directory "$::PRODUCTS_PATH" -type d *{tbb}*] $aVcLib "$anArchIter" ]
-        set aTbbDllPath [wokdep:SearchBin "tbb.dll" "$anArchIter" "$aPath/bin/$aSubDir/$aVcLib"]
+        set aTbbDllPath [wokdep:SearchBin "$aTbbMainLibName.dll" "$anArchIter" "$aPath/bin/$aSubDir/$aVcLib"]
         if { "$aTbbDllPath" != "" } {
           lappend ::CSF_OPT_BIN$anArchIter "$aPath/bin/$aSubDir/$aVcLib"
         } else {
-          lappend anErrBin$anArchIter "Error: 'tbb.dll' not found (Intel TBB)"
+          lappend anErrBin$anArchIter "Error: '$aTbbMainLibName.dll' not found (Intel TBB)"
           if { "$::ARCH" == "$anArchIter"} { set isFound "false" }
         }
       }
index 90ab8d16aedcff5dfe6f90b2defa3ed5a4c0442b..e34680525eb84b9c16f7e206da96e5bc36dce9db 100644 (file)
@@ -1437,7 +1437,11 @@ proc osutils:csfList { theOS theCsfLibsMap theCsfFrmsMap theRelease} {
     set aLibsMap(CSF_FFmpeg) "avcodec avformat swscale avutil"
   }
   if { "$::HAVE_TBB" == "true" } {
-    set aLibsMap(CSF_TBB) "tbb tbbmalloc"
+    if { "$theOS" == "wnt" } {
+      set aLibsMap(CSF_TBB) "tbb12 tbbmalloc"
+    } else {
+      set aLibsMap(CSF_TBB) "tbb tbbmalloc"
+    }
   }
   if { "$::HAVE_VTK" == "true" } {
     if { "$theOS" == "wnt" } {
index 3f18edb1cf203f0ea65a000a63df59256097c677..658ae9c6442d4a38203b388664f6bf38f217016d 100644 (file)
@@ -23,7 +23,11 @@ CSF_TclLibs   = -ltcl8.6
 CSF_TclTkLibs = -ltk8.6
 HAVE_FREEIMAGE { CSF_FreeImagePlus = -lfreeimage } else:win32 { CSF_FreeImagePlus = -lwindowscodecs -lole32 }
 HAVE_FFMPEG    { CSF_FFmpeg = -lavcodec -lavformat -lswscale -lavutil }
-HAVE_TBB       { CSF_TBB = -ltbb -ltbbmalloc }
+win32 {
+  HAVE_TBB       { CSF_TBB = -ltbb12 -ltbbmalloc }
+} else {
+  HAVE_TBB       { CSF_TBB = -ltbb -ltbbmalloc }
+}
 HAVE_ZLIB      { CSF_ZLIB = -lzlib }
 HAVE_LIBLZMA   { CSF_LIBLZMA = -lliblzma }
 HAVE_DRACO     { CSF_Draco = -ldraco }
index 39ad45085be94285588d43eb80ff76d1894b485b..0898edd15a911e409b24d3904e5e22194d0cf21a 100644 (file)
@@ -11,7 +11,7 @@ if /I "%VCVER%" == "@COMPILER@" (
     set "FREEIMAGE_DIR=@3RDPARTY_FREEIMAGE_DLL_DIRS@"
     set "EGL_DIR=@3RDPARTY_EGL_DLL_DIRS@"
     set "GLES2_DIR=@3RDPARTY_GLES2_DLL_DIRS@"
-    set "TBB_DIR=@3RDPARTY_TBB_DLL_DIR@"
+    set "TBB_DIR=@3RDPARTY_TBB12_DLL_DIR@"
     set "VTK_DIR=@3RDPARTY_VTK_DLL_DIR@"
     set "FFMPEG_DIR=@3RDPARTY_FFMPEG_DLL_DIR@"
     set "OPENVR_DIR=@3RDPARTY_OPENVR_DLL_DIRS@"
index 2eee48c8eba7a792d62b6b027777e333d89c243d..bc7d892671f2decffb2bdcfc05444a811afc111d 100644 (file)
@@ -128,8 +128,9 @@ You can download its sources from https://freetype.org/
 
 @subsection dev_guides__building_3rdparty_win_3_1 TBB
 
-This third-party product is installed with binaries from the archive that can be downloaded from https://github.com/intel/tbb.
-Go to the **Download** page, find the release version you need (e.g. `tbb30_018oss`) and pick the archive for Windows platform.
+This third-party product is installed with binaries from the archive that can be downloaded from https://github.com/oneapi-src/oneTBB/releases/tag/v2021.5.0.
+Go to the **Download** page, find the release version you need (e.g. `oneTBB 2021.5.0`) and pick the archive for Windows platform.
+To install, unpack the downloaded archive of TBB product (`oneapi-tbb-2021.5.0-win.zip`)
 
 Unpack the downloaded archive of TBB product into the `3rdparty` folder.
 
@@ -304,9 +305,9 @@ Download the necessary archive from https://freetype.org/ and unpack it.
 
 @subsection dev_guides__building_3rdparty_linux_3_1 TBB
 
-This third-party product is installed with binaries from the archive that can be downloaded from https://github.com/intel/tbb.
-Go to the **Download** page, find the release version you need and pick the archive for Linux platform.
-To install, unpack the downloaded archive of TBB product.
+This third-party product is installed with binaries from the archive that can be downloaded from https://github.com/oneapi-src/oneTBB/releases/tag/v2021.5.0.
+Go to the **Download** page, find the release version you need (e.g. `oneTBB 2021.5.0`) and pick the archive for Linux platform.
+To install, unpack the downloaded archive of TBB product (`oneapi-tbb-2021.5.0-lin.tgz`).
 
 @subsection dev_guides__building_3rdparty_linux_3_3 FreeImage
 
@@ -477,9 +478,9 @@ Download the necessary archive from https://freetype.org/ and unpack it.
 
 @subsection dev_guides__building_3rdparty_osx_3_1 TBB
 
-This third-party product is installed with binaries from the archive that can be downloaded from https://github.com/intel/tbb.
-Go to the **Download** page, find the release version you need (e.g. `tbb30_018oss`) and pick the archive for Mac OS X platform.
-To install, unpack the downloaded archive of TBB product (`tbb30_018oss_osx.tgz`).
+This third-party product is installed with binaries from the archive that can be downloaded from https://github.com/oneapi-src/oneTBB/releases/tag/v2021.5.0.
+Go to the **Download** page, find the release version you need (e.g. `oneTBB 2021.5.0`) and pick the archive for Mac OS X platform.
+To install, unpack the downloaded archive of TBB product (`oneapi-tbb-2021.5.0-mac.tgz`).
 
 @subsection dev_guides__building_3rdparty_osx_3_3 FreeImage
 
index 866ef181003cb71ba664e52052e1b31ed8d04e14..ed538caf90db6a54c593bafbc24559456944441b 100644 (file)
@@ -360,7 +360,7 @@ https://dev.opencascade.org/resources/download/3rd-party-components
 | Component | Where to find | Used for | Purpose |
 | --------- | ------------- | -------- | -------------------- |
 | CMake 3.1+ | https://cmake.org/ | Configuration | Build from sources |
-| Intel TBB 4.x or later | https://oneapi-src.github.io/oneTBB/ | All | Parallelization of algorithms (alternative to built-in thread pool) |
+| Intel oneTBB 2021.5.0 | https://github.com/oneapi-src/oneTBB/releases/tag/v2021.5.0 | All | Parallelization of algorithms (alternative to built-in thread pool) |
 | OpenGL 3.3+, OpenGL ES 2.0+ | System | Visualization | Required for using 3D Viewer |
 | OpenVR 1.10+ | https://github.com/ValveSoftware/openvr | Visualization | VR (Virtual Reality) support in 3D Viewer |
 | FreeType 2.4+ | https://www.freetype.org/download.html | Visualization | Text rendering in 3D Viewer |
@@ -572,7 +572,7 @@ FreeType 2 is released under two open-source licenses: BSD-like FreeType License
 It is a library that helps you to take advantage of multi-core processor performance without having to be a threading expert. 
 Threading Building Blocks is not just a threads-replacement library. It represents a higher-level, task-based parallelism that 
 abstracts platform details and threading mechanisms for scalability and performance. 
-TBB version 2017 is available under Apache 2.0 license, while older versions 
+oneTBB 2021.5.0 is available under Apache 2.0 license, while older versions
 until 4.4 are available under GPLv2 license with the runtime exception (https://www.threadingbuildingblocks.org).
 
 **OpenGL** is an industry standard API for 3D graphics used by OCCT for 
index 12f51c70695166b8ed16b064f2165ccdb85c9656..fe6da97701fce6726d678ac34dbf5580cadace3f 100755 (executable)
@@ -51,7 +51,11 @@ unix {
     DEFINES += OCC_CONVERT_SIGNALS QT_NO_STL
     !macx | equals(MACOSX_USE_GLX, true): LIBS += -L$$QMAKE_LIBDIR_X11 $$QMAKE_LIBS_X11 -L$$QMAKE_LIBDIR_OPENGL $$QMAKE_LIBS_OPENGL $$QMAKE_LIBS_THREAD
     LIBS += -lfreeimageplus
-    LIBS += -ltbb -ltbbmalloc
+    win32 {
+      LIBS += -ltbb12 -ltbbmalloc
+    } else {
+      LIBS += -ltbb -ltbbmalloc
+    }
     QMAKE_CXXFLAGS += -std=gnu++11
 }
 
index 7f24cf039cbdb43d5f3c1d3d1bdfd3f5b14af97e..8e1e7b620bd6a500dad294e28b13ea065524daa9 100644 (file)
@@ -125,10 +125,10 @@ protected:
 
     // Since C++20 inheritance from std::iterator is deprecated, so define predefined types manually:
     using iterator_category = std::forward_iterator_tag;
-    using value_type = UniversalIterator;
+    using value_type = IteratorInterface*;
     using difference_type = ptrdiff_t;
-    using pointer = UniversalIterator*;
-    using reference = UniversalIterator&;
+    using pointer = value_type;
+    using reference = value_type;
 
     UniversalIterator() {}
 
@@ -171,18 +171,8 @@ protected:
       return aValue;
     }
 
-    const UniversalIterator& operator* () const { return *this; }
-          UniversalIterator& operator* ()       { return *this; }
-
-    const UniversalIterator* operator->() const { return this; }
-          UniversalIterator* operator->()       { return this; }
-
-    // type cast to actual iterator
-    template <typename Iterator>
-    const Iterator& DownCast () const
-    {
-      return dynamic_cast<OSD_Parallel::IteratorWrapper<Iterator>*>(myPtr.get())->Value();
-    }
+    reference const operator* () const { return myPtr.get(); }
+    reference operator* () { return myPtr.get(); }
 
   private:
     std::unique_ptr<IteratorInterface> myPtr;
@@ -196,7 +186,14 @@ protected:
   public:
     virtual ~FunctorInterface() {}
 
-    virtual void operator () (UniversalIterator& theIterator) const = 0;
+    virtual void operator () (IteratorInterface* theIterator) const = 0;
+
+    // type cast to actual iterator
+    template <typename Iterator>
+    static const Iterator& DownCast(IteratorInterface* theIterator)
+    {
+      return dynamic_cast<OSD_Parallel::IteratorWrapper<Iterator>*>(theIterator)->Value();
+    }
   };
 
 private:
@@ -211,9 +208,9 @@ private:
     {
     }
 
-    virtual void operator() (UniversalIterator& theIterator) const Standard_OVERRIDE
+    virtual void operator() (IteratorInterface* theIterator) const Standard_OVERRIDE
     {
-      const Iterator& anIt = theIterator.DownCast<Iterator>();
+      const Iterator& anIt = DownCast<Iterator>(theIterator);
       myFunctor(*anIt);
     }
 
@@ -233,9 +230,9 @@ private:
     {
     }
 
-    virtual void operator() (UniversalIterator& theIterator) const Standard_OVERRIDE
+    virtual void operator() (IteratorInterface* theIterator) const Standard_OVERRIDE
     {
-      Standard_Integer anIndex = theIterator.DownCast<Standard_Integer>();
+      Standard_Integer anIndex = DownCast<Standard_Integer>(theIterator);
       myFunctor(anIndex);
     }
 
index 05066a0066572d5af0edbd48a3775eb503d69450..c36753ea9ac7505d88d5a27fb13e84f1dc17749d 100644 (file)
@@ -100,7 +100,7 @@ namespace
       {
         for (OSD_Parallel::UniversalIterator anIter = myRange.It(); anIter != myRange.End(); anIter = myRange.It())
         {
-          myPerformer (anIter);
+          myPerformer (*anIter);
         }
       }