From 158e28d6c1b0093bf6dcbc69f196dfc3cc482e15 Mon Sep 17 00:00:00 2001 From: Florian Uhlig <f.uhlig@gsi.de> Date: Fri, 13 May 2022 18:20:22 +0200 Subject: [PATCH] Fix compiler error on several systems Depending on the compiler the STL library support or does not support the usage of std::execution. Tets in the build system if the feature is available and switch off the usage if not supported. Remove default(none) from OpenMP parameters since it creates problems with older OpenMP versions. In the current code according to Jan the statement isn't needed. --- reco/tasks/CMakeLists.txt | 20 +++++++++++++++++++- reco/tasks/CbmTaskUnpack.cxx | 10 ++++++++-- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/reco/tasks/CMakeLists.txt b/reco/tasks/CMakeLists.txt index 4ba1d455fc..e98d6b0599 100644 --- a/reco/tasks/CMakeLists.txt +++ b/reco/tasks/CMakeLists.txt @@ -2,7 +2,6 @@ # V. Friese, 2 June 2021 - # ----- Library name ---------------------------------- Set(LIBRARY_NAME CbmRecoTasks) # --------------------------------------------------------- @@ -81,6 +80,25 @@ endif() set(LINKDEF ${LIBRARY_NAME}LinkDef.h) # --------------------------------------------------------- +# Check if the compiler supports std::execution in the respective STL +# library +CHECK_CXX_SOURCE_COMPILES(" +#include <numeric> +#include <vector> +#include <execution> + +int main(int argc, char *argv[]) +{ + std::vector<double> v(10, 1); + + auto result = std::reduce(std::execution::par, v.begin(), v.end()); + return 0; +}" HAS_STD_EXECUTION) + +if (HAS_STD_EXECUTION) + message("Execution is available in STL") + add_definitions(-DWITH_EXECUTION) +endif() # ----- Let cmake do the job --------------------------- include_directories( ${INCLUDE_DIRECTORIES}) diff --git a/reco/tasks/CbmTaskUnpack.cxx b/reco/tasks/CbmTaskUnpack.cxx index 40eeb99a0b..0d38ae6926 100644 --- a/reco/tasks/CbmTaskUnpack.cxx +++ b/reco/tasks/CbmTaskUnpack.cxx @@ -22,7 +22,9 @@ #include <algorithm> #include <cassert> #include <cstdint> +#ifdef WITH_EXECUTION #include <execution> +#endif #include <iomanip> #include <iostream> #include <memory> @@ -71,7 +73,7 @@ void CbmTaskUnpack::Exec(Option_t*) uint64_t numCompUsed = 0; // --- Component loop -#pragma omp parallel for schedule(dynamic) default(none) shared(timeslice) reduction(+: numMs, numBytes, numDigis, numCompUsed) +#pragma omp parallel for schedule(dynamic) shared(timeslice) reduction(+ : numMs, numBytes, numDigis, numCompUsed) for (uint64_t comp = 0; comp < timeslice->num_components(); comp++) { auto systemId = static_cast<fles::SubsystemIdentifier>(timeslice->descriptor(comp, 0).sys_id); @@ -124,9 +126,13 @@ void CbmTaskUnpack::Exec(Option_t*) } //# component // --- Sorting of output digis. Is required by both digi trigger and event builder. +#ifdef WITH_EXECUTION std::sort(std::execution::par_unseq, fTimeslice->fData.fSts.fDigis.begin(), fTimeslice->fData.fSts.fDigis.end(), [](CbmStsDigi digi1, CbmStsDigi digi2) { return digi1.GetTime() < digi2.GetTime(); }); - +#else + std::sort(fTimeslice->fData.fSts.fDigis.begin(), fTimeslice->fData.fSts.fDigis.end(), + [](CbmStsDigi digi1, CbmStsDigi digi2) { return digi1.GetTime() < digi2.GetTime(); }); +#endif // --- Timeslice log timer.Stop(); -- GitLab