From ad09caa982921246f2c3247be8cc239ee670fc6d Mon Sep 17 00:00:00 2001 From: Felix Weiglhofer <weiglhofer@fias.uni-frankfurt.de> Date: Thu, 22 Jun 2023 10:31:19 +0000 Subject: [PATCH] algo: Add flag to indicate if parallel STL algorithms are available to BuildInfo.h. --- algo/CMakeLists.txt | 2 +- algo/base/BuildInfo.h | 11 +++++++++++ algo/base/compat/Algorithm.h | 7 +++++-- algo/unpack/Unpack.cxx | 2 +- reco/app/cbmreco/main.cxx | 2 +- 5 files changed, 19 insertions(+), 5 deletions(-) diff --git a/algo/CMakeLists.txt b/algo/CMakeLists.txt index eb3ee186eb..4723ad70ff 100644 --- a/algo/CMakeLists.txt +++ b/algo/CMakeLists.txt @@ -94,7 +94,7 @@ if (CMAKE_SYSTEM_NAME STREQUAL "Linux") if (TBB_FOUND) message(STATUS "Found TBB") - add_compile_definitions(HAVE_TBB) + target_compile_definitions(Algo PUBLIC -DHAVE_TBB) target_link_libraries(Algo PUBLIC TBB::tbb) else() message(STATUS "TBB not found") diff --git a/algo/base/BuildInfo.h b/algo/base/BuildInfo.h index 5eba468404..bdacc7a166 100644 --- a/algo/base/BuildInfo.h +++ b/algo/base/BuildInfo.h @@ -6,6 +6,10 @@ #include <string> +#if defined(HAVE_TBB) && defined(__cpp_lib_parallel_algorithm) +#define HAVE_PARALLEL_ALGORITHM +#endif + namespace cbm::algo::BuildInfo { @@ -20,6 +24,13 @@ namespace cbm::algo::BuildInfo false; #endif + inline constexpr bool WITH_PARALLEL_ALGORITHM = +#ifdef HAVE_PARALLEL_ALGORITHM + true; +#else + false; +#endif + } // namespace cbm::algo::BuildInfo #endif // CBM_ALGO_BUILD_INFO_H diff --git a/algo/base/compat/Algorithm.h b/algo/base/compat/Algorithm.h index 5aef2404f7..cf784419c2 100644 --- a/algo/base/compat/Algorithm.h +++ b/algo/base/compat/Algorithm.h @@ -16,6 +16,9 @@ **/ #include <algorithm> + +#include "BuildInfo.h" + #ifdef __cpp_lib_execution #define WITH_EXECUTION #include <execution> @@ -28,11 +31,11 @@ namespace cbm::algo { #ifdef WITH_EXECUTION inline constexpr auto ExecPolicy = -#if defined(__cpp_lib_parallel_algorithm) && defined(HAVE_TBB) +#ifdef HAVE_PARALLEL_ALGORITHM std::execution::par_unseq; #else std::execution::seq; -#endif // __cpp_lib_parallel_algorithm && WITH_TBB +#endif // HAVE_PARALLEL_ALGORITHM #endif // WITH_EXECUTION } // namespace detail diff --git a/algo/unpack/Unpack.cxx b/algo/unpack/Unpack.cxx index a4000d7c60..cd318a5949 100644 --- a/algo/unpack/Unpack.cxx +++ b/algo/unpack/Unpack.cxx @@ -59,7 +59,7 @@ namespace cbm::algo } } //# component - // --- Sorting of output digis. Is required by both digi trigger and event builder. + // --- Sorting of output digis. Is required by both digi trigger and event builder. ParallelSort(digiTs.fData.fSts.fDigis.begin(), digiTs.fData.fSts.fDigis.end(), [](CbmStsDigi digi1, CbmStsDigi digi2) { return digi1.GetTime() < digi2.GetTime(); }); ParallelSort(digiTs.fData.fMuch.fDigis.begin(), digiTs.fData.fMuch.fDigis.end(), diff --git a/reco/app/cbmreco/main.cxx b/reco/app/cbmreco/main.cxx index b7a84cd7db..32f2b08078 100644 --- a/reco/app/cbmreco/main.cxx +++ b/reco/app/cbmreco/main.cxx @@ -34,7 +34,7 @@ int main(int argc, char** argv) xpu::preload<GPUReco>(); L_(info) << "CBMRECO buildType=" << BuildInfo::BUILD_TYPE << " gpuDebug=" << BuildInfo::GPU_DEBUG - << " commit=" << BuildInfo::GIT_HASH; + << " parallelSTL=" << BuildInfo::WITH_PARALLEL_ALGORITHM << " commit=" << BuildInfo::GIT_HASH; std::stringstream ss; for (int i = 0; i < argc; i++) { ss << argv[i] << " "; -- GitLab