Skip to content

Commit

Permalink
fix TBB version for terminating the thread pool
Browse files Browse the repository at this point in the history
  • Loading branch information
kittobi1992 committed Oct 8, 2024
1 parent e8bac18 commit 1cb38f5
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down
2 changes: 1 addition & 1 deletion include/libmtkahypar.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
2 changes: 2 additions & 0 deletions mt-kahypar/parallel/tbb_initializer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions python/module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ namespace {
}

bool terminate_thread_pool() {
mt_kahypar::TBBInitializer::instance().terminate();
return mt_kahypar::TBBInitializer::instance().terminate();
}

template<typename PartitionedHypergraph>
Expand Down Expand Up @@ -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 #######################

Expand Down

0 comments on commit 1cb38f5

Please sign in to comment.