From 96b4a6937f137d288694131e61f151f0aa1aa50d Mon Sep 17 00:00:00 2001 From: Kris Thielemans Date: Fri, 17 May 2024 22:37:07 +0100 Subject: [PATCH 1/4] OpenMP parallelise Array::sum/find_max/find_min implement the easy reduction clauses --- src/include/stir/Array.inl | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/include/stir/Array.inl b/src/include/stir/Array.inl index ee778dbd1..a0370e4d0 100644 --- a/src/include/stir/Array.inl +++ b/src/include/stir/Array.inl @@ -240,6 +240,11 @@ Array::size_all() const { this->check_state(); size_t acc = 0; +#ifdef STIR_OPENMP +# if _OPENMP >= 201107 +# pragma omp parallel for reduction(+ : acc) +# endif +#endif for (int i = this->get_min_index(); i <= this->get_max_index(); i++) acc += this->num[i].size_all(); return acc; @@ -327,6 +332,11 @@ Array::sum() const this->check_state(); typename HigherPrecision::type acc; assign(acc, 0); +#ifdef STIR_OPENMP +# if _OPENMP >= 201107 +# pragma omp parallel for reduction(+ : acc) +# endif +#endif for (int i = this->get_min_index(); i <= this->get_max_index(); i++) acc += this->num[i].sum(); return static_cast(acc); @@ -339,6 +349,11 @@ Array::sum_positive() const this->check_state(); typename HigherPrecision::type acc; assign(acc, 0); +#ifdef STIR_OPENMP +# if _OPENMP >= 201107 +# pragma omp parallel for reduction(+ : acc) +# endif +#endif for (int i = this->get_min_index(); i <= this->get_max_index(); i++) acc += this->num[i].sum_positive(); return static_cast(acc); @@ -352,6 +367,11 @@ Array::find_max() const if (this->size() > 0) { elemT maxval = this->num[this->get_min_index()].find_max(); +#ifdef STIR_OPENMP +# if _OPENMP >= 201107 +# pragma omp parallel for reduction(max : maxval) +# endif +#endif for (int i = this->get_min_index() + 1; i <= this->get_max_index(); i++) { maxval = std::max(this->num[i].find_max(), maxval); @@ -373,6 +393,11 @@ Array::find_min() const if (this->size() > 0) { elemT minval = this->num[this->get_min_index()].find_min(); +#ifdef STIR_OPENMP +# if _OPENMP >= 201107 +# pragma omp parallel for reduction(min : minval) +# endif +#endif for (int i = this->get_min_index() + 1; i <= this->get_max_index(); i++) { minval = std::min(this->num[i].find_min(), minval); From 84a804713468229a8376e97b75d518177d880242 Mon Sep 17 00:00:00 2001 From: Kris Thielemans Date: Sun, 2 Jun 2024 23:50:39 +0100 Subject: [PATCH 2/4] use openmp parallel for Array<1,...> sum() --- src/include/stir/Array.inl | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/include/stir/Array.inl b/src/include/stir/Array.inl index a0370e4d0..724f91f22 100644 --- a/src/include/stir/Array.inl +++ b/src/include/stir/Array.inl @@ -741,8 +741,13 @@ Array<1, elemT>::sum() const this->check_state(); typename HigherPrecision::type acc; assign(acc, 0); - for (int i = this->get_min_index(); i <= this->get_max_index(); acc += this->num[i++]) - {} +#ifdef STIR_OPENMP +# if _OPENMP >= 201107 +# pragma omp parallel for reduction(+ : acc) +# endif +#endif + for (int i = this->get_min_index(); i <= this->get_max_index(); ++i) + acc += this->num[i]; return static_cast(acc); }; @@ -753,6 +758,11 @@ Array<1, elemT>::sum_positive() const this->check_state(); typename HigherPrecision::type acc; assign(acc, 0); +#ifdef STIR_OPENMP +# if _OPENMP >= 201107 +# pragma omp parallel for reduction(+ : acc) +# endif +#endif for (int i = this->get_min_index(); i <= this->get_max_index(); i++) { if (this->num[i] > 0) From 075f41d084dbecbfcfcadd9d5c663dda869d83f0 Mon Sep 17 00:00:00 2001 From: Kris Thielemans Date: Sun, 9 Jun 2024 13:28:09 +0100 Subject: [PATCH 3/4] [CMAKE] add explicit -latomic for clang work around https://gitlab.kitware.com/cmake/cmake/-/issues/26037 --- src/CMakeLists.txt | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 7a731c2e6..1f8117d2d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -136,7 +136,13 @@ if(STIR_OPENMP) find_package(OpenMP REQUIRED) add_definitions(${OpenMP_CXX_FLAGS}) - set (OpenMP_EXE_LINKER_FLAGS OpenMP::OpenMP_CXX) + if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") + # work around https://gitlab.kitware.com/cmake/cmake/-/issues/26037 + set (OpenMP_EXE_LINKER_FLAGS OpenMP::OpenMP_CXX -latomic) + message(STATUS "OpenMP Linker flags for Clang: ${OpenMP_EXE_LINKER_FLAGS}") + else() + set (OpenMP_EXE_LINKER_FLAGS OpenMP::OpenMP_CXX) + endif() endif() #### Flags for compatibility between different systems From 833d34684375407061c1d7ce1d6c487c5a3f80b5 Mon Sep 17 00:00:00 2001 From: Kris Thielemans Date: Wed, 12 Jun 2024 22:44:41 +0100 Subject: [PATCH 4/4] update release notes [ci skip] --- documentation/release_6.2.htm | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/documentation/release_6.2.htm b/documentation/release_6.2.htm index 3db69540e..a58329505 100644 --- a/documentation/release_6.2.htm +++ b/documentation/release_6.2.htm @@ -100,7 +100,7 @@

Bug fixes

but non-TOF instead. This did not happen in our normal reconstruction code, and would have thrown an error if it occured.
- Fixed in issue #1427. + Fixed in PR #1427. @@ -108,7 +108,12 @@

Bug fixes

Other code changes

  • - Fixes an incompatibility with C++20. + Fixed an incompatibility with C++20. +
  • +
  • + Enabled OpenMP for Array members find_max(), find_min(), sum(), sum_positivie(). +
    + PR #1449.