diff --git a/documentation/release_6.2.htm b/documentation/release_6.2.htm
index 3db69540e0..a583295054 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.
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 7a731c2e63..1f8117d2df 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
diff --git a/src/include/stir/Array.inl b/src/include/stir/Array.inl
index ee778dbd13..724f91f227 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);
@@ -716,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);
};
@@ -728,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)