From bc3abe75780f50b46ac0b394012ad000a34fc2e6 Mon Sep 17 00:00:00 2001 From: tbbdev Date: Wed, 31 Jan 2024 10:28:52 -0600 Subject: [PATCH] Commit oneTBB source code 144b1846 --- .bazelversion | 2 +- .github/workflows/ci.yml | 6 +- CMakeLists.txt | 75 ++++---- CONTRIBUTING.md | 5 - INSTALL.md | 2 +- MODULE.bazel | 24 +++ README.md | 6 +- RELEASE_NOTES.md | 28 ++- SUPPORT.md | 35 ++++ WASM_Support.md | 39 ++++- cmake/README.md | 1 + cmake/compilers/Clang.cmake | 2 +- cmake/compilers/GNU.cmake | 4 +- cmake/compilers/IntelLLVM.cmake | 4 +- cmake/compilers/MSVC.cmake | 2 +- cmake/config_generation.cmake | 2 + cmake/hwloc_detection.cmake | 4 +- cmake/templates/TBBConfig.cmake.in | 2 + cmake/utils.cmake | 44 ++--- doc/conf.py | 6 +- doc/main/intro/Benefits.rst | 2 +- .../tbb_userguide/Flow_Graph_Reservation.rst | 10 +- .../Migration_Guide/Mixing_Two_Runtimes.rst | 1 + examples/CMakeLists.txt | 3 +- examples/README.md | 1 + examples/common/gui/CMakeLists.txt | 4 +- .../count_strings/CMakeLists.txt | 4 +- .../shortpath/CMakeLists.txt | 4 +- .../sub_string_finder/CMakeLists.txt | 4 +- examples/graph/binpack/CMakeLists.txt | 4 +- examples/graph/cholesky/CMakeLists.txt | 4 +- .../graph/dining_philosophers/CMakeLists.txt | 4 +- examples/graph/fgbzip2/CMakeLists.txt | 2 +- examples/graph/logic_sim/CMakeLists.txt | 4 +- examples/graph/som/CMakeLists.txt | 4 +- .../recursive_fibonacci/CMakeLists.txt | 4 +- .../migration/recursive_fibonacci/README.md | 5 +- .../recursive_fibonacci/fibonacci.cpp | 2 + .../fibonacci_single_task.h | 30 ++-- .../recursive_fibonacci/fibonacci_two_tasks.h | 16 +- .../task_emulation_layer.h | 59 ++++--- .../parallel_for/game_of_life/CMakeLists.txt | 4 +- .../polygon_overlay/CMakeLists.txt | 4 +- examples/parallel_for/seismic/CMakeLists.txt | 4 +- examples/parallel_for/tachyon/CMakeLists.txt | 4 +- .../parallel_preorder/CMakeLists.txt | 4 +- .../parallel_pipeline/square/CMakeLists.txt | 4 +- examples/parallel_reduce/README.md | 1 + .../convex_hull/CMakeLists.txt | 4 +- examples/parallel_reduce/pi/CMakeLists.txt | 33 ++++ examples/parallel_reduce/pi/README.md | 24 +++ examples/parallel_reduce/pi/common.h | 51 ++++++ examples/parallel_reduce/pi/main.cpp | 100 +++++++++++ examples/parallel_reduce/pi/pi.cpp | 55 ++++++ .../parallel_reduce/primes/CMakeLists.txt | 4 +- examples/task_arena/fractal/CMakeLists.txt | 4 +- examples/task_group/sudoku/CMakeLists.txt | 4 +- examples/test_all/fibonacci/CMakeLists.txt | 4 +- .../tbb/detail/_concurrent_unordered_base.h | 2 +- .../oneapi/tbb/enumerable_thread_specific.h | 10 +- include/oneapi/tbb/parallel_for_each.h | 29 ++++ include/oneapi/tbb/version.h | 36 ++-- integration/linux/modulefiles/tbb | 1 + integration/linux/modulefiles/tbb32 | 1 + .../windows/nuget/inteltbb.devel.win.targets | 12 +- src/tbb/CMakeLists.txt | 100 +++++------ src/tbb/arena.h | 3 +- src/tbb/concurrent_monitor.h | 12 +- src/tbb/global_control.cpp | 1 + src/tbb/waiters.h | 7 +- src/tbbbind/CMakeLists.txt | 10 -- src/tbbmalloc/TypeDefinitions.h | 4 +- test/CMakeLists.txt | 5 +- test/common/utils_concurrency_limit.h | 55 ++++-- .../conformance_parallel_for_each.cpp | 2 - test/tbb/test_eh_thread.cpp | 4 +- test/tbb/test_fuzzing.cpp | 2 +- test/tbb/test_parallel_for_each.cpp | 163 +++++++++++++++++- test/tbb/test_task.cpp | 6 +- test/tbbmalloc/test_malloc_compliance.cpp | 7 +- 80 files changed, 926 insertions(+), 318 deletions(-) create mode 100644 MODULE.bazel create mode 100644 SUPPORT.md create mode 100644 examples/parallel_reduce/pi/CMakeLists.txt create mode 100644 examples/parallel_reduce/pi/README.md create mode 100644 examples/parallel_reduce/pi/common.h create mode 100644 examples/parallel_reduce/pi/main.cpp create mode 100644 examples/parallel_reduce/pi/pi.cpp diff --git a/.bazelversion b/.bazelversion index 09b254e90c..66ce77b7ea 100644 --- a/.bazelversion +++ b/.bazelversion @@ -1 +1 @@ -6.0.0 +7.0.0 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a6d710f883..d758aee050 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,4 +1,4 @@ -# Copyright (c) 2021-2023 Intel Corporation +# Copyright (c) 2021-2024 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -25,6 +25,8 @@ on: - synchronize - reopened +permissions: read-all + env: BUILD_CONCURRENCY: 2 MACOS_BUILD_CONCURRENCY: 3 @@ -57,7 +59,7 @@ jobs: needs: [codespell] env: BUILD_TYPE: oss - runs-on: [ubuntu-20.04] + runs-on: [ubuntu-22.04] timeout-minutes: 10 steps: - uses: actions/checkout@v2 diff --git a/CMakeLists.txt b/CMakeLists.txt index 16ee29edcb..189d7e53d3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,10 +12,15 @@ # See the License for the specific language governing permissions and # limitations under the License. -cmake_minimum_required(VERSION 3.1) +cmake_minimum_required(VERSION 3.5) # Enable CMake policies +if (POLICY CMP0068) + # RPATH settings do not affect install_name on macOS since CMake 3.9 + cmake_policy(SET CMP0068 NEW) +endif() + if (POLICY CMP0091) # The NEW behavior for this policy is to not place MSVC runtime library flags in the default # CMAKE__FLAGS_ cache entries and use CMAKE_MSVC_RUNTIME_LIBRARY abstraction instead. @@ -38,12 +43,6 @@ if (APPLE) endif() endif() -# Until CMake 3.4.0 FindThreads.cmake requires C language enabled. -# Enable C language before CXX to avoid possible override of CMAKE_SIZEOF_VOID_P. -if (CMAKE_VERSION VERSION_LESS 3.4) - enable_language(C) -endif() - file(READ include/oneapi/tbb/version.h _tbb_version_info) string(REGEX REPLACE ".*#define TBB_VERSION_MAJOR ([0-9]+).*" "\\1" _tbb_ver_major "${_tbb_version_info}") string(REGEX REPLACE ".*#define TBB_VERSION_MINOR ([0-9]+).*" "\\1" _tbb_ver_minor "${_tbb_version_info}") @@ -104,9 +103,10 @@ option(TBBMALLOC_BUILD "Enable tbbmalloc build" ON) cmake_dependent_option(TBBMALLOC_PROXY_BUILD "Enable tbbmalloc_proxy build" ON "TBBMALLOC_BUILD" OFF) option(TBB_CPF "Enable preview features of the library" OFF) option(TBB_FIND_PACKAGE "Enable search for external oneTBB using find_package instead of build from sources" OFF) -option(TBB_DISABLE_HWLOC_AUTOMATIC_SEARCH "Disable HWLOC automatic search by pkg-config tool" OFF) +option(TBB_DISABLE_HWLOC_AUTOMATIC_SEARCH "Disable HWLOC automatic search by pkg-config tool" ${CMAKE_CROSSCOMPILING}) option(TBB_ENABLE_IPO "Enable Interprocedural Optimization (IPO) during the compilation" ON) option(TBB_FUZZ_TESTING "Enable fuzz testing" OFF) +option(TBB_INSTALL "Enable installation" ON) if (NOT DEFINED BUILD_SHARED_LIBS) set(BUILD_SHARED_LIBS ON) @@ -250,34 +250,39 @@ else() else() add_subdirectory(src/tbbbind) endif() + if (TBB_INSTALL) + # ------------------------------------------------------------------- + # Installation instructions + include(CMakePackageConfigHelpers) + + install(DIRECTORY include/ + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} + COMPONENT devel) + + install(EXPORT ${PROJECT_NAME}Targets + NAMESPACE TBB:: + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME} + COMPONENT devel) + file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake + "include(\${CMAKE_CURRENT_LIST_DIR}/${PROJECT_NAME}Targets.cmake)\n") + if (NOT BUILD_SHARED_LIBS) + file(APPEND ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake + "include(CMakeFindDependencyMacro)\nfind_dependency(Threads)\n") + endif() + + write_basic_package_version_file("${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake" + COMPATIBILITY AnyNewerVersion) - # ------------------------------------------------------------------- - # Installation instructions - include(CMakePackageConfigHelpers) - - install(DIRECTORY include/ - DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} - COMPONENT devel) - - install(EXPORT ${PROJECT_NAME}Targets - NAMESPACE TBB:: - DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME} - COMPONENT devel) - file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake - "include(\${CMAKE_CURRENT_LIST_DIR}/${PROJECT_NAME}Targets.cmake)\n") - - write_basic_package_version_file("${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake" - COMPATIBILITY AnyNewerVersion) - - install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake" - "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake" - DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME} - COMPONENT devel) - - install(FILES "README.md" - DESTINATION ${CMAKE_INSTALL_DOCDIR} - COMPONENT devel) - # ------------------------------------------------------------------- + install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake" + "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake" + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME} + COMPONENT devel) + + install(FILES "README.md" + DESTINATION ${CMAKE_INSTALL_DOCDIR} + COMPONENT devel) + # ------------------------------------------------------------------- + endif() endif() if (TBB_TEST) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index c8b437083a..3048b21199 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -29,11 +29,6 @@ The DCO is an attestation attached to every contribution made by every developer As a contributor, you’ll want to be familiar with the oneTBB project and the repository layout. You should also know how to use it as explained in the [oneTBB documentation](https://oneapi-src.github.io/oneTBB/) and how to set up your build development environment to configure, build, and test oneTBB as explained in the [oneTBB Build System Description](cmake/README.md). -## Issues -If you face a problem, first check out open [oneTBB GitHub issues](https://github.com/oneapi-src/oneTBB/issues) to see if the issue you’d like to address is already reported. You may find users that have encountered the bug you’re finding or have similar ideas for changes or additions. - -You can use issues to report a problem, make a feature request, or add comments on an existing issue. - ## Pull Requests You can find all [open oneTBB pull requests](https://github.com/oneapi-src/oneTBB/pulls) on GitHub. diff --git a/INSTALL.md b/INSTALL.md index 3c63c9fd84..0ac95f8755 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -61,7 +61,7 @@ You can use the ``install`` components for partial installation. The following install components are supported: - `runtime` - oneTBB runtime package (core shared libraries and `.dll` files on Windows* OS). - `devel` - oneTBB development package (header files, CMake integration files, library symbolic links, and `.lib` files on Windows* OS). -- `tbb4py` - [oneTBB Module for Python](#onetbb-python-module-support). +- `tbb4py` - [oneTBB Module for Python](https://github.com/oneapi-src/oneTBB/blob/master/python/README.md). If you want to install specific components after configuration and build, run: diff --git a/MODULE.bazel b/MODULE.bazel new file mode 100644 index 0000000000..393dc0ac42 --- /dev/null +++ b/MODULE.bazel @@ -0,0 +1,24 @@ +# Copyright (c) 2021-2024 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# DISCLAIMER: Bazel support is community-based. The maintainers do not +# use Bazel internally. The Bazel build can have security risks or +# optimization gaps. + +module( + name = "onetbb", + compatibility_level = 1, +) + +bazel_dep(name = "platforms", version = "0.0.8") diff --git a/README.md b/README.md index b96e1fb000..f2bc0a0afa 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,8 @@ oneTBB is a part of [oneAPI](https://oneapi.io). The current branch implements v > **_NOTE:_** Threading Building Blocks (TBB) is now called oneAPI Threading Building Blocks (oneTBB) to highlight that the tool is a part of the oneAPI ecosystem. ## Release Information -Here are [Release Notes](RELEASE_NOTES.md) and [System Requirements](SYSTEM_REQUIREMENTS.md). + +See [Release Notes](RELEASE_NOTES.md) and [System Requirements](SYSTEM_REQUIREMENTS.md). ## Documentation * [oneTBB Specification](https://spec.oneapi.com/versions/latest/elements/oneTBB/source/nested-index.html) @@ -39,7 +40,7 @@ Here are [Release Notes](RELEASE_NOTES.md) and [System Requirements](SYSTEM_REQU See [Installation from Sources](INSTALL.md) to learn how to install oneTBB. ## Support -Please report issues and suggestions via [GitHub issues](https://github.com/oneapi-src/oneTBB/issues). See our [documentation](./CONTRIBUTING.md##Issues) to learn how to work with them. +See our [documentation](./SUPPORT.md) to learn how to request help. ## How to Contribute We welcome community contributions, so check our [Contributing Guidelines](CONTRIBUTING.md) @@ -49,7 +50,6 @@ to learn more. oneAPI Threading Building Blocks is licensed under [Apache License, Version 2.0](LICENSE.txt). By its terms, contributions submitted to the project are also done under that license. - ## Engineering team contacts * [Email us.](mailto:inteltbbdevelopers@intel.com) diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index 57258416fe..24687d1ffd 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -18,26 +18,22 @@ This document contains changes of oneTBB compared to the last release. ## Table of Contents -- [New Features](#new-features) - [Known Limitations](#known-limitations) - [Fixed Issues](#fixed-issues) -## :tada: New Features -- Since C++17, parallel algorithms and Flow Graph nodes are allowed to accept pointers to the member functions and member objects as the user-provided callables. -- Added missed member functions, such as assignment operators and swap function, to the ``concurrent_queue`` and ``concurrent_bounded_queue`` containers. - ## :rotating_light: Known Limitations -- A static assert will cause compilation failures in oneTBB headers when compiling with clang 12.0.0 or newer if using the LLVM standard library with ``-ffreestanding`` and C++11/14 compiler options. -- An application using Parallel STL algorithms in libstdc++ versions 9 and 10 may fail to compile due to incompatible interface changes between earlier versions of Threading Building Blocks (TBB) and oneAPI Threading Building Blocks (oneTBB). Disable support for Parallel STL algorithms by defining ``PSTL_USE_PARALLEL_POLICIES`` (in libstdc++ 9) or ``_GLIBCXX_USE_TBB_PAR_BACKEND`` (in libstdc++ 10) macro to zero before inclusion of the first standard header file in each translation unit. -- On Linux* OS, if oneAPI Threading Building Blocks (oneTBB) or Threading Building Blocks (TBB) are installed in a system folder like ``/usr/lib64``, the application may fail to link due to the order in which the linker searches for libraries. Use the ``-L`` linker option to specify the correct location of oneTBB library. This issue does not affect the program execution. -- The ``oneapi::tbb::info`` namespace interfaces might unexpectedly change the process affinity mask on Windows* OS systems (see https://github.com/open-mpi/hwloc/issues/366 for details) when using hwloc* version lower than 2.5. -- Using a hwloc* version other than 1.11, 2.0, or 2.5 may cause an undefined behavior on Windows* OS. See https://github.com/open-mpi/hwloc/issues/477 for details. -- The NUMA* topology may be detected incorrectly on Windows* OS machines where the number of NUMA* node threads exceeds the size of 1 processor group. -- On Windows* OS on ARM64*, when compiling an application using oneTBB with the Microsoft* Compiler, the compiler issues a warning C4324 that a structure was padded due to the alignment specifier. Consider suppressing the warning by specifying ``/wd4324`` to the compiler command line. -- oneTBB does not support ``fork()``, to work-around the issue, consider using task_scheduler_handle to join oneTBB worker threads before using fork(). +- The ``oneapi::tbb::info`` namespace interfaces might unexpectedly change the process affinity mask on Windows* OS systems (see https://github.com/open-mpi/hwloc/issues/366 for details) when using hwloc version lower than 2.5. +- Using a hwloc version other than 1.11, 2.0, or 2.5 may cause an undefined behavior on Windows OS. See https://github.com/open-mpi/hwloc/issues/477 for details. +- The NUMA topology may be detected incorrectly on Windows* OS machines where the number of NUMA node threads exceeds the size of 1 processor group. +- On Windows OS on ARM64*, when compiling an application using oneTBB with the Microsoft* Compiler, the compiler issues a warning C4324 that a structure was padded due to the alignment specifier. Consider suppressing the warning by specifying /wd4324 to the compiler command line. - C++ exception handling mechanism on Windows* OS on ARM64* might corrupt memory if an exception is thrown from any oneTBB parallel algorithm (see Windows* OS on ARM64* compiler issue: https://developercommunity.visualstudio.com/t/ARM64-incorrect-stack-unwinding-for-alig/1544293). +- Using ``TBBConfig.cmake`` in 32-bit environment may cause incorrect linkage with 64-bit oneTBB library. As a workaround, set ``CMAKE_PREFIX_PATH``: + - On Linux* OS: to ``TBBROOT/lib32/`` + - On Windows* OS: to ``TBBROOT/lib32/;TBBROOT/bin32/`` + +> **_NOTE:_** To see known limitations that impact all versions of oneTBB, refer to [oneTBB Documentation](https://oneapi-src.github.io/oneTBB/main/intro/limitations.html). + ## :hammer: Fixed Issues -- Fixed the hang in the reserve method of concurrent unordered containers ([GitHub* #1056](http://github.com/oneapi-src/oneTBB/issues/1056)). -- Fixed the C++20 three-way comparison feature detection ([GitHub* #1093](http://github.com/oneapi-src/oneTBB/issues/1093)). -- Fixed oneTBB integration with CMake* in the Conda* environment. +- Fixed ``tbb::this_task_arena()`` behavior for specific ``tbb::task_arena{1,0}``. +- Restored performance on systems with a high number of CPU cores that support ``_tpause``. diff --git a/SUPPORT.md b/SUPPORT.md new file mode 100644 index 0000000000..47bb60a538 --- /dev/null +++ b/SUPPORT.md @@ -0,0 +1,35 @@ + + +# oneTBB Support + +We are committed to providing support and assistance to help you make the most out of oneTBB. +Use the following methods if you face any challenges. + +## Issues + +If you have a problem, check out the [GitHub Issues](https://github.com/oneapi-src/oneTBB/issues) to see if the issue you want to address is already reported. +You may find users that have encountered the same bug or have similar ideas for changes or updates. + +You can use issues to report a problem, make a feature request, or add comments on an existing issue. + +## Discussions + +Visit the [GitHub Discussions](https://github.com/oneapi-src/oneTBB/discussions) to engage with the community, ask questions, or help others. + +## Email + +Reach out to us privately via [email](mailto:inteltbbdevelopers@intel.com). \ No newline at end of file diff --git a/WASM_Support.md b/WASM_Support.md index 67925ee496..bf38a91e8e 100644 --- a/WASM_Support.md +++ b/WASM_Support.md @@ -16,16 +16,43 @@ # WASM Support +oneTBB extends its capabilities by offering robust support for ``WASM``. + ``WASM`` stands for WebAssembly, a low-level binary format for executing code in web browsers. -It is designed to be a portable target for compilers and to be efficient to parse and execute. +It is designed to be a portable target for compilers and efficient to parse and execute. + +Using oneTBB with WASM, you can take full advantage of parallelism and concurrency while working on web-based applications, interactive websites, and a variety of other WASM-compatible platforms. + +oneTBB offers WASM support through the integration with [Emscripten*](https://emscripten.org/docs/introducing_emscripten/index.html), a powerful toolchain for compiling C and C++ code into WASM-compatible runtimes. + +## Build + +**Prerequisites:** Download and install Emscripten*. See the [instructions](https://emscripten.org/docs/getting_started/downloads.html). + +To build the system, run: + +``` +mkdir build && cd build +emcmake cmake .. -DCMAKE_CXX_COMPILER=em++ -DCMAKE_C_COMPILER=emcc -DTBB_STRICT=OFF -DCMAKE_CXX_FLAGS=-Wno-unused-command-line-argument -DTBB_DISABLE_HWLOC_AUTOMATIC_SEARCH=ON -DBUILD_SHARED_LIBS=ON -DTBB_EXAMPLES=ON -DTBB_TEST=ON +cmake --build . +cmake --install . +``` + +Where: + +* ``emcmake`` - a tool that sets up the environment for Emscripten*. +* ``-DCMAKE_CXX_COMPILER=em++`` - specifies the C++ compiler as Emscripten* C++ compiler. +* ``-DCMAKE_C_COMPILER=emcc`` - specifies the C compiler as Emscripten* C compiler. + -WebAssembly aims to provide a fast, efficient, and safe way to run code in web browsers without needing plugins or other software. Code written in a variety of programming languages, including C, C++, Rust and others, can be compiled into WebAssembly format for use in web pages. This allows you to write high-performance applications that run directly in the browser. +> **_NOTE:_** See [CMake documentation](https://github.com/oneapi-src/oneTBB/blob/master/cmake/README.md) to learn about other options. -We currently have an [under development branch that provides you with WASM support](https://github.com/oneapi-src/oneTBB/tree/tbb_wasm). -By using WASM, you can: -* Create highly performant and scalable applications that can meet the demands of modern web-based systems. -* Take advantage of oneTBB features to optimize the performance of your web-based applications. +## Run Test +To run tests, use: +``` +ctest +``` diff --git a/cmake/README.md b/cmake/README.md index ff37ad8e44..9a68f730f3 100644 --- a/cmake/README.md +++ b/cmake/README.md @@ -14,6 +14,7 @@ TBBMALLOC_BUILD:BOOL - Enable Intel(R) oneAPI Threading Building Blocks (oneTBB) TBBMALLOC_PROXY_BUILD:BOOL - Enable Intel(R) oneAPI Threading Building Blocks (oneTBB) memory allocator proxy build (requires TBBMALLOC_BUILD. ON by default) TBB4PY_BUILD:BOOL - Enable Intel(R) oneAPI Threading Building Blocks (oneTBB) Python module build (OFF by default) TBB_CPF:BOOL - Enable preview features of the library (OFF by default) +TBB_INSTALL:BOOL - Enable installation (ON by default) TBB_INSTALL_VARS:BOOL - Enable auto-generated vars installation(packages generated by `cpack` and `make install` will also include the vars script)(OFF by default) TBB_VALGRIND_MEMCHECK:BOOL - Enable scan for memory leaks using Valgrind (OFF by default) TBB_DISABLE_HWLOC_AUTOMATIC_SEARCH - Disable HWLOC automatic search by pkg-config tool (OFF by default) diff --git a/cmake/compilers/Clang.cmake b/cmake/compilers/Clang.cmake index 7ce4d46deb..330dffa277 100644 --- a/cmake/compilers/Clang.cmake +++ b/cmake/compilers/Clang.cmake @@ -52,7 +52,7 @@ if (NOT TBB_STRICT AND COMMAND tbb_remove_compile_flag) endif() # Enable Intel(R) Transactional Synchronization Extensions (-mrtm) and WAITPKG instructions support (-mwaitpkg) on relevant processors -if (CMAKE_SYSTEM_PROCESSOR MATCHES "(AMD64|amd64|i.86|x86)") +if (CMAKE_SYSTEM_PROCESSOR MATCHES "(AMD64|amd64|i.86|x86)" AND NOT EMSCRIPTEN) set(TBB_COMMON_COMPILE_FLAGS ${TBB_COMMON_COMPILE_FLAGS} -mrtm $<$>:-mwaitpkg>) endif() diff --git a/cmake/compilers/GNU.cmake b/cmake/compilers/GNU.cmake index 08c7f2e530..871b72a712 100644 --- a/cmake/compilers/GNU.cmake +++ b/cmake/compilers/GNU.cmake @@ -71,8 +71,8 @@ endif () set(TBB_COMMON_COMPILE_FLAGS ${TBB_COMMON_COMPILE_FLAGS} -fno-strict-overflow -fno-delete-null-pointer-checks -fwrapv) set(TBB_COMMON_COMPILE_FLAGS ${TBB_COMMON_COMPILE_FLAGS} -Wformat -Wformat-security -Werror=format-security -fstack-protector-strong ) -# -z switch is not supported on MacOS -if (NOT APPLE) +# -z switch is not supported on MacOS and MinGW +if (NOT APPLE AND NOT MINGW) set(TBB_LIB_LINK_FLAGS ${TBB_LIB_LINK_FLAGS} -Wl,-z,relro,-z,now,-z,noexecstack) endif() set(TBB_COMMON_COMPILE_FLAGS ${TBB_COMMON_COMPILE_FLAGS} $<$>:-D_FORTIFY_SOURCE=2> ) diff --git a/cmake/compilers/IntelLLVM.cmake b/cmake/compilers/IntelLLVM.cmake index 89d56ae620..a9ebb3e670 100644 --- a/cmake/compilers/IntelLLVM.cmake +++ b/cmake/compilers/IntelLLVM.cmake @@ -1,4 +1,4 @@ -# Copyright (c) 2020-2021 Intel Corporation +# Copyright (c) 2020-2023 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -14,10 +14,12 @@ if (WIN32) include(${CMAKE_CURRENT_LIST_DIR}/MSVC.cmake) + set(TBB_OPENMP_FLAG /Qopenmp) set(TBB_IPO_COMPILE_FLAGS $<$>:/Qipo>) set(TBB_IPO_LINK_FLAGS $<$>:/INCREMENTAL:NO>) else() include(${CMAKE_CURRENT_LIST_DIR}/Clang.cmake) set(TBB_IPO_COMPILE_FLAGS $<$>:-ipo>) + set(TBB_OPENMP_FLAG -qopenmp) endif() set(TBB_IPO_LINK_FLAGS ${TBB_IPO_LINK_FLAGS} ${TBB_IPO_COMPILE_FLAGS}) diff --git a/cmake/compilers/MSVC.cmake b/cmake/compilers/MSVC.cmake index 0e0dfd31aa..addb15ca46 100644 --- a/cmake/compilers/MSVC.cmake +++ b/cmake/compilers/MSVC.cmake @@ -33,7 +33,7 @@ if (MSVC_VERSION LESS_EQUAL 1900) set(TBB_TEST_COMPILE_FLAGS ${TBB_TEST_COMPILE_FLAGS} /wd4503) endif() set(TBB_LIB_COMPILE_FLAGS -D_CRT_SECURE_NO_WARNINGS /GS) -set(TBB_COMMON_COMPILE_FLAGS /volatile:iso /FS /EHsc) +set(TBB_COMMON_COMPILE_FLAGS ${TBB_COMMON_COMPILE_FLAGS} /volatile:iso /FS /EHsc) set(TBB_LIB_LINK_FLAGS ${TBB_LIB_LINK_FLAGS} /DYNAMICBASE /NXCOMPAT) diff --git a/cmake/config_generation.cmake b/cmake/config_generation.cmake index 0cbdd7450f..e4ef7bcead 100644 --- a/cmake/config_generation.cmake +++ b/cmake/config_generation.cmake @@ -92,6 +92,7 @@ set(_tbbbind_bin_version ${tbb_gen_cfg_TBBBIND_BINARY_VERSION}) NAMES \${_tbb_component}\${_bin_version}.dll PATHS \${_tbb_root} PATH_SUFFIXES \"redist/\${_tbb_intel_arch}/\${_tbb_subdir}\" \"bin\${_tbb_arch_suffix}/\${_tbb_subdir}\" \"bin\${_tbb_arch_suffix}/\" \"bin\" + NO_DEFAULT_PATH ) if (EXISTS \"\${_tbb_debug_lib}\") @@ -99,6 +100,7 @@ set(_tbbbind_bin_version ${tbb_gen_cfg_TBBBIND_BINARY_VERSION}) NAMES \${_tbb_component}\${_bin_version}_debug.dll PATHS \${_tbb_root} PATH_SUFFIXES \"redist/\${_tbb_intel_arch}/\${_tbb_subdir}\" \"bin\${_tbb_arch_suffix}/\${_tbb_subdir}\" \"bin\${_tbb_arch_suffix}/\" \"bin\" + NO_DEFAULT_PATH ) endif() ") diff --git a/cmake/hwloc_detection.cmake b/cmake/hwloc_detection.cmake index 47233b1773..aaca5a599c 100644 --- a/cmake/hwloc_detection.cmake +++ b/cmake/hwloc_detection.cmake @@ -1,4 +1,4 @@ -# Copyright (c) 2020-2021 Intel Corporation +# Copyright (c) 2020-2023 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -46,8 +46,6 @@ endforeach() unset(HWLOC_TARGET_NAME) if (NOT HWLOC_TARGET_EXPLICITLY_DEFINED AND - # No hwloc auto detection for cross compilation - NOT CMAKE_CROSSCOMPILING AND NOT TBB_DISABLE_HWLOC_AUTOMATIC_SEARCH ) find_package(PkgConfig QUIET) diff --git a/cmake/templates/TBBConfig.cmake.in b/cmake/templates/TBBConfig.cmake.in index 18ac68d3c1..3131e3dd7c 100644 --- a/cmake/templates/TBBConfig.cmake.in +++ b/cmake/templates/TBBConfig.cmake.in @@ -65,6 +65,7 @@ foreach (_tbb_component ${TBB_FIND_COMPONENTS}) NAMES @TBB_LIB_PREFIX@${_tbb_component}${_bin_version}.@TBB_LIB_EXT@ PATHS ${_tbb_root} PATH_SUFFIXES "@TBB_LIB_REL_PATH@/${_tbb_intel_arch}/${_tbb_subdir}" "@TBB_LIB_REL_PATH@${_tbb_arch_suffix}/${_tbb_subdir}" "@TBB_LIB_REL_PATH@${_tbb_arch_suffix}" "@TBB_LIB_REL_PATH@" + NO_DEFAULT_PATH ) if (NOT TBB_FIND_RELEASE_ONLY) @@ -72,6 +73,7 @@ foreach (_tbb_component ${TBB_FIND_COMPONENTS}) NAMES @TBB_LIB_PREFIX@${_tbb_component}${_bin_version}_debug.@TBB_LIB_EXT@ PATHS ${_tbb_root} PATH_SUFFIXES "@TBB_LIB_REL_PATH@/${_tbb_intel_arch}/${_tbb_subdir}" "@TBB_LIB_REL_PATH@${_tbb_arch_suffix}/${_tbb_subdir}" "@TBB_LIB_REL_PATH@${_tbb_arch_suffix}" "@TBB_LIB_REL_PATH@" + NO_DEFAULT_PATH ) endif() diff --git a/cmake/utils.cmake b/cmake/utils.cmake index 982a633fdb..078a0c742b 100644 --- a/cmake/utils.cmake +++ b/cmake/utils.cmake @@ -23,31 +23,33 @@ macro(tbb_remove_compile_flag flag) endmacro() macro(tbb_install_target target) - install(TARGETS ${target} - EXPORT TBBTargets - LIBRARY - DESTINATION ${CMAKE_INSTALL_LIBDIR} - NAMELINK_SKIP - COMPONENT runtime - RUNTIME - DESTINATION ${CMAKE_INSTALL_BINDIR} - COMPONENT runtime - ARCHIVE - DESTINATION ${CMAKE_INSTALL_LIBDIR} - COMPONENT devel) - - if (BUILD_SHARED_LIBS) + if (TBB_INSTALL) install(TARGETS ${target} + EXPORT TBBTargets LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} - NAMELINK_ONLY + NAMELINK_SKIP + COMPONENT runtime + RUNTIME + DESTINATION ${CMAKE_INSTALL_BINDIR} + COMPONENT runtime + ARCHIVE + DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT devel) - endif() - if (MSVC AND BUILD_SHARED_LIBS) - install(FILES $ - DESTINATION ${CMAKE_INSTALL_BINDIR} - COMPONENT devel - OPTIONAL) + + if (BUILD_SHARED_LIBS) + install(TARGETS ${target} + LIBRARY + DESTINATION ${CMAKE_INSTALL_LIBDIR} + NAMELINK_ONLY + COMPONENT devel) + endif() + if (MSVC AND BUILD_SHARED_LIBS) + install(FILES $ + DESTINATION ${CMAKE_INSTALL_BINDIR} + COMPONENT devel + OPTIONAL) + endif() endif() endmacro() diff --git a/doc/conf.py b/doc/conf.py index 87593ebfea..19da0a4caf 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -137,10 +137,14 @@ 'use_issues_button': True, 'use_edit_page_button': True, 'repository_branch': 'master', - 'extra_footer': '

