From b3284f3ba911e4d18477ff1788ace3d7201a8827 Mon Sep 17 00:00:00 2001 From: ddzama Date: Thu, 15 Sep 2022 09:40:48 +0300 Subject: [PATCH] 0033117: migration to intel oneTBB 2021.5.0 (c++20 ready) 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 TKernel and TMath have been occurred... ...Error occurred 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. To solve the problem, i have to modify `UniversalIterator` class: `value_type` instead `UniversalIterator` converted to `IteratorInterface*` `pointer` = `reference` = `value_type` Method `DownCast` moved into `FunctorInterface` abstract class. argument `UniversalIterator& item` of the unary fuctions converted to `IteratorInterface*`. The proposed solution removes compilation error. Affected projects: TKernel, TMath Affected sources: 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. --- adm/cmake/tbb.cmake | 388 ++++++++---------- adm/genconfdeps.tcl | 6 +- dox/build/build_3rdparty/building_3rdparty.md | 17 +- dox/introduction/introduction.md | 5 +- src/OSD/OSD_Parallel.hxx | 37 +- src/OSD/OSD_Parallel_Threads.cxx | 2 +- 6 files changed, 210 insertions(+), 245 deletions(-) diff --git a/adm/cmake/tbb.cmake b/adm/cmake/tbb.cmake index 670fa4d338..c39a1a9f2e 100644 --- a/adm/cmake/tbb.cmake +++ b/adm/cmake/tbb.cmake @@ -1,5 +1,13 @@ # tbb +if (NOT DEFINED 3RDPARTY_DIR) + message (FATAL_ERROR "3RDPARTY_DIR is not defined.") +endif() + +if ((NOT EXISTS "${3RDPARTY_DIR}") OR ("${3RDPARTY_DIR}" STREQUAL "")) + message (FATAL_ERROR "Directory ${3RDPARTY_DIR} is not set.") +endif() + if (NOT DEFINED INSTALL_TBB AND BUILD_SHARED_LIBS) set (INSTALL_TBB OFF CACHE BOOL "${INSTALL_TBB_DESCR}") endif() @@ -69,226 +77,186 @@ else() set (3RDPARTY_TBB_INCLUDE_DIR "" CACHE PATH "the path to tbb.h" FORCE) endif() -# common steps for tbb and tbbmalloc -macro (TBB_PRODUCT_SEARCH PRODUCT_LIBRARY_NAME) +# Throw execution if 3RDPARTY_TBB_DIR is equal to void string. +if ("${3RDPARTY_TBB_DIR}" STREQUAL "") + message (FATAL_ERROR "Directory with one TBB have not found.") +endif() - string (TOUPPER ${PRODUCT_LIBRARY_NAME} upper_PRODUCT_LIBRARY_NAME) +# Searching TBBConfig.cmake and TBBTargets-release.cmake in 3RDPARTY_TBB_DIR +# TBBConfig.cmake - is required, TBBTargets-release.cmake is optional. +file (GLOB_RECURSE TBB_CONFIG_CMAKE_FILE "${3RDPARTY_TBB_DIR}/*TBBConfig.cmake") +if (NOT EXISTS "${TBB_CONFIG_CMAKE_FILE}") + message (FATAL_ERROR "TBBConfig.cmake has not been found.") +endif() +include ("${TBB_CONFIG_CMAKE_FILE}") - # define required tbb/tbbmalloc variables - if (NOT DEFINED 3RDPARTY_${upper_PRODUCT_LIBRARY_NAME}_LIBRARY OR NOT 3RDPARTY_${upper_PRODUCT_LIBRARY_NAME}_LIBRARY_DIR OR NOT EXISTS "${3RDPARTY_${upper_PRODUCT_LIBRARY_NAME}_LIBRARY_DIR}") - set (3RDPARTY_${upper_PRODUCT_LIBRARY_NAME}_LIBRARY "" CACHE FILEPATH "${upper_PRODUCT_LIBRARY_NAME} library" FORCE) - endif() +file (GLOB_RECURSE TBB_TARGET_CMAKE_FILE "${3RDPARTY_TBB_DIR}/*TBBTargets-release.cmake") +if (EXISTS "${TBB_TARGET_CMAKE_FILE}") + include ("${TBB_TARGET_CMAKE_FILE}") +endif() - if (NOT DEFINED 3RDPARTY_${upper_PRODUCT_LIBRARY_NAME}_LIBRARY_DIR) - set (3RDPARTY_${upper_PRODUCT_LIBRARY_NAME}_LIBRARY_DIR "" CACHE PATH "The directory containing ${upper_PRODUCT_LIBRARY_NAME} library") - endif() - - if (WIN32) - if (NOT DEFINED 3RDPARTY_${upper_PRODUCT_LIBRARY_NAME}_DLL OR NOT 3RDPARTY_${upper_PRODUCT_LIBRARY_NAME}_DLL_DIR OR NOT EXISTS "${3RDPARTY_${upper_PRODUCT_LIBRARY_NAME}_DLL_DIR}") - set (3RDPARTY_${upper_PRODUCT_LIBRARY_NAME}_DLL "" CACHE FILEPATH "${upper_PRODUCT_LIBRARY_NAME} shared library" FORCE) - endif() - endif() - - if (WIN32 AND NOT DEFINED 3RDPARTY_${upper_PRODUCT_LIBRARY_NAME}_DLL_DIR) - set (3RDPARTY_${upper_PRODUCT_LIBRARY_NAME}_DLL_DIR "" CACHE PATH "The directory containing ${upper_PRODUCT_LIBRARY_NAME} shared library") - endif() - - # check 3RDPARTY_${upper_PRODUCT_LIBRARY_NAME}_ paths for consistency with specified 3RDPARTY_TBB_DIR - if (3RDPARTY_TBB_DIR AND EXISTS "${3RDPARTY_TBB_DIR}") - CHECK_PATH_FOR_CONSISTENCY (3RDPARTY_TBB_DIR 3RDPARTY_${upper_PRODUCT_LIBRARY_NAME}_LIBRARY FILEPATH "the path to ${upper_PRODUCT_LIBRARY_NAME} library") - - if (3RDPARTY_${upper_PRODUCT_LIBRARY_NAME}_LIBRARY AND EXISTS "${3RDPARTY_${upper_PRODUCT_LIBRARY_NAME}_LIBRARY}") - get_filename_component (3RDPARTY_${upper_PRODUCT_LIBRARY_NAME}_LIBRARY_DIR "${3RDPARTY_${upper_PRODUCT_LIBRARY_NAME}_LIBRARY}" PATH) - set (3RDPARTY_${upper_PRODUCT_LIBRARY_NAME}_LIBRARY_DIR "${3RDPARTY_${upper_PRODUCT_LIBRARY_NAME}_LIBRARY_DIR}" CACHE PATH "The directory containing ${upper_PRODUCT_LIBRARY_NAME} library" FORCE) - else() - CHECK_PATH_FOR_CONSISTENCY (3RDPARTY_TBB_DIR 3RDPARTY_${upper_PRODUCT_LIBRARY_NAME}_LIBRARY_DIR PATH "The directory containing ${upper_PRODUCT_LIBRARY_NAME} library") - endif() - - if (WIN32) - CHECK_PATH_FOR_CONSISTENCY (3RDPARTY_TBB_DIR 3RDPARTY_${upper_PRODUCT_LIBRARY_NAME}_DLL FILEPATH "the path to ${upper_PRODUCT_LIBRARY_NAME} shared library") - - if (3RDPARTY_${upper_PRODUCT_LIBRARY_NAME}_DLL AND EXISTS "${3RDPARTY_${upper_PRODUCT_LIBRARY_NAME}_DLL}") - get_filename_component (3RDPARTY_${upper_PRODUCT_LIBRARY_NAME}_DLL_DIR "${3RDPARTY_${upper_PRODUCT_LIBRARY_NAME}_DLL}" PATH) - set (3RDPARTY_${upper_PRODUCT_LIBRARY_NAME}_DLL_DIR "${3RDPARTY_${upper_PRODUCT_LIBRARY_NAME}_DLL_DIR}" CACHE PATH "The directory containing ${upper_PRODUCT_LIBRARY_NAME} shared library" FORCE) - else() - - CHECK_PATH_FOR_CONSISTENCY (3RDPARTY_TBB_DIR 3RDPARTY_${upper_PRODUCT_LIBRARY_NAME}_DLL_DIR PATH "The directory containing ${upper_PRODUCT_LIBRARY_NAME} shared library") - endif() - endif() - endif() - - OCCT_MAKE_COMPILER_SHORT_NAME() - OCCT_MAKE_COMPILER_BITNESS() - - if (${COMPILER_BITNESS} EQUAL 32) - set (${upper_PRODUCT_LIBRARY_NAME}_ARCH_NAME ia32) +# We do not know, full path to file is pointed, or local. +# So, we should check it and output FULL PATH to FILE. +macro (TBB_FILE_NAME_TO_FILEPATH FL_NAME FL_PATH) + if (EXISTS "${FL_NAME}") + # FL_NAME is full path. + set (${FL_PATH} "${FL_NAME}") else() - set (${upper_PRODUCT_LIBRARY_NAME}_ARCH_NAME intel64) - endif() - - # tbb/tbbmalloc library - if (NOT 3RDPARTY_${upper_PRODUCT_LIBRARY_NAME}_LIBRARY OR NOT EXISTS "${3RDPARTY_${upper_PRODUCT_LIBRARY_NAME}_LIBRARY}") - - set (CMAKE_FIND_LIBRARY_SUFFIXES .lib .so .dylib .a) - set (PRODUCT_PATH_SUFFIXES lib ${PRODUCT_LIBRARY_NAME}) - - # set 3RDPARTY_${upper_PRODUCT_LIBRARY_NAME}_LIBRARY as notfound, otherwise find_library can't assign a new value to 3RDPARTY_${upper_PRODUCT_LIBRARY_NAME}_LIBRARY - set (3RDPARTY_${upper_PRODUCT_LIBRARY_NAME}_LIBRARY "3RDPARTY_${upper_PRODUCT_LIBRARY_NAME}_LIBRARY-NOTFOUND" CACHE FILEPATH "The path to ${upper_PRODUCT_LIBRARY_NAME} library" FORCE) - - if (3RDPARTY_TBB_DIR AND EXISTS "${3RDPARTY_TBB_DIR}") - if (NOT EXISTS "${3RDPARTY_TBB_DIR}/lib/${${upper_PRODUCT_LIBRARY_NAME}_ARCH_NAME}/${COMPILER}") - if (EXISTS "${3RDPARTY_TBB_DIR}/lib/${${upper_PRODUCT_LIBRARY_NAME}_ARCH_NAME}") - file (GLOB ${upper_PRODUCT_LIBRARY_NAME}_COMPILER_LIST "${3RDPARTY_TBB_DIR}/lib/${${upper_PRODUCT_LIBRARY_NAME}_ARCH_NAME}/*") - if (${upper_PRODUCT_LIBRARY_NAME}_COMPILER_LIST) - list (GET ${upper_PRODUCT_LIBRARY_NAME}_COMPILER_LIST -1 THE_MOST_FRESH_COMPILER_VERSION) - if (THE_MOST_FRESH_COMPILER_VERSION) - get_filename_component (THE_MOST_FRESH_COMPILER_VERSION_NAME "${THE_MOST_FRESH_COMPILER_VERSION}" NAME) - set (PRODUCT_PATH_SUFFIXES lib ${PRODUCT_LIBRARY_NAME} lib/${${upper_PRODUCT_LIBRARY_NAME}_ARCH_NAME}/${THE_MOST_FRESH_COMPILER_VERSION_NAME}) - endif() - endif() - endif() - else() - set (PRODUCT_PATH_SUFFIXES lib ${PRODUCT_LIBRARY_NAME} lib/${${upper_PRODUCT_LIBRARY_NAME}_ARCH_NAME}/${COMPILER}) - endif() - - find_library (3RDPARTY_${upper_PRODUCT_LIBRARY_NAME}_LIBRARY ${PRODUCT_LIBRARY_NAME} - PATHS "${3RDPARTY_${upper_PRODUCT_LIBRARY_NAME}_LIBRARY_DIR}" "${3RDPARTY_TBB_DIR}" - PATH_SUFFIXES ${PRODUCT_PATH_SUFFIXES} - CMAKE_FIND_ROOT_PATH_BOTH - NO_DEFAULT_PATH) - else() - find_library (3RDPARTY_${upper_PRODUCT_LIBRARY_NAME}_LIBRARY ${PRODUCT_LIBRARY_NAME} - PATH_SUFFIXES ${PRODUCT_PATH_SUFFIXES} - CMAKE_FIND_ROOT_PATH_BOTH) - endif() - - if (3RDPARTY_${upper_PRODUCT_LIBRARY_NAME}_LIBRARY AND EXISTS "${3RDPARTY_${upper_PRODUCT_LIBRARY_NAME}_LIBRARY}") - get_filename_component (3RDPARTY_${upper_PRODUCT_LIBRARY_NAME}_LIBRARY_DIR "${3RDPARTY_${upper_PRODUCT_LIBRARY_NAME}_LIBRARY}" PATH) - set (3RDPARTY_${upper_PRODUCT_LIBRARY_NAME}_LIBRARY_DIR "${3RDPARTY_${upper_PRODUCT_LIBRARY_NAME}_LIBRARY_DIR}" CACHE PATH "The directory containing ${upper_PRODUCT_LIBRARY_NAME} library" FORCE) - else() - set (3RDPARTY_${upper_PRODUCT_LIBRARY_NAME}_LIBRARY_DIR "" CACHE PATH "The directory containing ${upper_PRODUCT_LIBRARY_NAME} library" FORCE) + # Here we deal with local path, so assign to var full path to file. + # Acquire full path. + set (${FL_PATH} "${3RDPARTY_TBB_DIR}${FL_NAME}") + if (NOT EXISTS "${${FL_PATH}}") + message (FATAL_ERROR "TBB: needed file not found (${FL_PATH}).") endif() endif() - - if (3RDPARTY_${upper_PRODUCT_LIBRARY_NAME}_LIBRARY_DIR AND EXISTS "${3RDPARTY_${upper_PRODUCT_LIBRARY_NAME}_LIBRARY_DIR}") - list (APPEND 3RDPARTY_LIBRARY_DIRS "${3RDPARTY_${upper_PRODUCT_LIBRARY_NAME}_LIBRARY_DIR}") - else() - list (APPEND 3RDPARTY_NO_LIBS 3RDPARTY_${upper_PRODUCT_LIBRARY_NAME}_LIBRARY_DIR) - - set (3RDPARTY_${upper_PRODUCT_LIBRARY_NAME}_LIBRARY "" CACHE FILEPATH "The path to ${upper_PRODUCT_LIBRARY_NAME} library" FORCE) - endif() - - # tbb/tbbmalloc shared library - if (WIN32) - if (NOT 3RDPARTY_${upper_PRODUCT_LIBRARY_NAME}_DLL OR NOT EXISTS "${3RDPARTY_${upper_PRODUCT_LIBRARY_NAME}_DLL}") - set (CMAKE_FIND_LIBRARY_SUFFIXES .dll) - set (PRODUCT_PATH_SUFFIXES bin) - - # set 3RDPARTY_${upper_PRODUCT_LIBRARY_NAME}_DLL as notfound, otherwise find_library can't assign a new value to 3RDPARTY_${upper_PRODUCT_LIBRARY_NAME}_DLL - set (3RDPARTY_${upper_PRODUCT_LIBRARY_NAME}_DLL "3RDPARTY_${upper_PRODUCT_LIBRARY_NAME}_DLL-NOTFOUND" CACHE FILEPATH "${upper_PRODUCT_LIBRARY_NAME} shared library" FORCE) - - if (3RDPARTY_TBB_DIR AND EXISTS "${3RDPARTY_TBB_DIR}") - if (NOT EXISTS "${3RDPARTY_TBB_DIR}/bin/${${upper_PRODUCT_LIBRARY_NAME}_ARCH_NAME}/${COMPILER}") - if (EXISTS "${3RDPARTY_TBB_DIR}/bin/${${upper_PRODUCT_LIBRARY_NAME}_ARCH_NAME}") - file (GLOB ${upper_PRODUCT_LIBRARY_NAME}_COMPILER_LIST "${3RDPARTY_TBB_DIR}/bin/${${upper_PRODUCT_LIBRARY_NAME}_ARCH_NAME}/*") - if (${upper_PRODUCT_LIBRARY_NAME}_COMPILER_LIST) - list (GET ${upper_PRODUCT_LIBRARY_NAME}_COMPILER_LIST -1 THE_MOST_FRESH_COMPILER_VERSION) - if (THE_MOST_FRESH_COMPILER_VERSION) - get_filename_component (THE_MOST_FRESH_COMPILER_VERSION_NAME "${THE_MOST_FRESH_COMPILER_VERSION}" NAME) - set (PRODUCT_PATH_SUFFIXES bin bin/${${upper_PRODUCT_LIBRARY_NAME}_ARCH_NAME}/${THE_MOST_FRESH_COMPILER_VERSION_NAME}) - endif() - endif() - endif() - else() - set (PRODUCT_PATH_SUFFIXES bin bin/${${upper_PRODUCT_LIBRARY_NAME}_ARCH_NAME}/${COMPILER}) - endif() - - if (3RDPARTY_TBB_DIR AND EXISTS "${3RDPARTY_TBB_DIR}") - find_library (3RDPARTY_${upper_PRODUCT_LIBRARY_NAME}_DLL ${PRODUCT_LIBRARY_NAME} - PATHS "${3RDPARTY_TBB_DIR}" - PATH_SUFFIXES ${PRODUCT_PATH_SUFFIXES} - NO_DEFAULT_PATH) - else() - find_library (3RDPARTY_${upper_PRODUCT_LIBRARY_NAME}_DLL ${PRODUCT_LIBRARY_NAME} PATH_SUFFIXES ${PRODUCT_PATH_SUFFIXES}) - endif() - - if (3RDPARTY_${upper_PRODUCT_LIBRARY_NAME}_DLL AND EXISTS "${3RDPARTY_${upper_PRODUCT_LIBRARY_NAME}_DLL}") - get_filename_component (3RDPARTY_${upper_PRODUCT_LIBRARY_NAME}_DLL_DIR "${3RDPARTY_${upper_PRODUCT_LIBRARY_NAME}_DLL}" PATH) - set (3RDPARTY_${upper_PRODUCT_LIBRARY_NAME}_DLL_DIR "${3RDPARTY_${upper_PRODUCT_LIBRARY_NAME}_DLL_DIR}" CACHE PATH "The directory containing ${upper_PRODUCT_LIBRARY_NAME} library" FORCE) - else() - set (3RDPARTY_${upper_PRODUCT_LIBRARY_NAME}_DLL_DIR "" CACHE PATH "The directory containing ${upper_PRODUCT_LIBRARY_NAME} shared library" FORCE) - - set (3RDPARTY_${upper_PRODUCT_LIBRARY_NAME}_DLL "" CACHE FILEPATH "${upper_PRODUCT_LIBRARY_NAME} shared library" FORCE) - endif() - endif() - endif() - - if (3RDPARTY_${upper_PRODUCT_LIBRARY_NAME}_DLL_DIR OR EXISTS "${3RDPARTY_${upper_PRODUCT_LIBRARY_NAME}_DLL_DIR}") - list (APPEND 3RDPARTY_DLL_DIRS "${3RDPARTY_${upper_PRODUCT_LIBRARY_NAME}_DLL_DIR}") - else() - list (APPEND 3RDPARTY_NO_DLLS 3RDPARTY_${upper_PRODUCT_LIBRARY_NAME}_DLL_DIR) - endif() - endif() - - # install tbb/tbbmalloc - if (INSTALL_TBB) - OCCT_MAKE_OS_WITH_BITNESS() - OCCT_MAKE_COMPILER_SHORT_NAME() - - if (WIN32) - if (SINGLE_GENERATOR) - install (FILES ${3RDPARTY_${upper_PRODUCT_LIBRARY_NAME}_DLL} DESTINATION "${INSTALL_DIR_BIN}") - else() - install (FILES ${3RDPARTY_${upper_PRODUCT_LIBRARY_NAME}_DLL} - CONFIGURATIONS Release - DESTINATION "${INSTALL_DIR_BIN}") - install (FILES ${3RDPARTY_${upper_PRODUCT_LIBRARY_NAME}_DLL} - CONFIGURATIONS RelWithDebInfo - DESTINATION "${INSTALL_DIR_BIN}i") - install (FILES ${3RDPARTY_${upper_PRODUCT_LIBRARY_NAME}_DLL} - CONFIGURATIONS Debug - DESTINATION "${INSTALL_DIR_BIN}d") - endif() - else() - get_filename_component (PRODUCT_LIBRARY_NAME ${3RDPARTY_${upper_PRODUCT_LIBRARY_NAME}_LIBRARY} NAME) - - if (SINGLE_GENERATOR) - install (FILES ${3RDPARTY_${upper_PRODUCT_LIBRARY_NAME}_LIBRARY}.2 - DESTINATION "${INSTALL_DIR_LIB}" - RENAME ${PRODUCT_LIBRARY_NAME}.2) - else() - install (FILES ${3RDPARTY_${upper_PRODUCT_LIBRARY_NAME}_LIBRARY}.2 - CONFIGURATIONS Release - DESTINATION "${INSTALL_DIR_LIB}" - RENAME ${PRODUCT_LIBRARY_NAME}.2) - install (FILES ${3RDPARTY_${upper_PRODUCT_LIBRARY_NAME}_LIBRARY}.2 - CONFIGURATIONS RelWithDebInfo - DESTINATION "${INSTALL_DIR_LIB}i" - RENAME ${PRODUCT_LIBRARY_NAME}.2) - install (FILES ${3RDPARTY_${upper_PRODUCT_LIBRARY_NAME}_LIBRARY}.2 - CONFIGURATIONS Debug - DESTINATION "${INSTALL_DIR_LIB}d" - RENAME ${PRODUCT_LIBRARY_NAME}.2) - endif() - endif() - endif() - mark_as_advanced (3RDPARTY_${upper_PRODUCT_LIBRARY_NAME}_LIBRARY 3RDPARTY_${upper_PRODUCT_LIBRARY_NAME}_DLL) endmacro() -#if (BUILD_SHARED_LIBS) - separate_arguments (CSF_TBB) - foreach (LIB IN LISTS CSF_TBB) - TBB_PRODUCT_SEARCH (${LIB}) - endforeach() +# TARGET_NAME - is target name from oneTBB cmake file +# it is either "TBB::tbb", or "TBB::tbbmalloc" +# LIB_NAME_UC - is library id (TBB or TBBMALLOC) +# PROPERTY_TO_SET - LIBRARY or DLL +macro (WIN_TBB_PARSE TARGET_NAME LIB_NAME PROPERTY_TO_SET) + set (FILE_NAME "") + set (FILE_PATH "") + set (FILE_DIR "") - if (INSTALL_TBB) - set (USED_3RDPARTY_TBB_DIR "") + if ("${PROPERTY_TO_SET}" STREQUAL "LIBRARY") + get_target_property (FILE_NAME "${TARGET_NAME}" IMPORTED_IMPLIB_RELEASE) else() - # the library directory for using by the executable - if (WIN32) - set (USED_3RDPARTY_TBB_DIR ${3RDPARTY_TBB_DLL_DIR}) + get_target_property (FILE_NAME "${TARGET_NAME}" IMPORTED_LOCATION_RELEASE) + endif() + + # acquire full path + TBB_FILE_NAME_TO_FILEPATH("${FILE_NAME}" FILE_PATH) + + get_filename_component (FILE_NAME "${FILE_PATH}" NAME) + get_filename_component (FILE_DIR "${FILE_PATH}" DIRECTORY) + + if (NOT EXISTS "${FILE_DIR}/${FILE_NAME}") + set (3RDPARTY_${LIB_NAME}_${PROPERTY_TO_SET} "" CACHE FILEPATH "${LIB_NAME} library" FORCE) + set (3RDPARTY_${LIB_NAME}_${PROPERTY_TO_SET}_DIR "" CACHE PATH "The directory containing ${LIB_NAME} shared library") + + if ("${PROPERTY_TO_SET}" STREQUAL "LIBRARY") + list (APPEND 3RDPARTY_NO_LIBS 3RDPARTY_${LIB_NAME}_${PROPERTY_TO_SET}_DIR) else() - set (USED_3RDPARTY_TBB_DIR ${3RDPARTY_TBB_LIBRARY_DIR}) + list (APPEND 3RDPARTY_NO_DLLS 3RDPARTY_${LIB_NAME}_${PROPERTY_TO_SET}_DIR) + endif() + else() + set (3RDPARTY_${LIB_NAME}_${PROPERTY_TO_SET} "${FILE_DIR}/${FILE_NAME}" CACHE FILEPATH "${LIB_NAME} library" FORCE) + set (3RDPARTY_${LIB_NAME}_${PROPERTY_TO_SET}_DIR "${FILE_DIR}" CACHE PATH "The directory containing ${LIB_NAME} shared library") + + if ("${PROPERTY_TO_SET}" STREQUAL "LIBRARY") + list (APPEND 3RDPARTY_LIBRARY_DIRS "${FILE_DIR}") + else() + list (APPEND 3RDPARTY_DLL_DIRS "${FILE_DIR}") endif() endif() -#endif() +endmacro() + +# TARGET_NAME - is target name from oneTBB cmake file +# it is either "TBB::tbb", or "TBB::tbbmalloc" +# LIB_NAME_UC - is library id (TBB or TBBMALLOC) +macro (LIN_TBB_PARSE TARGET_NAME LIB_NAME) + set (FILE_NAME "") + set (FILE_PATH "") + set (FILE_DIR "") + + get_target_property (FILE_NAME "${TARGET_NAME}" IMPORTED_LOCATION_RELEASE) + + # acquire full path + TBB_FILE_NAME_TO_FILEPATH("${FILE_NAME}" FILE_PATH) + + get_filename_component (FILE_NAME "${FILE_PATH}" NAME) + get_filename_component (FILE_DIR "${FILE_PATH}" DIRECTORY) + + if (NOT EXISTS "${FILE_DIR}/${FILE_NAME}") + set (3RDPARTY_${LIB_NAME}_LIBRARY "" CACHE FILEPATH "${LIB_NAME} library" FORCE) + set (3RDPARTY_${LIB_NAME}_LIBRARY_DIR "" CACHE PATH "The directory containing ${LIB_NAME} shared library") + + list (APPEND 3RDPARTY_NO_LIBS 3RDPARTY_${LIB_NAME}_LIBRARY_DIR) + else() + set (3RDPARTY_${LIB_NAME}_LIBRARY "${FILE_DIR}/${FILE_NAME}" CACHE FILEPATH "${LIB_NAME} library" FORCE) + set (3RDPARTY_${LIB_NAME}_LIBRARY_DIR "${FILE_DIR}" CACHE PATH "The directory containing ${LIB_NAME} shared library") + + list (APPEND 3RDPARTY_LIBRARY_DIRS "${3RDPARTY_${LIB_NAME}_LIBRARY_DIR}") + endif() +endmacro() + +if (WIN32) + # Here we should set: + # - 3RDPARTY_*_LIBRARY + # - 3RDPARTY_*_LIBRARY_DIR + # - 3RDPARTY_*_DLL + # - 3RDPARTY_*_DLL_DIR + # where * - is TBB or TBBMALLOC + + separate_arguments (CSF_TBB) + foreach (LIB IN LISTS CSF_TBB) + string(TOLOWER "${LIB}" LIB_LOWER) + string(TOUPPER "${LIB}" LIB_UPPER) + WIN_TBB_PARSE("TBB::${LIB_LOWER}" "${LIB_UPPER}" "LIBRARY") + WIN_TBB_PARSE("TBB::${LIB_LOWER}" "${LIB_UPPER}" "DLL") + endforeach() +else() + # Here we should set: + # - 3RDPARTY_*_LIBRARY + # - 3RDPARTY_*_LIBRARY_DIR + + separate_arguments (CSF_TBB) + foreach (LIB IN LISTS CSF_TBB) + string(TOLOWER "${LIB}" LIB_LOWER) + string(TOUPPER "${LIB}" LIB_UPPER) + LIN_TBB_PARSE("TBB::${LIB_LOWER}" "${LIB_UPPER}") + endforeach() +endif() + +# install tbb/tbbmalloc +if (INSTALL_TBB) + OCCT_MAKE_OS_WITH_BITNESS() + OCCT_MAKE_COMPILER_SHORT_NAME() + + if (WIN32) + if (SINGLE_GENERATOR) + foreach (LIB IN LISTS CSF_TBB) + string(TOUPPER "${LIB}" LIB_UPPER) + install (FILES ${3RDPARTY_${LIB_UPPER}_DLL} DESTINATION "${INSTALL_DIR_BIN}") + endforeach() + else() + foreach (LIB IN LISTS CSF_TBB) + string(TOUPPER "${LIB}" LIB_UPPER) + install (FILES ${3RDPARTY_${LIB_UPPER}_DLL} CONFIGURATIONS Release DESTINATION "${INSTALL_DIR_BIN}") + install (FILES ${3RDPARTY_${LIB_UPPER}_DLL} CONFIGURATIONS RelWithDebInfo DESTINATION "${INSTALL_DIR_BIN}i") + install (FILES ${3RDPARTY_${LIB_UPPER}_DLL} CONFIGURATIONS Debug DESTINATION "${INSTALL_DIR_BIN}d") + endforeach() + endif() + else() + if (SINGLE_GENERATOR) + foreach (LIB IN LISTS CSF_TBB) + string(TOUPPER "${LIB}" LIB_UPPER) + install (FILES ${3RDPARTY_${LIB_UPPER}_LIBRARY} DESTINATION "${INSTALL_DIR_LIB}") + endforeach() + else() + foreach (LIB IN LISTS CSF_TBB) + string(TOUPPER "${LIB}" LIB_UPPER) + install (FILES ${3RDPARTY_${LIB_UPPER}_LIBRARY} CONFIGURATIONS Release DESTINATION "${INSTALL_DIR_LIB}") + install (FILES ${3RDPARTY_${LIB_UPPER}_LIBRARY} CONFIGURATIONS RelWithDebInfo DESTINATION "${INSTALL_DIR_LIB}i") + install (FILES ${3RDPARTY_${LIB_UPPER}_LIBRARY} CONFIGURATIONS Debug DESTINATION "${INSTALL_DIR_LIB}d") + endforeach() + endif() + endif() +endif() +foreach (LIB IN LISTS CSF_TBB) + string(TOUPPER "${LIB}" LIB_UPPER) + mark_as_advanced (3RDPARTY_${LIB_UPPER}_LIBRARY 3RDPARTY_${LIB_UPPER}_DLL) +endforeach() + +if (INSTALL_TBB) + set (USED_3RDPARTY_TBB_DIR "") +else() + # the library directory for using by the executable + if (WIN32) + set (USED_3RDPARTY_TBB_DIR ${3RDPARTY_TBB_DLL_DIR}) + else() + set (USED_3RDPARTY_TBB_DIR ${3RDPARTY_TBB_LIBRARY_DIR}) + endif() +endif() diff --git a/adm/genconfdeps.tcl b/adm/genconfdeps.tcl index 1ffb65afdb..fe99b70dc6 100644 --- a/adm/genconfdeps.tcl +++ b/adm/genconfdeps.tcl @@ -780,14 +780,14 @@ proc wokdep:SearchTBB {theErrInc theErrLib32 theErrLib64 theErrBin32 theErrBin64 } } if { "$::tcl_platform(platform)" == "windows" } { - set aTbbDllPath [wokdep:SearchBin "tbb.dll" "$anArchIter"] + set aTbbDllPath [wokdep:SearchBin "tbb12.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 "tbb12.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: 'tbb12.dll' not found (Intel TBB)" if { "$::ARCH" == "$anArchIter"} { set isFound "false" } } } diff --git a/dox/build/build_3rdparty/building_3rdparty.md b/dox/build/build_3rdparty/building_3rdparty.md index 2eee48c8eb..bc7d892671 100644 --- a/dox/build/build_3rdparty/building_3rdparty.md +++ b/dox/build/build_3rdparty/building_3rdparty.md @@ -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 diff --git a/dox/introduction/introduction.md b/dox/introduction/introduction.md index 866ef18100..fde58463d7 100644 --- a/dox/introduction/introduction.md +++ b/dox/introduction/introduction.md @@ -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,8 +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 -until 4.4 are available under GPLv2 license with the runtime exception (https://www.threadingbuildingblocks.org). +Intel oneTBB 2021.5.0 is available under Apache 2.0 license (https://www.threadingbuildingblocks.org). **OpenGL** is an industry standard API for 3D graphics used by OCCT for implementation of 3D viewer. OpenGL specification is developed by the diff --git a/src/OSD/OSD_Parallel.hxx b/src/OSD/OSD_Parallel.hxx index 7f24cf039c..190b49d329 100644 --- a/src/OSD/OSD_Parallel.hxx +++ b/src/OSD/OSD_Parallel.hxx @@ -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 - const Iterator& DownCast () const - { - return dynamic_cast*>(myPtr.get())->Value(); - } + reference operator* () const { return myPtr.get(); } + reference operator* () { return myPtr.get(); } private: std::unique_ptr 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 + static const Iterator& DownCast(IteratorInterface* theIterator) + { + return dynamic_cast*>(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(); + const Iterator& anIt = DownCast(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 anIndex = DownCast(theIterator); myFunctor(anIndex); } diff --git a/src/OSD/OSD_Parallel_Threads.cxx b/src/OSD/OSD_Parallel_Threads.cxx index 05066a0066..c36753ea9a 100644 --- a/src/OSD/OSD_Parallel_Threads.cxx +++ b/src/OSD/OSD_Parallel_Threads.cxx @@ -100,7 +100,7 @@ namespace { for (OSD_Parallel::UniversalIterator anIter = myRange.It(); anIter != myRange.End(); anIter = myRange.It()) { - myPerformer (anIter); + myPerformer (*anIter); } }