Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions cmake/modules/FindTBB.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,18 @@ if(NOT TBB_FOUND)
##################################
# Set version strings
##################################

if(TBB_INCLUDE_DIRS)
file(READ "${TBB_INCLUDE_DIRS}/tbb/tbb_stddef.h" _tbb_version_file)
set(TBB_VERSION_FILE_PRIOR_TO_TBB_2021_1 "${TBB_INCLUDE_DIRS}/tbb/tbb_stddef.h")
set(TBB_VERSION_FILE_AFTER_TBB_2021_1 "${TBB_INCLUDE_DIRS}/oneapi/tbb/version.h")
if (EXISTS "${TBB_VERSION_FILE_PRIOR_TO_TBB_2021_1}")
set(TBB_VERSION_FILE "${TBB_VERSION_FILE_PRIOR_TO_TBB_2021_1}")
elseif (EXISTS "${TBB_VERSION_FILE_AFTER_TBB_2021_1}")
set(TBB_VERSION_FILE "${TBB_VERSION_FILE_AFTER_TBB_2021_1}")
else()
message(FATAL_ERROR "Found TBB installation: ${TBB_INCLUDE_DIRS} missing version header.")
endif()

file(READ "${TBB_VERSION_FILE}" _tbb_version_file)
string(REGEX REPLACE ".*#define TBB_VERSION_MAJOR ([0-9]+).*" "\\1"
TBB_VERSION_MAJOR "${_tbb_version_file}")
string(REGEX REPLACE ".*#define TBB_VERSION_MINOR ([0-9]+).*" "\\1"
Expand Down
16 changes: 15 additions & 1 deletion python/perspective/perspective/src/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
#include <perspective/python/base.h>
#include <perspective/python/utils.h>

#if TBB_VERSION_MAJOR >= 2021 && TBB_VERSION_MINOR >= 1
#define USE_ONETBB_INTERFACE
#endif

#ifdef PSP_PARALLEL_FOR
#ifndef TBB_PREVIEW_GLOBAL_CONTROL
#define TBB_PREVIEW_GLOBAL_CONTROL 1
Expand All @@ -27,15 +31,25 @@ namespace binding {
std::shared_ptr<tbb::global_control> control =
std::make_shared<tbb::global_control>(
tbb::global_control::max_allowed_parallelism,
#ifdef USE_ONETBB_INTERFACE
oneapi::tbb::info::default_concurrency()
#else
tbb::task_scheduler_init::default_num_threads()
#endif
);
#endif

void _set_nthreads(int nthreads) {
#ifdef PSP_PARALLEL_FOR
control = std::make_shared<tbb::global_control>(
tbb::global_control::max_allowed_parallelism,
nthreads == -1 ? tbb::task_scheduler_init::default_num_threads() : nthreads
nthreads == -1 ?
#ifdef USE_ONETBB_INTERFACE
oneapi::tbb::info::default_concurrency()
#else
tbb::task_scheduler_init::default_num_threads()
#endif
: nthreads
);
#endif
}
Expand Down