From 847c2c22fad4fdae9b99d62d21646db79ff88ef2 Mon Sep 17 00:00:00 2001 From: ruberith Date: Wed, 18 Sep 2024 18:53:57 +0200 Subject: [PATCH] Replace oneDPL with Dispatch on macOS --- CMakeLists.txt | 5 ----- demo/main.cpp | 2 +- include/Config.h | 19 +++++++++++++++++-- src/CompactNSearch.cpp | 8 ++++---- 4 files changed, 22 insertions(+), 12 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3858fd7..0e49b8e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -49,11 +49,6 @@ endif () target_include_directories(CompactNSearch PUBLIC include) -if (APPLE AND CMAKE_CXX_COMPILER_ID MATCHES "Clang") - find_package(oneDPL REQUIRED) - target_link_libraries(CompactNSearch PUBLIC oneDPL) -endif() - install(FILES "include/CompactNSearch" ${HEADER_FILES} DESTINATION include/) diff --git a/demo/main.cpp b/demo/main.cpp index 64dbbff..e0a94c4 100644 --- a/demo/main.cpp +++ b/demo/main.cpp @@ -154,7 +154,7 @@ advect() #ifdef _MSC_VER concurrency::parallel_for_each( #elif defined(__APPLE__) && defined(__clang__) - std::for_each(oneapi::dpl::execution::par, + dispatch::parallel_for_each( #else __gnu_parallel::for_each( #endif diff --git a/include/Config.h b/include/Config.h index da73373..4dfb245 100644 --- a/include/Config.h +++ b/include/Config.h @@ -15,8 +15,23 @@ namespace CompactNSearch #ifdef _MSC_VER #include #elif defined(__APPLE__) && defined(__clang__) - #include - #include + #include + #include + + namespace dispatch + { + template + void parallel_for_each(_Iterator first, _Iterator last, const _Function& _Func) + { + dispatch_apply( + std::distance(first, last), + DISPATCH_APPLY_AUTO, + ^(size_t i) { + _Func(*std::next(first, i)); + } + ); + } + } #else #include #endif diff --git a/src/CompactNSearch.cpp b/src/CompactNSearch.cpp index 557e52c..3e99ac6 100644 --- a/src/CompactNSearch.cpp +++ b/src/CompactNSearch.cpp @@ -237,7 +237,7 @@ NeighborhoodSearch::update_point_sets() #ifdef _MSC_VER concurrency::parallel_for_each( #elif defined(__APPLE__) && defined(__clang__) - std::for_each(oneapi::dpl::execution::par, + dispatch::parallel_for_each( #else __gnu_parallel::for_each( #endif @@ -318,7 +318,7 @@ NeighborhoodSearch::erase_empty_entries(std::vector const& to_dele #ifdef _MSC_VER concurrency::parallel_for_each( #elif defined(__APPLE__) && defined(__clang__) - std::for_each(oneapi::dpl::execution::par, + dispatch::parallel_for_each( #else __gnu_parallel::for_each( #endif @@ -418,7 +418,7 @@ NeighborhoodSearch::query() #ifdef _MSC_VER concurrency::parallel_for_each( #elif defined(__APPLE__) && defined(__clang__) - std::for_each(oneapi::dpl::execution::par, + dispatch::parallel_for_each( #else __gnu_parallel::for_each( #endif @@ -480,7 +480,7 @@ NeighborhoodSearch::query() #ifdef _MSC_VER concurrency::parallel_for_each( #elif defined(__APPLE__) && defined(__clang__) - std::for_each(oneapi::dpl::execution::par, + dispatch::parallel_for_each( #else __gnu_parallel::for_each( #endif