From 1cb38f547815fa50678d5996d4ebf95d29ed6d25 Mon Sep 17 00:00:00 2001 From: Tobias Heuer Date: Tue, 8 Oct 2024 16:16:14 +0200 Subject: [PATCH] fix TBB version for terminating the thread pool --- CMakeLists.txt | 4 ++++ include/libmtkahypar.h | 2 +- mt-kahypar/parallel/tbb_initializer.h | 2 ++ python/module.cpp | 4 ++-- 4 files changed, 9 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 207246767..1a7a27795 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -210,6 +210,10 @@ endif() # Find TBB Library find_package(TBB REQUIRED) if (TBB_FOUND) + if ( TBB_INTERFACE_VERSION GREATER 12050 ) + add_compile_definitions(MT_KAHYPAR_SUPPORTS_THREAD_POOL_TERMINATION) + ENDIF() + if ((TBB_INTERFACE_VERSION GREATER_EQUAL 12050) OR (NOT KAHYPAR_ENFORCE_MINIMUM_TBB_VERSION) OR KAHYPAR_CI_BUILD) include_directories(SYSTEM ${TBB_INCLUDE_DIRS} ${TBB_MALLOC_INCLUDE_DIRS}) link_libraries(${TBB_LIBRARIES} ${TBB_MALLOC_LIBRARIES}) diff --git a/include/libmtkahypar.h b/include/libmtkahypar.h index f10a16f49..bb7c3d650 100644 --- a/include/libmtkahypar.h +++ b/include/libmtkahypar.h @@ -110,7 +110,7 @@ MT_KAHYPAR_API void mt_kahypar_initialize_thread_pool(const size_t num_threads, const bool interleaved_allocations); /** - * Terminates the TBB thread pool. + * Terminates the TBB thread pool (only supported at oneTBB version >= 2021.6). * * \return `true` if the thread pool was successfully terminated, `false` otherwise. */ diff --git a/mt-kahypar/parallel/tbb_initializer.h b/mt-kahypar/parallel/tbb_initializer.h index b91e834b2..6b7cfb246 100644 --- a/mt-kahypar/parallel/tbb_initializer.h +++ b/mt-kahypar/parallel/tbb_initializer.h @@ -141,10 +141,12 @@ class TBBInitializer { _global_observer->observe(false); } + #ifdef MT_KAHYPAR_SUPPORTS_THREAD_POOL_TERMINATION // Waits until the last worker threads have finished, and // then terminates the task scheduler. oneapi::tbb::task_scheduler_handle handle(oneapi::tbb::attach{}); return oneapi::tbb::finalize(handle, std::nothrow_t{}); + #endif } private: diff --git a/python/module.cpp b/python/module.cpp index 3d16808c8..4e590d088 100644 --- a/python/module.cpp +++ b/python/module.cpp @@ -76,7 +76,7 @@ namespace { } bool terminate_thread_pool() { - mt_kahypar::TBBInitializer::instance().terminate(); + return mt_kahypar::TBBInitializer::instance().terminate(); } template @@ -238,7 +238,7 @@ PYBIND11_MODULE(mtkahypar, m) { py::arg("number of threads")); m.def("terminateThreadPool", &terminate_thread_pool, - "Terminates the thread pool."); + "Terminates the thread pool (only supported for oneTBB version >= 2021.6)."); // ####################### Initialize Random Number Generator #######################