Cookies

' } +if BUILD_TYPE != 'oneapi' and BUILD_TYPE != 'dita': + html_theme_options = { + "extra_footer": "
© Intel Corporation. Intel, the Intel logo, and other Intel marks are trademarks of Intel Corporation or its subsidiaries. Other names and brands may be claimed as the property of others. No license (express or implied, by estoppel or otherwise) to any intellectual property rights is granted by this document, with the sole exception that code included in this document is licensed subject to the Zero-Clause BSD open source license (OBSD), http://opensource.org/licenses/0BSD.

oneTBB is licensed under Apache License Version 2.0. Refer to the LICENSE file for the full license text and copyright notice.
" + } + # Add any paths that contain custom static files (such as style sheets) here, # relative to this directory. They are copied after the builtin static files, # so a file named "default.css" will overwrite the builtin "default.css". diff --git a/doc/main/intro/Benefits.rst b/doc/main/intro/Benefits.rst index b66ea5d1ac..5058cc71e5 100644 --- a/doc/main/intro/Benefits.rst +++ b/doc/main/intro/Benefits.rst @@ -20,7 +20,7 @@ it with any compiler supporting ISO C++. The library differs from typical threading packages in the following ways: -- **oneTBB enables you to specify logical paralleism instead of +- **oneTBB enables you to specify logical parallelism instead of threads**. Most threading packages require you to specify threads. Programming directly in terms of threads can be tedious and lead to inefficient programs, because threads are low-level, heavy constructs diff --git a/doc/main/tbb_userguide/Flow_Graph_Reservation.rst b/doc/main/tbb_userguide/Flow_Graph_Reservation.rst index 8487c449d6..44fc2f0a98 100644 --- a/doc/main/tbb_userguide/Flow_Graph_Reservation.rst +++ b/doc/main/tbb_userguide/Flow_Graph_Reservation.rst @@ -63,7 +63,7 @@ messages and do not support ``try_get()`` or ``try_reserve()``. broadcast_node bn(g); buffer_node buf1(g); buffer_node buf2(g); - typedef join_node reserving> join_type; + typedef join_node, reserving> join_type; join_type jn(g); buffer_node buf_out(g); join_type::output_type tuple_out; @@ -71,9 +71,9 @@ messages and do not support ``try_get()`` or ``try_reserve()``. // join_node predecessors are both reservable buffer_nodes - make_edge(buf1,input_port<0>jn)); - make_edge(bn,input_port<0>jn)); // attach a broadcast_node - make_edge(buf2,input_port<1>jn)); + make_edge(buf1,input_port<0>(jn)); + make_edge(bn,input_port<0>(jn)); // attach a broadcast_node + make_edge(buf2,input_port<1>(jn)); make_edge(jn, buf_out); bn.try_put(2); buf1.try_put(3); @@ -81,7 +81,7 @@ messages and do not support ``try_get()`` or ``try_reserve()``. buf2.try_put(7); g.wait_for_all(); while (buf_out.try_get(tuple_out)) { - printf("join_node output == (%d,%d)\n",get<0>tuple_out), get<1>tuple_out) ); + printf("join_node output == (%d,%d)\n",get<0>(tuple_out), get<1>(tuple_out) ); } if(buf1.try_get(icnt)) printf("buf1 had %d\n", icnt); else printf("buf1 was empty\n"); diff --git a/doc/main/tbb_userguide/Migration_Guide/Mixing_Two_Runtimes.rst b/doc/main/tbb_userguide/Migration_Guide/Mixing_Two_Runtimes.rst index 57582aacad..8d467fb620 100644 --- a/doc/main/tbb_userguide/Migration_Guide/Mixing_Two_Runtimes.rst +++ b/doc/main/tbb_userguide/Migration_Guide/Mixing_Two_Runtimes.rst @@ -46,3 +46,4 @@ TBB possible output: TBB: RML private TBB: Tools support disabled +.. note:: The ``tbbmalloc`` library in oneTBB is fully binary compatible with TBB. diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 979998c66a..16f1c4552a 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -cmake_minimum_required(VERSION 3.1) +cmake_minimum_required(VERSION 3.5) project(tbb_examples CXX) @@ -66,6 +66,7 @@ tbb_add_example(parallel_for_each parallel_preorder) tbb_add_example(parallel_pipeline square) tbb_add_example(parallel_reduce convex_hull) +tbb_add_example(parallel_reduce pi) tbb_add_example(parallel_reduce primes) tbb_add_example(task_arena fractal) diff --git a/examples/README.md b/examples/README.md index 318d2d93da..037ca4d4e3 100644 --- a/examples/README.md +++ b/examples/README.md @@ -19,6 +19,7 @@ This directory contains example usages of oneAPI Threading Building Blocks. | parallel_for_each/parallel_preorder | Parallel preorder traversal of a graph. | parallel_pipeline/square | Another string transformation example that squares numbers read from a file. | parallel_reduce/convex_hull | Parallel version of convex hull algorithm (quick hull). +| parallel_reduce/pi | Parallel version of calculating π by numerical integration. | parallel_reduce/primes | Parallel version of the Sieve of Eratosthenes. | task_arena/fractal |The example calculates two classical Mandelbrot fractals with different concurrency limits. | task_group/sudoku | Compute all solutions for a Sudoku board. diff --git a/examples/common/gui/CMakeLists.txt b/examples/common/gui/CMakeLists.txt index 8bee0a83c2..ea8b0060aa 100644 --- a/examples/common/gui/CMakeLists.txt +++ b/examples/common/gui/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (c) 2020-2021 Intel Corporation +# Copyright (c) 2020-2023 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -cmake_minimum_required(VERSION 3.1) +cmake_minimum_required(VERSION 3.5) set(EXAMPLES_UI_MODE "con" CACHE STRING "EXAMPLES_UI_MODE") diff --git a/examples/concurrent_hash_map/count_strings/CMakeLists.txt b/examples/concurrent_hash_map/count_strings/CMakeLists.txt index 14d25fa7a0..77efd2f66f 100644 --- a/examples/concurrent_hash_map/count_strings/CMakeLists.txt +++ b/examples/concurrent_hash_map/count_strings/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (c) 2020-2021 Intel Corporation +# Copyright (c) 2020-2023 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -cmake_minimum_required(VERSION 3.1) +cmake_minimum_required(VERSION 3.5) project(count_strings CXX) diff --git a/examples/concurrent_priority_queue/shortpath/CMakeLists.txt b/examples/concurrent_priority_queue/shortpath/CMakeLists.txt index 8a6d78a01c..624a59285f 100644 --- a/examples/concurrent_priority_queue/shortpath/CMakeLists.txt +++ b/examples/concurrent_priority_queue/shortpath/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (c) 2020-2021 Intel Corporation +# Copyright (c) 2020-2023 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -cmake_minimum_required(VERSION 3.1) +cmake_minimum_required(VERSION 3.5) project(shortpath CXX) diff --git a/examples/getting_started/sub_string_finder/CMakeLists.txt b/examples/getting_started/sub_string_finder/CMakeLists.txt index cf4e6a1bbb..91792dde1d 100644 --- a/examples/getting_started/sub_string_finder/CMakeLists.txt +++ b/examples/getting_started/sub_string_finder/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (c) 2020-2021 Intel Corporation +# Copyright (c) 2020-2023 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -cmake_minimum_required(VERSION 3.1) +cmake_minimum_required(VERSION 3.5) project(sub_string_finder_simple CXX) project(sub_string_finder_extended CXX) diff --git a/examples/graph/binpack/CMakeLists.txt b/examples/graph/binpack/CMakeLists.txt index 5fc979a558..3d3b79215a 100644 --- a/examples/graph/binpack/CMakeLists.txt +++ b/examples/graph/binpack/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (c) 2020-2021 Intel Corporation +# Copyright (c) 2020-2023 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -cmake_minimum_required(VERSION 3.1) +cmake_minimum_required(VERSION 3.5) project(binpack CXX) diff --git a/examples/graph/cholesky/CMakeLists.txt b/examples/graph/cholesky/CMakeLists.txt index eeb2649a25..2e8273ae71 100644 --- a/examples/graph/cholesky/CMakeLists.txt +++ b/examples/graph/cholesky/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (c) 2020-2021 Intel Corporation +# Copyright (c) 2020-2023 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -cmake_minimum_required(VERSION 3.1) +cmake_minimum_required(VERSION 3.5) project(cholesky CXX) diff --git a/examples/graph/dining_philosophers/CMakeLists.txt b/examples/graph/dining_philosophers/CMakeLists.txt index 95f7a483a2..d46af59b1d 100644 --- a/examples/graph/dining_philosophers/CMakeLists.txt +++ b/examples/graph/dining_philosophers/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (c) 2020-2021 Intel Corporation +# Copyright (c) 2020-2023 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -cmake_minimum_required(VERSION 3.1) +cmake_minimum_required(VERSION 3.5) project(dining_philosophers CXX) diff --git a/examples/graph/fgbzip2/CMakeLists.txt b/examples/graph/fgbzip2/CMakeLists.txt index a2034edb73..7a9142a52c 100644 --- a/examples/graph/fgbzip2/CMakeLists.txt +++ b/examples/graph/fgbzip2/CMakeLists.txt @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -cmake_minimum_required(VERSION 3.1) +cmake_minimum_required(VERSION 3.5) project(fgbzip2 CXX) diff --git a/examples/graph/logic_sim/CMakeLists.txt b/examples/graph/logic_sim/CMakeLists.txt index b33f915648..99e1cc8f0b 100644 --- a/examples/graph/logic_sim/CMakeLists.txt +++ b/examples/graph/logic_sim/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (c) 2020-2021 Intel Corporation +# Copyright (c) 2020-2023 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -cmake_minimum_required(VERSION 3.1) +cmake_minimum_required(VERSION 3.5) project(logic_sim CXX) diff --git a/examples/graph/som/CMakeLists.txt b/examples/graph/som/CMakeLists.txt index 6e7593313b..c2dd1a8088 100644 --- a/examples/graph/som/CMakeLists.txt +++ b/examples/graph/som/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (c) 2020-2021 Intel Corporation +# Copyright (c) 2020-2023 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -cmake_minimum_required(VERSION 3.1) +cmake_minimum_required(VERSION 3.5) include(../../common/cmake/common.cmake) project(som CXX) diff --git a/examples/migration/recursive_fibonacci/CMakeLists.txt b/examples/migration/recursive_fibonacci/CMakeLists.txt index 5032da2330..57e027cfbf 100644 --- a/examples/migration/recursive_fibonacci/CMakeLists.txt +++ b/examples/migration/recursive_fibonacci/CMakeLists.txt @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -cmake_minimum_required(VERSION 3.1) +cmake_minimum_required(VERSION 3.5) project(recursive_fibonacci CXX) @@ -33,7 +33,7 @@ set(EXECUTABLE "$") # `N` - specifies the fibonacci number which would be calculated. # `C` - cutoff that will be used to stop recursive split. # `I` - number of iteration to measure benchmark time. -set(ARGS 30 16 20) +set(ARGS 30 16 20 1) set(PERF_ARGS 50 5 20) add_execution_target(run_recursive_fibonacci recursive_fibonacci ${EXECUTABLE} "${ARGS}") diff --git a/examples/migration/recursive_fibonacci/README.md b/examples/migration/recursive_fibonacci/README.md index bc66c5d814..1f0341c1ea 100644 --- a/examples/migration/recursive_fibonacci/README.md +++ b/examples/migration/recursive_fibonacci/README.md @@ -9,14 +9,15 @@ cmake --build . ## Running the sample ### Predefined make targets -* `make run_recursive_fibonacci` - executes the example with predefined parameters. +* `make run_recursive_fibonacci` - executes the example with predefined parameters (extended testing enabled). * `make perf_run_recursive_fibonacci` - executes the example with suggested parameters to measure the oneTBB performance. ### Application parameters Usage: ``` -recursive_fibonacci N C I +recursive_fibonacci N C I T ``` * `N` - specifies the fibonacci number which would be calculated. * `C` - cutoff that will be used to stop recursive split. * `I` - number of iteration to measure benchmark time. +* `T` - enables extended testing (recycle task in a loop). diff --git a/examples/migration/recursive_fibonacci/fibonacci.cpp b/examples/migration/recursive_fibonacci/fibonacci.cpp index acf22a497a..e4a7c12eb7 100644 --- a/examples/migration/recursive_fibonacci/fibonacci.cpp +++ b/examples/migration/recursive_fibonacci/fibonacci.cpp @@ -22,6 +22,7 @@ #include int cutoff; +bool testing_enabled; template std::pair measure(F&& f, @@ -48,6 +49,7 @@ int main(int argc, char* argv[]) { int numbers = argc > 1 ? strtol(argv[1], nullptr, 0) : 50; cutoff = argc > 2 ? strtol(argv[2], nullptr, 0) : 16; unsigned long ntrial = argc > 3 ? (unsigned long)strtoul(argv[3], nullptr, 0) : 20; + testing_enabled = argc > 4 ? (bool)strtol(argv[4], nullptr, 0) : false; auto res = measure(fibonacci_two_tasks, numbers, ntrial); std::cout << "Fibonacci two tasks impl N = " << res.first << " Avg time = " << res.second diff --git a/examples/migration/recursive_fibonacci/fibonacci_single_task.h b/examples/migration/recursive_fibonacci/fibonacci_single_task.h index 2467f862b0..dae8895b8c 100644 --- a/examples/migration/recursive_fibonacci/fibonacci_single_task.h +++ b/examples/migration/recursive_fibonacci/fibonacci_single_task.h @@ -24,6 +24,7 @@ #include extern int cutoff; +extern bool testing_enabled; long serial_fib_1(int n) { return n < 2 ? n : serial_fib_1(n - 1) + serial_fib_1(n - 2); @@ -38,39 +39,43 @@ struct single_fib_task : task_emulation::base_task { single_fib_task(int n, int* x) : n(n), x(x), s(state::compute) {} - void execute() override { + task_emulation::base_task* execute() override { + task_emulation::base_task* bypass = nullptr; switch (s) { case state::compute : { - compute_impl(); + bypass = compute_impl(); break; } case state::sum : { *x = x_l + x_r; + + if (testing_enabled) { + if (n == cutoff && num_recycles > 0) { + --num_recycles; + bypass = compute_impl(); + } + } + break; } } + return bypass; } - void compute_impl() { + task_emulation::base_task* compute_impl() { + task_emulation::base_task* bypass = nullptr; if (n < cutoff) { *x = serial_fib_1(n); } else { - auto bypass = this->allocate_child_and_increment(n - 2, &x_r); + bypass = this->allocate_child_and_increment(n - 2, &x_r); task_emulation::run_task(this->allocate_child_and_increment(n - 1, &x_l)); // Recycling this->s = state::sum; this->recycle_as_continuation(); - - // Bypass is not supported by task_emulation and next_task executed directly. - // However, the old-TBB bypass behavior can be achieved with - // `return task_group::defer()` (check Migration Guide). - // Consider submit another task if recursion call is not acceptable - // i.e. instead of Direct Body call - // submit task_emulation::run_task(this->allocate_child_and_increment(n - 2, &x_r)); - bypass->operator()(); } + return bypass; } @@ -79,6 +84,7 @@ struct single_fib_task : task_emulation::base_task { state s; int x_l{ 0 }, x_r{ 0 }; + int num_recycles{5}; }; int fibonacci_single_task(int n) { diff --git a/examples/migration/recursive_fibonacci/fibonacci_two_tasks.h b/examples/migration/recursive_fibonacci/fibonacci_two_tasks.h index 9123662522..5d7fd02292 100644 --- a/examples/migration/recursive_fibonacci/fibonacci_two_tasks.h +++ b/examples/migration/recursive_fibonacci/fibonacci_two_tasks.h @@ -33,8 +33,9 @@ long serial_fib(int n) { struct fib_continuation : task_emulation::base_task { fib_continuation(int& s) : sum(s) {} - void execute() override { + task_emulation::base_task* execute() override { sum = x + y; + return nullptr; } int x{ 0 }, y{ 0 }; @@ -44,7 +45,8 @@ struct fib_continuation : task_emulation::base_task { struct fib_computation : task_emulation::base_task { fib_computation(int n, int* x) : n(n), x(x) {} - void execute() override { + task_emulation::base_task* execute() override { + task_emulation::base_task* bypass = nullptr; if (n < cutoff) { *x = serial_fib(n); } @@ -57,15 +59,9 @@ struct fib_computation : task_emulation::base_task { this->recycle_as_child_of(c); n = n - 2; x = &c.y; - - // Bypass is not supported by task_emulation and next_task executed directly. - // However, the old-TBB bypass behavior can be achieved with - // `return task_group::defer()` (check Migration Guide). - // Consider submit another task if recursion call is not acceptable - // i.e. instead of Recycling + Direct Body call - // submit task_emulation::run_task(c.create_child(n - 2, &c.y)); - this->operator()(); + bypass = this; } + return bypass; } int n; diff --git a/examples/migration/recursive_fibonacci/task_emulation_layer.h b/examples/migration/recursive_fibonacci/task_emulation_layer.h index 3a38712765..7252d447a0 100644 --- a/examples/migration/recursive_fibonacci/task_emulation_layer.h +++ b/examples/migration/recursive_fibonacci/task_emulation_layer.h @@ -47,32 +47,45 @@ class base_task { public: base_task() = default; - base_task(const base_task& t) : m_parent(t.m_parent), m_child_counter(t.m_child_counter.load()) + base_task(const base_task& t) : m_type(t.m_type), m_parent(t.m_parent), m_child_counter(t.m_child_counter.load()) {} virtual ~base_task() = default; void operator() () const { - base_task* parent_snapshot = m_parent; - const_cast(this)->execute(); - if (m_parent && parent_snapshot == m_parent && m_child_counter == 0) { - if (m_parent->remove_reference() == 0) { + task_type type_snapshot = m_type; + + base_task* bypass = const_cast(this)->execute(); + + if (m_parent && m_type != task_type::recycled) { + if (m_parent->remove_child_reference() == 0) { m_parent->operator()(); - delete m_parent; } } - if (m_child_counter == 0 && m_type == task_type::allocated) { + if (m_type == task_type::allocated) { delete this; } + + if (bypass != nullptr) { + m_type = type_snapshot; + + // Bypass is not supported by task_emulation and next_task executed directly. + // However, the old-TBB bypass behavior can be achieved with + // `return task_group::defer()` (check Migration Guide). + // Consider submit another task if recursion call is not acceptable + // i.e. instead of Direct Body call + // submit task_emulation::run_task(); + bypass->operator()(); + } } - virtual void execute() = 0; + virtual base_task* execute() = 0; template C* allocate_continuation(std::uint64_t ref, Args&&... args) { C* continuation = new C{std::forward(args)...}; - continuation->m_type = task_type::continuation; + continuation->m_type = task_type::allocated; continuation->reset_parent(reset_parent()); continuation->m_child_counter = ref; return continuation; @@ -85,7 +98,7 @@ class base_task { template F create_child_and_increment(Args&&... args) { - add_reference(); + add_child_reference(); return create_child_impl(std::forward(args)...); } @@ -96,35 +109,36 @@ class base_task { template F* allocate_child_and_increment(Args&&... args) { - add_reference(); + add_child_reference(); return allocate_child_impl(std::forward(args)...); } template void recycle_as_child_of(C& c) { + m_type = task_type::recycled; reset_parent(&c); } void recycle_as_continuation() { - m_type = task_type::continuation; + m_type = task_type::recycled; } - void add_reference() { + void add_child_reference() { ++m_child_counter; } - std::uint64_t remove_reference() { + std::uint64_t remove_child_reference() { return --m_child_counter; } protected: enum class task_type { - created, + stack_based, allocated, - continuation + recycled }; - task_type m_type; + mutable task_type m_type; private: template @@ -136,7 +150,7 @@ class base_task { template F create_child_impl(Args&&... args) { F obj{std::forward(args)...}; - obj.m_type = task_type::created; + obj.m_type = task_type::stack_based; obj.reset_parent(this); return obj; } @@ -162,13 +176,14 @@ class base_task { class root_task : public base_task { public: root_task(tbb::task_group& tg) : m_tg(tg), m_callback(m_tg.defer([] { /* Create empty callback to preserve reference for wait. */})) { - add_reference(); - m_type = base_task::task_type::continuation; + add_child_reference(); + m_type = base_task::task_type::allocated; } private: - void execute() override { + base_task* execute() override { m_tg.run(std::move(m_callback)); + return nullptr; } tbb::task_group& m_tg; @@ -178,7 +193,7 @@ class root_task : public base_task { template F create_root_task(tbb::task_group& tg, Args&&... args) { F obj{std::forward(args)...}; - obj.m_type = base_task::task_type::created; + obj.m_type = base_task::task_type::stack_based; obj.reset_parent(new root_task{tg}); return obj; } diff --git a/examples/parallel_for/game_of_life/CMakeLists.txt b/examples/parallel_for/game_of_life/CMakeLists.txt index 47f7ca7b91..596342424c 100644 --- a/examples/parallel_for/game_of_life/CMakeLists.txt +++ b/examples/parallel_for/game_of_life/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (c) 2020-2021 Intel Corporation +# Copyright (c) 2020-2023 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -cmake_minimum_required(VERSION 3.1) +cmake_minimum_required(VERSION 3.5) project(game_of_life CXX) diff --git a/examples/parallel_for/polygon_overlay/CMakeLists.txt b/examples/parallel_for/polygon_overlay/CMakeLists.txt index cb0475e275..a45aaa6824 100644 --- a/examples/parallel_for/polygon_overlay/CMakeLists.txt +++ b/examples/parallel_for/polygon_overlay/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (c) 2020-2021 Intel Corporation +# Copyright (c) 2020-2023 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -cmake_minimum_required(VERSION 3.1) +cmake_minimum_required(VERSION 3.5) project(polygon_overlay CXX) diff --git a/examples/parallel_for/seismic/CMakeLists.txt b/examples/parallel_for/seismic/CMakeLists.txt index 9236176b97..61675f19a5 100644 --- a/examples/parallel_for/seismic/CMakeLists.txt +++ b/examples/parallel_for/seismic/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (c) 2020-2021 Intel Corporation +# Copyright (c) 2020-2023 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -cmake_minimum_required(VERSION 3.1) +cmake_minimum_required(VERSION 3.5) project(seismic CXX) diff --git a/examples/parallel_for/tachyon/CMakeLists.txt b/examples/parallel_for/tachyon/CMakeLists.txt index 9dc0f83cef..6cd4169bc0 100644 --- a/examples/parallel_for/tachyon/CMakeLists.txt +++ b/examples/parallel_for/tachyon/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (c) 2020-2021 Intel Corporation +# Copyright (c) 2020-2023 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -cmake_minimum_required(VERSION 3.1) +cmake_minimum_required(VERSION 3.5) project(tachyon CXX) diff --git a/examples/parallel_for_each/parallel_preorder/CMakeLists.txt b/examples/parallel_for_each/parallel_preorder/CMakeLists.txt index 235604ab5b..8e98d3604f 100644 --- a/examples/parallel_for_each/parallel_preorder/CMakeLists.txt +++ b/examples/parallel_for_each/parallel_preorder/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (c) 2020-2021 Intel Corporation +# Copyright (c) 2020-2023 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -cmake_minimum_required(VERSION 3.1) +cmake_minimum_required(VERSION 3.5) project(parallel_preorder CXX) diff --git a/examples/parallel_pipeline/square/CMakeLists.txt b/examples/parallel_pipeline/square/CMakeLists.txt index a32eaaf81c..184c787ed9 100644 --- a/examples/parallel_pipeline/square/CMakeLists.txt +++ b/examples/parallel_pipeline/square/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (c) 2020-2021 Intel Corporation +# Copyright (c) 2020-2023 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -cmake_minimum_required(VERSION 3.1) +cmake_minimum_required(VERSION 3.5) project(square CXX) diff --git a/examples/parallel_reduce/README.md b/examples/parallel_reduce/README.md index 481d8e183f..0dba80ca99 100644 --- a/examples/parallel_reduce/README.md +++ b/examples/parallel_reduce/README.md @@ -4,4 +4,5 @@ Examples using `parallel_reduce` algorithm. | Code sample name | Description |:--- |:--- | convex_hull | Parallel version of convex hull algorithm (quick hull). +| pi | Parallel version of calculating π by numerical integration. | primes | Parallel version of the Sieve of Eratosthenes. diff --git a/examples/parallel_reduce/convex_hull/CMakeLists.txt b/examples/parallel_reduce/convex_hull/CMakeLists.txt index de32d1dedf..0492244a6a 100644 --- a/examples/parallel_reduce/convex_hull/CMakeLists.txt +++ b/examples/parallel_reduce/convex_hull/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (c) 2020-2021 Intel Corporation +# Copyright (c) 2020-2023 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -cmake_minimum_required(VERSION 3.1) +cmake_minimum_required(VERSION 3.5) project(convex_hull_bench CXX) project(convex_hull_sample CXX) diff --git a/examples/parallel_reduce/pi/CMakeLists.txt b/examples/parallel_reduce/pi/CMakeLists.txt new file mode 100644 index 0000000000..62ebe022f7 --- /dev/null +++ b/examples/parallel_reduce/pi/CMakeLists.txt @@ -0,0 +1,33 @@ +# Copyright (c) 2023 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +cmake_minimum_required(VERSION 3.5) + +project(pi CXX) + +include(../../common/cmake/common.cmake) + +set_common_project_settings(tbb) + +add_executable(pi main.cpp pi.cpp) + +target_link_libraries(pi TBB::tbb Threads::Threads) +target_compile_options(pi PRIVATE ${TBB_CXX_STD_FLAG}) + +set(EXECUTABLE "$") +set(ARGS "") +set(PERF_ARGS auto 100000000000) + +add_execution_target(run_pi pi ${EXECUTABLE} "${ARGS}") +add_execution_target(perf_run_pi pi ${EXECUTABLE} "${PERF_ARGS}") diff --git a/examples/parallel_reduce/pi/README.md b/examples/parallel_reduce/pi/README.md new file mode 100644 index 0000000000..be7ce0d4ff --- /dev/null +++ b/examples/parallel_reduce/pi/README.md @@ -0,0 +1,24 @@ +# Pi Sample +Parallel version of calculating π by numerical integration. + +## Build +To build the sample, run the following commands: +``` +cmake +cmake --build . +``` + +## Run +### Predefined Make Targets +* `make run_pi` - executes the example with predefined parameters +* `make perf_run_pi` - executes the example with suggested parameters to measure the oneTBB performance + +### Application Parameters +You can use the following application parameters: +``` +pi [n-of-threads=value] [n-of-intervals=value] [silent] [-h] [n-of-threads [n-of-intervals]] +``` +* `-h` - prints the help for command-line options. +* `n-of-threads` - the number of threads to use. This number is specified in the low\[:high\] range format, where both ``low`` and, optionally, ``high`` are non-negative integers. You can also use ``auto`` to let the system choose a default number of threads suitable for the platform. +* `n-of-intervals` - the number of intervals to subdivide into. Must be a positive integer. +* `silent` - no output except the elapsed time. diff --git a/examples/parallel_reduce/pi/common.h b/examples/parallel_reduce/pi/common.h new file mode 100644 index 0000000000..0e316854cd --- /dev/null +++ b/examples/parallel_reduce/pi/common.h @@ -0,0 +1,51 @@ +/* + Copyright (c) 2023 Intel Corporation + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +#ifndef TBB_examples_pi_H +#define TBB_examples_pi_H + +#include + +typedef std::size_t number_t; +typedef double pi_t; + +extern const number_t chunk_size; +extern number_t num_intervals; +extern pi_t step; + +extern bool silent; + +inline pi_t pi_kernel(number_t i) { + pi_t dx = (pi_t(i) + pi_t(0.5)) * step; + return pi_t(4.0) / (pi_t(1.0) + dx * dx); +} + +inline double pi_slice_kernel(number_t slice, number_t slice_size = chunk_size) { + pi_t pi = pi_t(0.0); + for (number_t i = slice; i < slice + slice_size; ++i) { + pi += pi_kernel(i); + } + return pi; +} + +struct threading { + threading(int p); + ~threading(); +}; + +double compute_pi_parallel(); + +#endif // TBB_examples_pi_H diff --git a/examples/parallel_reduce/pi/main.cpp b/examples/parallel_reduce/pi/main.cpp new file mode 100644 index 0000000000..81690617dc --- /dev/null +++ b/examples/parallel_reduce/pi/main.cpp @@ -0,0 +1,100 @@ +/* + Copyright (c) 2023 Intel Corporation + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +#include "oneapi/tbb/tick_count.h" + +#include "common/utility/get_default_num_threads.hpp" +#include "common/utility/utility.hpp" + +#include "common.h" + +const number_t chunk_size = 4096; // Multiple of 16, to fit float datatype to a vector register. + +// number of intervals +number_t num_intervals = 1000000000; +pi_t step = pi_t(0.0); + +bool silent = false; + +double compute_pi_serial() { + double ret = 0; + + step = pi_t(1.0) / num_intervals; + + number_t tail = num_intervals % chunk_size; + number_t last = num_intervals - tail; + + for (number_t slice = 0; slice < last; slice += chunk_size) { + ret += pi_slice_kernel(slice); + } + ret += pi_slice_kernel(last, tail); + ret *= step; + + return ret; +} + +int main(int argc, char* argv[]) { + try { + tbb::tick_count main_start_time = tbb::tick_count::now(); + // zero number of threads means to run serial version + utility::thread_number_range threads(utility::get_default_num_threads, 0); + + utility::parse_cli_arguments( + argc, + argv, + utility::cli_argument_pack() + //"-h" option for for displaying help is present implicitly + .positional_arg(threads, "n-of-threads", utility::thread_number_range_desc) + .positional_arg(num_intervals, "n-of-intervals", "number of intervals") + .arg(silent, "silent", "no output except time elapsed")); + + for (int p = threads.first; p <= threads.last; p = threads.step(p)) { + pi_t pi; + double compute_time; + if (p == 0) { + //run a serial version + tbb::tick_count compute_start_time = tbb::tick_count::now(); + pi = compute_pi_serial(); + compute_time = (tbb::tick_count::now() - compute_start_time).seconds(); + } + else { + //run a parallel version + threading tp(p); + tbb::tick_count compute_start_time = tbb::tick_count::now(); + pi = compute_pi_parallel(); + compute_time = (tbb::tick_count::now() - compute_start_time).seconds(); + } + + if (!silent) { + if (p == 0) { + std::cout << "Serial run:\tpi = " << pi << "\tcompute time = " << compute_time + << " sec\n"; + } + else { + std::cout << "Parallel run:\tpi = " << pi << "\tcompute time = " << compute_time + << " sec\t on " << p << " threads\n"; + } + } + } + + utility::report_elapsed_time((tbb::tick_count::now() - main_start_time).seconds()); + return 0; + } + catch (std::exception& e) { + std::cerr << "error occurred. error text is :\"" << e.what() << "\"\n"; + return 1; + } +} diff --git a/examples/parallel_reduce/pi/pi.cpp b/examples/parallel_reduce/pi/pi.cpp new file mode 100644 index 0000000000..230752a998 --- /dev/null +++ b/examples/parallel_reduce/pi/pi.cpp @@ -0,0 +1,55 @@ +/* + Copyright (c) 2023 Intel Corporation + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +#include "common.h" +#include "oneapi/tbb/blocked_range.h" +#include "oneapi/tbb/global_control.h" +#include "oneapi/tbb/parallel_reduce.h" + +struct reduce_body { + double my_pi; + reduce_body() : my_pi(0) {} + reduce_body(reduce_body& x, tbb::split) : my_pi(0) {} + void operator()(const tbb::blocked_range& r) { + my_pi += pi_slice_kernel(r.begin(), r.size()); + } + void join(const reduce_body& y) { + my_pi += y.my_pi; + } +}; + +double compute_pi_parallel() { + step = pi_t(1.0) / num_intervals; + + double ret = 0.0; + + reduce_body body; + tbb::parallel_reduce(tbb::blocked_range(0, num_intervals), body); + + ret = body.my_pi * step; + + return ret; +} + +static std::unique_ptr gc; + +threading::threading(int p) { + gc.reset(new tbb::global_control(tbb::global_control::max_allowed_parallelism, p)); +} + +threading::~threading() { + gc.reset(); +} diff --git a/examples/parallel_reduce/primes/CMakeLists.txt b/examples/parallel_reduce/primes/CMakeLists.txt index dabd968245..987d4656cb 100644 --- a/examples/parallel_reduce/primes/CMakeLists.txt +++ b/examples/parallel_reduce/primes/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (c) 2020-2021 Intel Corporation +# Copyright (c) 2020-2023 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -cmake_minimum_required(VERSION 3.1) +cmake_minimum_required(VERSION 3.5) project(primes CXX) diff --git a/examples/task_arena/fractal/CMakeLists.txt b/examples/task_arena/fractal/CMakeLists.txt index 888428b342..857dae642e 100644 --- a/examples/task_arena/fractal/CMakeLists.txt +++ b/examples/task_arena/fractal/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (c) 2020-2021 Intel Corporation +# Copyright (c) 2020-2023 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -cmake_minimum_required(VERSION 3.1) +cmake_minimum_required(VERSION 3.5) project(fractal CXX) diff --git a/examples/task_group/sudoku/CMakeLists.txt b/examples/task_group/sudoku/CMakeLists.txt index 5fea9ee68c..f514662aba 100644 --- a/examples/task_group/sudoku/CMakeLists.txt +++ b/examples/task_group/sudoku/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (c) 2020-2021 Intel Corporation +# Copyright (c) 2020-2023 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -cmake_minimum_required(VERSION 3.1) +cmake_minimum_required(VERSION 3.5) project(sudoku CXX) diff --git a/examples/test_all/fibonacci/CMakeLists.txt b/examples/test_all/fibonacci/CMakeLists.txt index 5c97e28aeb..3b2368e06c 100644 --- a/examples/test_all/fibonacci/CMakeLists.txt +++ b/examples/test_all/fibonacci/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (c) 2019-2021 Intel Corporation +# Copyright (c) 2019-2023 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -cmake_minimum_required(VERSION 3.1) +cmake_minimum_required(VERSION 3.5) project(fibonacci CXX) diff --git a/include/oneapi/tbb/detail/_concurrent_unordered_base.h b/include/oneapi/tbb/detail/_concurrent_unordered_base.h index ade91c330f..408292086a 100644 --- a/include/oneapi/tbb/detail/_concurrent_unordered_base.h +++ b/include/oneapi/tbb/detail/_concurrent_unordered_base.h @@ -921,7 +921,7 @@ class concurrent_unordered_base { node_allocator_traits::deallocate(dummy_node_allocator, node, 1); } else { // GCC 11.1 issues a warning here that incorrect destructor might be called for dummy_nodes - #if (__TBB_GCC_VERSION >= 110100 && __TBB_GCC_VERSION < 130000 ) && !__clang__ && !__INTEL_COMPILER + #if (__TBB_GCC_VERSION >= 110100 && __TBB_GCC_VERSION < 140000 ) && !__clang__ && !__INTEL_COMPILER volatile #endif value_node_ptr val_node = static_cast(node); diff --git a/include/oneapi/tbb/enumerable_thread_specific.h b/include/oneapi/tbb/enumerable_thread_specific.h index 34bcab6821..caa53fa0d6 100644 --- a/include/oneapi/tbb/enumerable_thread_specific.h +++ b/include/oneapi/tbb/enumerable_thread_specific.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2005-2022 Intel Corporation + Copyright (c) 2005-2024 Intel Corporation Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -36,7 +36,15 @@ #include "task.h" // for task::suspend_point #if _WIN32 || _WIN64 +#ifndef NOMINMAX +#define NOMINMAX +#define __TBB_DEFINED_NOMINMAX 1 +#endif #include +#if __TBB_DEFINED_NOMINMAX +#undef NOMINMAX +#undef __TBB_DEFINED_NOMINMAX +#endif #else #include #endif diff --git a/include/oneapi/tbb/parallel_for_each.h b/include/oneapi/tbb/parallel_for_each.h index 56dbeb4101..ab0b345388 100644 --- a/include/oneapi/tbb/parallel_for_each.h +++ b/include/oneapi/tbb/parallel_for_each.h @@ -407,6 +407,34 @@ class parallel_for_body_wrapper { template using tag = typename std::iterator_traits::iterator_category; +#if __TBB_CPP20_PRESENT +template +struct move_iterator_dispatch_helper { + using type = It; +}; + +// Until C++23, std::move_iterator::iterator_concept always defines +// to std::input_iterator_tag and hence std::forward_iterator concept +// always evaluates to false, so std::move_iterator dispatch should be +// made according to the base iterator type. +template +struct move_iterator_dispatch_helper> { + using type = It; +}; + +template +using iterator_tag_dispatch_impl = + std::conditional_t, + std::random_access_iterator_tag, + std::conditional_t, + std::forward_iterator_tag, + std::input_iterator_tag>>; + +template +using iterator_tag_dispatch = + iterator_tag_dispatch_impl::type>; + +#else template using iterator_tag_dispatch = typename std::conditional< @@ -418,6 +446,7 @@ using iterator_tag_dispatch = typename std::input_iterator_tag >::type >::type; +#endif // __TBB_CPP20_PRESENT template using feeder_is_required = tbb::detail::void_t(), diff --git a/include/oneapi/tbb/version.h b/include/oneapi/tbb/version.h index db4f5f203f..52ab98e7bc 100644 --- a/include/oneapi/tbb/version.h +++ b/include/oneapi/tbb/version.h @@ -29,18 +29,22 @@ // Product version #define TBB_VERSION_MAJOR 2021 // Update version -#define TBB_VERSION_MINOR 11 +#define TBB_VERSION_MINOR 12 // "Patch" version for custom releases #define TBB_VERSION_PATCH 0 // Suffix string #define __TBB_VERSION_SUFFIX "" // Full official version string -#define TBB_VERSION_STRING __TBB_STRING(TBB_VERSION_MAJOR) "." __TBB_STRING(TBB_VERSION_MINOR) __TBB_VERSION_SUFFIX +#define TBB_VERSION_STRING \ + __TBB_STRING(TBB_VERSION_MAJOR) "." \ + __TBB_STRING(TBB_VERSION_MINOR) "." \ + __TBB_STRING(TBB_VERSION_PATCH) \ + __TBB_VERSION_SUFFIX // OneAPI oneTBB specification version #define ONETBB_SPEC_VERSION "1.0" // Full interface version -#define TBB_INTERFACE_VERSION 12110 +#define TBB_INTERFACE_VERSION 12120 // Major interface version #define TBB_INTERFACE_VERSION_MAJOR (TBB_INTERFACE_VERSION/1000) // Minor interface version @@ -51,37 +55,37 @@ #define __TBB_BINARY_VERSION 12 //! TBB_VERSION support -#ifndef ENDL -#define ENDL "\n" +#ifndef TBB_ENDL +#define TBB_ENDL "\n" #endif //TBB_REVAMP_TODO: consider enabling version_string.ver generation //TBB_REVAMP_TODO: #include "version_string.ver" -#define __TBB_ONETBB_SPEC_VERSION(N) #N ": SPECIFICATION VERSION\t" ONETBB_SPEC_VERSION ENDL -#define __TBB_VERSION_NUMBER(N) #N ": VERSION\t\t" TBB_VERSION_STRING ENDL -#define __TBB_INTERFACE_VERSION_NUMBER(N) #N ": INTERFACE VERSION\t" __TBB_STRING(TBB_INTERFACE_VERSION) ENDL +#define __TBB_ONETBB_SPEC_VERSION(N) #N ": SPECIFICATION VERSION\t" ONETBB_SPEC_VERSION TBB_ENDL +#define __TBB_VERSION_NUMBER(N) #N ": VERSION\t\t" TBB_VERSION_STRING TBB_ENDL +#define __TBB_INTERFACE_VERSION_NUMBER(N) #N ": INTERFACE VERSION\t" __TBB_STRING(TBB_INTERFACE_VERSION) TBB_ENDL #ifndef TBB_USE_DEBUG - #define __TBB_VERSION_USE_DEBUG(N) #N ": TBB_USE_DEBUG\tundefined" ENDL + #define __TBB_VERSION_USE_DEBUG(N) #N ": TBB_USE_DEBUG\tundefined" TBB_ENDL #elif TBB_USE_DEBUG==0 - #define __TBB_VERSION_USE_DEBUG(N) #N ": TBB_USE_DEBUG\t0" ENDL + #define __TBB_VERSION_USE_DEBUG(N) #N ": TBB_USE_DEBUG\t0" TBB_ENDL #elif TBB_USE_DEBUG==1 - #define __TBB_VERSION_USE_DEBUG(N) #N ": TBB_USE_DEBUG\t1" ENDL + #define __TBB_VERSION_USE_DEBUG(N) #N ": TBB_USE_DEBUG\t1" TBB_ENDL #elif TBB_USE_DEBUG==2 - #define __TBB_VERSION_USE_DEBUG(N) #N ": TBB_USE_DEBUG\t2" ENDL + #define __TBB_VERSION_USE_DEBUG(N) #N ": TBB_USE_DEBUG\t2" TBB_ENDL #else #error Unexpected value for TBB_USE_DEBUG #endif #ifndef TBB_USE_ASSERT - #define __TBB_VERSION_USE_ASSERT(N) #N ": TBB_USE_ASSERT\tundefined" ENDL + #define __TBB_VERSION_USE_ASSERT(N) #N ": TBB_USE_ASSERT\tundefined" TBB_ENDL #elif TBB_USE_ASSERT==0 - #define __TBB_VERSION_USE_ASSERT(N) #N ": TBB_USE_ASSERT\t0" ENDL + #define __TBB_VERSION_USE_ASSERT(N) #N ": TBB_USE_ASSERT\t0" TBB_ENDL #elif TBB_USE_ASSERT==1 - #define __TBB_VERSION_USE_ASSERT(N) #N ": TBB_USE_ASSERT\t1" ENDL + #define __TBB_VERSION_USE_ASSERT(N) #N ": TBB_USE_ASSERT\t1" TBB_ENDL #elif TBB_USE_ASSERT==2 - #define __TBB_VERSION_USE_ASSERT(N) #N ": TBB_USE_ASSERT\t2" ENDL + #define __TBB_VERSION_USE_ASSERT(N) #N ": TBB_USE_ASSERT\t2" TBB_ENDL #else #error Unexpected value for TBB_USE_ASSERT #endif diff --git a/integration/linux/modulefiles/tbb b/integration/linux/modulefiles/tbb index ab08c3529e..b8c695ed2c 100644 --- a/integration/linux/modulefiles/tbb +++ b/integration/linux/modulefiles/tbb @@ -66,3 +66,4 @@ prepend-path CPATH "$tbbroot/include" prepend-path LIBRARY_PATH "$tbbroot/lib" prepend-path LD_LIBRARY_PATH "$tbbroot/lib" prepend-path CMAKE_PREFIX_PATH "$tbbroot" +prepend-path PKG_CONFIG_PATH "$tbbroot/lib/pkgconfig" diff --git a/integration/linux/modulefiles/tbb32 b/integration/linux/modulefiles/tbb32 index 9d0efc5a7c..db34135176 100644 --- a/integration/linux/modulefiles/tbb32 +++ b/integration/linux/modulefiles/tbb32 @@ -66,3 +66,4 @@ prepend-path CPATH "$tbbroot/include32:$tbbroot/include" prepend-path LIBRARY_PATH "$tbbroot/lib32" prepend-path LD_LIBRARY_PATH "$tbbroot/lib32" prepend-path CMAKE_PREFIX_PATH "$tbbroot" +prepend-path PKG_CONFIG_PATH "$tbbroot/lib32/pkgconfig" diff --git a/integration/windows/nuget/inteltbb.devel.win.targets b/integration/windows/nuget/inteltbb.devel.win.targets index ab1f244f93..1c94a12c13 100644 --- a/integration/windows/nuget/inteltbb.devel.win.targets +++ b/integration/windows/nuget/inteltbb.devel.win.targets @@ -1,6 +1,6 @@ - $(MSBuildThisFileDirectory)..\..\lib\native\include;%(AdditionalIncludeDirectories) + $(MSBuildThisFileDirectory)..\..\build\native\include;%(AdditionalIncludeDirectories) TBB_USE_DEBUG;%(PreprocessorDefinitions) @@ -27,25 +27,25 @@ - $(MSBuildThisFileDirectory)..\..\lib\native\win-x86;%(AdditionalLibraryDirectories) + $(MSBuildThisFileDirectory)..\..\build\native\win-x86;%(AdditionalLibraryDirectories) tbb12.lib;tbbmalloc.lib;tbbmalloc_proxy.lib;%(AdditionalDependencies) - $(MSBuildThisFileDirectory)..\..\lib\native\win-x64;%(AdditionalLibraryDirectories) + $(MSBuildThisFileDirectory)..\..\build\native\win-x64;%(AdditionalLibraryDirectories) tbb12.lib;tbbmalloc.lib;tbbmalloc_proxy.lib;%(AdditionalDependencies) - $(MSBuildThisFileDirectory)..\..\lib\native\win-x86;%(AdditionalLibraryDirectories) + $(MSBuildThisFileDirectory)..\..\build\native\win-x86;%(AdditionalLibraryDirectories) tbb12_debug.lib;tbbmalloc_debug.lib;tbbmalloc_proxy_debug.lib;%(AdditionalDependencies) - $(MSBuildThisFileDirectory)..\..\lib\native\win-x64;%(AdditionalLibraryDirectories) + $(MSBuildThisFileDirectory)..\..\build\native\win-x64;%(AdditionalLibraryDirectories) tbb12_debug.lib;tbbmalloc_debug.lib;tbbmalloc_proxy_debug.lib;%(AdditionalDependencies) diff --git a/src/tbb/CMakeLists.txt b/src/tbb/CMakeLists.txt index e3df9fc9fe..4003d7b47e 100644 --- a/src/tbb/CMakeLists.txt +++ b/src/tbb/CMakeLists.txt @@ -128,57 +128,59 @@ target_link_libraries(tbb tbb_install_target(tbb) -if (MSVC) - # Create a copy of target linker file (tbb[_debug].lib) with legacy name (tbb[_debug].lib) - # to support previous user experience for linkage. - install(FILES - $ - DESTINATION lib - CONFIGURATIONS RelWithDebInfo Release MinSizeRel - RENAME tbb.lib - COMPONENT devel - ) - - install(FILES - $ - DESTINATION lib - CONFIGURATIONS Debug - RENAME tbb_debug.lib - COMPONENT devel - ) -endif() - -set(_tbb_pc_lib_name tbb) - -if (WIN32) - set(_tbb_pc_lib_name ${_tbb_pc_lib_name}${TBB_BINARY_VERSION}) -endif() - -if (CMAKE_SIZEOF_VOID_P EQUAL 8) - set(TBB_PC_NAME tbb) -else() - set(TBB_PC_NAME tbb32) -endif() - -set(_prefix_for_pc_file "${CMAKE_INSTALL_PREFIX}") - -if (IS_ABSOLUTE "${CMAKE_INSTALL_LIBDIR}") - set(_libdir_for_pc_file "${CMAKE_INSTALL_LIBDIR}") -else() - set(_libdir_for_pc_file "\${prefix}/${CMAKE_INSTALL_LIBDIR}") +if (TBB_INSTALL) + if (MSVC) + # Create a copy of target linker file (tbb[_debug].lib) with legacy name (tbb[_debug].lib) + # to support previous user experience for linkage. + install(FILES + $ + DESTINATION lib + CONFIGURATIONS RelWithDebInfo Release MinSizeRel + RENAME tbb.lib + COMPONENT devel + ) + + install(FILES + $ + DESTINATION lib + CONFIGURATIONS Debug + RENAME tbb_debug.lib + COMPONENT devel + ) + endif() + + set(_tbb_pc_lib_name tbb) + + if (WIN32) + set(_tbb_pc_lib_name ${_tbb_pc_lib_name}${TBB_BINARY_VERSION}) + endif() + + if (CMAKE_SIZEOF_VOID_P EQUAL 8) + set(TBB_PC_NAME tbb) + else() + set(TBB_PC_NAME tbb32) + endif() + + set(_prefix_for_pc_file "${CMAKE_INSTALL_PREFIX}") + + if (IS_ABSOLUTE "${CMAKE_INSTALL_LIBDIR}") + set(_libdir_for_pc_file "${CMAKE_INSTALL_LIBDIR}") + else() + set(_libdir_for_pc_file "\${prefix}/${CMAKE_INSTALL_LIBDIR}") + endif() + + if (IS_ABSOLUTE "${CMAKE_INSTALL_INCLUDEDIR}") + set(_includedir_for_pc_file "${CMAKE_INSTALL_INCLUDEDIR}") + else() + set(_includedir_for_pc_file "\${prefix}/${CMAKE_INSTALL_INCLUDEDIR}") + endif() + + configure_file(${PROJECT_SOURCE_DIR}/integration/pkg-config/tbb.pc.in ${CMAKE_CURRENT_BINARY_DIR}/${TBB_PC_NAME}.pc @ONLY) + install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${TBB_PC_NAME}.pc + DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig/ + COMPONENT devel) endif() -if (IS_ABSOLUTE "${CMAKE_INSTALL_INCLUDEDIR}") - set(_includedir_for_pc_file "${CMAKE_INSTALL_INCLUDEDIR}") -else() - set(_includedir_for_pc_file "\${prefix}/${CMAKE_INSTALL_INCLUDEDIR}") -endif() - -configure_file(${PROJECT_SOURCE_DIR}/integration/pkg-config/tbb.pc.in ${CMAKE_CURRENT_BINARY_DIR}/${TBB_PC_NAME}.pc @ONLY) -install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${TBB_PC_NAME}.pc - DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig/ - COMPONENT devel) - if (COMMAND tbb_gen_vars) tbb_gen_vars(tbb) endif() diff --git a/src/tbb/arena.h b/src/tbb/arena.h index 61bda0bfc4..ab218eeaee 100644 --- a/src/tbb/arena.h +++ b/src/tbb/arena.h @@ -429,8 +429,7 @@ void arena::advertise_new_work() { workers_delta = 1; } - bool wakeup_workers = is_mandatory_needed || are_workers_needed; - request_workers(mandatory_delta, workers_delta, wakeup_workers); + request_workers(mandatory_delta, workers_delta, /* wakeup_threads = */ true); } } diff --git a/src/tbb/concurrent_monitor.h b/src/tbb/concurrent_monitor.h index 3d20ef5b98..3e5c4bebe8 100644 --- a/src/tbb/concurrent_monitor.h +++ b/src/tbb/concurrent_monitor.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2005-2021 Intel Corporation + Copyright (c) 2005-2023 Intel Corporation Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -290,7 +290,17 @@ class concurrent_monitor_base { n = my_waitset.front(); if (n != end) { my_waitset.remove(*n); + +// GCC 12.x-13.x issues a warning here that to_wait_node(n)->my_is_in_list might have size 0, since n is +// a base_node pointer. (This cannot happen, because only wait_node pointers are added to my_waitset.) +#if (__TBB_GCC_VERSION >= 120100 && __TBB_GCC_VERSION < 140000 ) && !__clang__ && !__INTEL_COMPILER +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wstringop-overflow" +#endif to_wait_node(n)->my_is_in_list.store(false, std::memory_order_relaxed); +#if (__TBB_GCC_VERSION >= 120100 && __TBB_GCC_VERSION < 140000 ) && !__clang__ && !__INTEL_COMPILER +#pragma GCC diagnostic pop +#endif } } diff --git a/src/tbb/global_control.cpp b/src/tbb/global_control.cpp index 12c146c2c1..b8dd6b34f8 100644 --- a/src/tbb/global_control.cpp +++ b/src/tbb/global_control.cpp @@ -49,6 +49,7 @@ class control_storage { std::set> my_list{}; spin_mutex my_list_mutex{}; public: + virtual ~control_storage() = default; virtual std::size_t default_value() const = 0; virtual void apply_active(std::size_t new_active) { my_active_value = new_active; diff --git a/src/tbb/waiters.h b/src/tbb/waiters.h index e2aa4abce1..dba43f0de3 100644 --- a/src/tbb/waiters.h +++ b/src/tbb/waiters.h @@ -114,6 +114,7 @@ class sleep_waiter : public waiter_base { void sleep(std::uintptr_t uniq_tag, Pred wakeup_condition) { my_arena.get_waiting_threads_monitor().wait(wakeup_condition, market_context{uniq_tag, &my_arena}); + reset_wait(); } }; @@ -139,7 +140,6 @@ class external_waiter : public sleep_waiter { auto wakeup_condition = [&] { return !my_arena.is_empty() || !my_wait_ctx.continue_execution(); }; sleep(std::uintptr_t(&my_wait_ctx), wakeup_condition); - my_backoff.reset_wait(); } d1::wait_context* wait_ctx() { @@ -176,11 +176,6 @@ class coroutine_waiter : public sleep_waiter { auto wakeup_condition = [&] { return !my_arena.is_empty() || sp->m_is_owner_recalled.load(std::memory_order_relaxed); }; sleep(std::uintptr_t(sp), wakeup_condition); - my_backoff.reset_wait(); - } - - void reset_wait() { - my_backoff.reset_wait(); } d1::wait_context* wait_ctx() { diff --git a/src/tbbbind/CMakeLists.txt b/src/tbbbind/CMakeLists.txt index 24cd3e5d85..993dc8b859 100644 --- a/src/tbbbind/CMakeLists.txt +++ b/src/tbbbind/CMakeLists.txt @@ -12,9 +12,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -if (DEFINED CMAKE_SKIP_BUILD_RPATH) - set(CMAKE_SKIP_BUILD_RPATH_OLD_VALUE ${CMAKE_SKIP_BUILD_RPATH}) -endif() set(CMAKE_SKIP_BUILD_RPATH TRUE) function(tbbbind_build TBBBIND_NAME REQUIRED_HWLOC_TARGET) @@ -106,10 +103,3 @@ else() tbbbind_build(tbbbind_2_5 HWLOC::hwloc_2_5 ) endif() - -if (DEFINED CMAKE_SKIP_BUILD_RPATH_OLD_VALUE) - set(CMAKE_SKIP_BUILD_RPATH ${CMAKE_SKIP_BUILD_RPATH_OLD_VALUE}) - unset(CMAKE_SKIP_BUILD_RPATH_OLD_VALUE) -else() - unset(CMAKE_SKIP_BUILD_RPATH) -endif() diff --git a/src/tbbmalloc/TypeDefinitions.h b/src/tbbmalloc/TypeDefinitions.h index 81149166e6..bfadf61d6e 100644 --- a/src/tbbmalloc/TypeDefinitions.h +++ b/src/tbbmalloc/TypeDefinitions.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2005-2021 Intel Corporation + Copyright (c) 2005-2023 Intel Corporation Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -25,7 +25,7 @@ # define __ARCH_ipf 1 # elif defined(_M_IX86)||defined(__i386__) // the latter for MinGW support # define __ARCH_x86_32 1 -# elif defined(_M_ARM) || defined(_M_ARM64) +# elif defined(_M_ARM) || defined(_M_ARM64) || defined(__aarch64__) // the latter for MinGW support # define __ARCH_other 1 # else # error Unknown processor architecture for Windows diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 0e0b39660d..5c6cbb676a 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -29,6 +29,9 @@ function(tbb_add_test) add_executable(${_tbb_test_TARGET_NAME} ${_tbb_test_SUBDIR}/${_tbb_test_NAME}.cpp) target_include_directories(${_tbb_test_TARGET_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/.. ${CMAKE_CURRENT_SOURCE_DIR}) + # cmake>=3.4 no longer adds flags to export symbols from executables (CMP0065) + set_property(TARGET ${_tbb_test_TARGET_NAME} PROPERTY ENABLE_EXPORTS TRUE) + target_compile_options(${_tbb_test_TARGET_NAME} PRIVATE ${TBB_CXX_STD_FLAG} @@ -558,7 +561,7 @@ if (TARGET TBB::tbb) target_include_directories(test_implicit_linkage_on_windows PRIVATE $) set_target_properties(test_implicit_linkage_on_windows PROPERTIES - LINK_OPTIONS /LIBPATH:$) + LINK_OPTIONS LINKER:/LIBPATH:$) add_dependencies(test_implicit_linkage_on_windows TBB::tbb) endif() endif() diff --git a/test/common/utils_concurrency_limit.h b/test/common/utils_concurrency_limit.h index 4b1e8d206b..9d0b3c77ed 100644 --- a/test/common/utils_concurrency_limit.h +++ b/test/common/utils_concurrency_limit.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2020-2022 Intel Corporation + Copyright (c) 2020-2023 Intel Corporation Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -287,27 +287,44 @@ bool can_change_thread_priority() { return false; } -void increase_thread_priority() { #if __unix__ - pthread_t this_thread = pthread_self(); - sched_param params; - params.sched_priority = sched_get_priority_max(SCHED_FIFO); - ASSERT(params.sched_priority != -1, nullptr); - int err = pthread_setschedparam(this_thread, SCHED_FIFO, ¶ms); - ASSERT(err == 0, "Can not change thread priority."); -#endif -} +class increased_priority_guard { +public: + increased_priority_guard() : m_backup(get_current_schedparam()) { + increase_thread_priority(); + } -void decrease_thread_priority() { -#if __unix__ - pthread_t this_thread = pthread_self(); - sched_param params; - params.sched_priority = sched_get_priority_min(SCHED_FIFO); - ASSERT(params.sched_priority != -1, nullptr); - int err = pthread_setschedparam(this_thread, SCHED_FIFO, ¶ms); - ASSERT(err == 0, "Can not change thread priority."); + ~increased_priority_guard() { + // restore priority on destruction + pthread_t this_thread = pthread_self(); + int err = pthread_setschedparam(this_thread, + /*policy*/ m_backup.first, /*sched_param*/ &m_backup.second); + ASSERT(err == 0, nullptr); + } +private: + std::pair get_current_schedparam() { + pthread_t this_thread = pthread_self(); + sched_param params; + int policy = 0; + int err = pthread_getschedparam(this_thread, &policy, ¶ms); + ASSERT(err == 0, nullptr); + return std::make_pair(policy, params); + } + + void increase_thread_priority() { + pthread_t this_thread = pthread_self(); + sched_param params; + params.sched_priority = sched_get_priority_max(SCHED_FIFO); + ASSERT(params.sched_priority != -1, nullptr); + int err = pthread_setschedparam(this_thread, SCHED_FIFO, ¶ms); + ASSERT(err == 0, "Can not change thread priority."); + } + + std::pair m_backup; +}; +#else + class increased_priority_guard{}; #endif -} } // namespace utils diff --git a/test/conformance/conformance_parallel_for_each.cpp b/test/conformance/conformance_parallel_for_each.cpp index ad8ee672f7..e36a2803cf 100644 --- a/test/conformance/conformance_parallel_for_each.cpp +++ b/test/conformance/conformance_parallel_for_each.cpp @@ -102,10 +102,8 @@ class ForEachInvokeItem { void do_action_and_feed(oneapi::tbb::feeder& feeder) const { CHECK_MESSAGE(change_vector.size() % 2 == 0, "incorrect test setup"); std::size_t shift = change_vector.size() / 2; - std::cout << "Process " << real_value << std::endl; ++change_vector[real_value]; if (real_value < shift) { - std::cout << "Add " << real_value + shift << std::endl; feeder.add(ForEachInvokeItem(real_value + shift, change_vector)); } } diff --git a/test/tbb/test_eh_thread.cpp b/test/tbb/test_eh_thread.cpp index d5af9db6a0..a5ac1c8a21 100644 --- a/test/tbb/test_eh_thread.cpp +++ b/test/tbb/test_eh_thread.cpp @@ -1,5 +1,5 @@ /* - Copyright (c) 2020-2022 Intel Corporation + Copyright (c) 2020-2023 Intel Corporation Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -75,7 +75,7 @@ class Thread { mValid = false; pthread_attr_t attr; // Limit the stack size not to consume all virtual memory on 32 bit platforms. - std::size_t stacksize = utils::max(128*1024, PTHREAD_STACK_MIN); + std::size_t stacksize = utils::max(std::size_t(128*1024), std::size_t(PTHREAD_STACK_MIN)); if (pthread_attr_init(&attr) == 0 && pthread_attr_setstacksize(&attr, stacksize) == 0) { mValid = pthread_create(&mHandle, &attr, thread_routine, /* arg = */ nullptr) == 0; } diff --git a/test/tbb/test_fuzzing.cpp b/test/tbb/test_fuzzing.cpp index 6571ae0d57..38cd7f8a3b 100644 --- a/test/tbb/test_fuzzing.cpp +++ b/test/tbb/test_fuzzing.cpp @@ -15,7 +15,7 @@ */ //! \file test_fuzzing.cpp -//! \brief Test the [fuzzing] of environment variables +//! \brief Test the [internal] of environment variables #include diff --git a/test/tbb/test_parallel_for_each.cpp b/test/tbb/test_parallel_for_each.cpp index f6bb5090b4..3dfc107e91 100644 --- a/test/tbb/test_parallel_for_each.cpp +++ b/test/tbb/test_parallel_for_each.cpp @@ -1,5 +1,5 @@ /* - Copyright (c) 2005-2021 Intel Corporation + Copyright (c) 2005-2023 Intel Corporation Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -22,6 +22,105 @@ //! \file test_parallel_for_each.cpp //! \brief Test for [algorithms.parallel_for_each] +#if __TBB_CPP20_PRESENT +// Fancy iterator type that models the C++20 iterator type +// that defines the real iterator category using iterator_concept type +// and iterator_category is always std::input_iterator_type +// Similar iterators are used by C++20 ranges (e.g. std::ranges::iota_view::iterator) +// parallel_for_each algorithm should detect such iterators with respect to iterator_concept value + +template +struct cpp20_iterator { + static_assert(std::derived_from, + "cpp20_iterator should be of at least forward iterator category"); + + using iterator_concept = Category; + using iterator_category = std::input_iterator_tag; + using value_type = T; + using difference_type = std::ptrdiff_t; + + cpp20_iterator() = default; + explicit cpp20_iterator(T* ptr) : my_ptr(ptr) {} + + T& operator*() const { return *my_ptr; } + + cpp20_iterator& operator++() { + ++my_ptr; + return *this; + } + + cpp20_iterator operator++(int) { + auto it = *this; + ++*this; + return it; + } + + cpp20_iterator& operator--() + requires std::derived_from + { + --my_ptr; + return *this; + } + + cpp20_iterator operator--(int) + requires std::derived_from + { + auto it = *this; + --*this; + return it; + } + + cpp20_iterator& operator+=(difference_type n) + requires std::derived_from + { + my_ptr += n; + return *this; + } + + cpp20_iterator& operator-=(difference_type n) + requires std::derived_from + { + my_ptr -= n; + return *this; + } + + T& operator[](difference_type n) const + requires std::derived_from + { + return my_ptr[n]; + } + + friend bool operator==(const cpp20_iterator&, const cpp20_iterator&) = default; + + friend auto operator<=>(const cpp20_iterator&, const cpp20_iterator&) + requires std::derived_from = default; + + friend cpp20_iterator operator+(cpp20_iterator i, difference_type n) + requires std::derived_from + { + return cpp20_iterator(i.my_ptr + n); + } + + friend cpp20_iterator operator+(difference_type n, cpp20_iterator i) + requires std::derived_from + { + return i + n; + } + + friend cpp20_iterator operator-(cpp20_iterator i, difference_type n) + requires std::derived_from + { + return cpp20_iterator(i.my_ptr - n); + } + + friend difference_type operator-(const cpp20_iterator& x, const cpp20_iterator& y) { + return x.my_ptr - y.my_ptr; + } +private: + T* my_ptr = nullptr; +}; // class cpp20_iterator +#endif // __TBB_CPP20_PRESENT + //! Test forward access iterator support //! \brief \ref error_guessing \ref interface TEST_CASE("Forward iterator support") { @@ -172,3 +271,65 @@ TEST_CASE("parallel_for_each constraints") { } #endif // __TBB_CPP20_CONCEPTS_PRESENT + +#if __TBB_CPP20_PRESENT + +struct no_copy_move { + no_copy_move() = default; + + no_copy_move(const no_copy_move&) = delete; + no_copy_move(no_copy_move&&) = delete; + + no_copy_move& operator=(const no_copy_move&) = delete; + no_copy_move& operator=(no_copy_move&&) = delete; + + int item = 0; +}; + +template +void test_with_cpp20_iterator() { + constexpr std::size_t n = 1'000'000; + + std::vector elements(n); + + cpp20_iterator begin(elements.data()); + cpp20_iterator end(elements.data() + n); + + oneapi::tbb::parallel_for_each(begin, end, [](no_copy_move& element) { + element.item = 42; + }); + + for (std::size_t index = 0; index < n; ++index) { + CHECK(elements[index].item == 42); + } +} + +//! \brief \ref error_guessing \ref regression +TEST_CASE("parallel_for_each with cpp20 iterator") { + // Test that parallel_for_each threats ignores iterator_category type + // if iterator_concept type is defined for iterator + + // For input iterators parallel_for_each requires element to be + // copyable or movable so since cpp20_iterator is at least forward + // parallel_for_each should work with cpp20_iterator + // on non-copyable and non-movable type + + // test cpp20_iterator implementation + using cpp20_forward_iterator = cpp20_iterator; + using cpp20_bidirectional_iterator = cpp20_iterator; + using cpp20_random_access_iterator = cpp20_iterator; + + static_assert(std::forward_iterator); + static_assert(!std::bidirectional_iterator); + + static_assert(std::bidirectional_iterator); + static_assert(!std::random_access_iterator); + + static_assert(std::random_access_iterator); + + test_with_cpp20_iterator(); + test_with_cpp20_iterator(); + test_with_cpp20_iterator(); +} + +#endif // __TBB_CPP20_PRESENT diff --git a/test/tbb/test_task.cpp b/test/tbb/test_task.cpp index dec24def02..876e351006 100644 --- a/test/tbb/test_task.cpp +++ b/test/tbb/test_task.cpp @@ -771,7 +771,8 @@ TEST_CASE("Test with priority inversion") { auto high_priority_thread_func = [&] { // Increase external threads priority - utils::increase_thread_priority(); + utils::increased_priority_guard guard{}; + utils::suppress_unused_warning(guard); // pin external threads test_arena.execute([]{}); while (task_counter++ < critical_task_counter) { @@ -796,7 +797,8 @@ TEST_CASE("Test with priority inversion") { high_priority_threads.emplace_back(high_priority_thread_func); } - utils::increase_thread_priority(); + utils::increased_priority_guard guard{}; + utils::suppress_unused_warning(guard); while (task_counter++ < critical_task_counter) { submit(critical_task, test_arena, test_context, true); std::this_thread::sleep_for(std::chrono::milliseconds(1)); diff --git a/test/tbbmalloc/test_malloc_compliance.cpp b/test/tbbmalloc/test_malloc_compliance.cpp index 224e2476ce..1a85ed5829 100644 --- a/test/tbbmalloc/test_malloc_compliance.cpp +++ b/test/tbbmalloc/test_malloc_compliance.cpp @@ -1,5 +1,5 @@ /* - Copyright (c) 2005-2022 Intel Corporation + Copyright (c) 2005-2023 Intel Corporation Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -30,6 +30,10 @@ #include "oneapi/tbb/detail/_config.h" +// There is no RLIMIT_AS on OpenBSD. +// Therefore, the tests for memory limit is unreasonable. +#if !__OpenBSD__ + #define __TBB_NO_IMPLICIT_LINKAGE 1 #include "tbb/scalable_allocator.h" @@ -1091,3 +1095,4 @@ TEST_CASE("MAIN TEST") { } #endif /* __TBB_WIN8UI_SUPPORT */ +#endif /* Enable test */