From de45cae55f2d82a7cf713b245963fe3acf68fec6 Mon Sep 17 00:00:00 2001
From: Felix Weiglhofer <weiglhofer@fias.uni-frankfurt.de>
Date: Thu, 18 Apr 2024 09:25:06 +0000
Subject: [PATCH] online: Disable parallel sorting to prevent memleak from
 libTBB

---
 algo/base/BuildInfo.h        | 4 ++++
 algo/base/compat/Algorithm.h | 9 ++++++---
 2 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/algo/base/BuildInfo.h b/algo/base/BuildInfo.h
index d044534a54..679d18742e 100644
--- a/algo/base/BuildInfo.h
+++ b/algo/base/BuildInfo.h
@@ -6,6 +6,10 @@
 
 #include <string>
 
+#if __has_include(<execution>) && !defined(__CLING__)
+#include <execution>  // for feature test macro __cpp_lib_parallel_algorithm
+#endif
+
 #if defined(HAVE_TBB) && defined(__cpp_lib_parallel_algorithm)
 #define HAVE_PARALLEL_ALGORITHM
 #endif
diff --git a/algo/base/compat/Algorithm.h b/algo/base/compat/Algorithm.h
index 94c03a7de8..b6864ab822 100644
--- a/algo/base/compat/Algorithm.h
+++ b/algo/base/compat/Algorithm.h
@@ -19,8 +19,7 @@
 
 #include <algorithm>
 
-#if defined(__cpp_lib_execution) && defined(HAVE_PARALLEL_ALGORITHM)
-#define WITH_EXECUTION
+#ifdef HAVE_PARALLEL_ALGORITHM
 #include <execution>
 #endif
 
@@ -36,7 +35,11 @@ namespace cbm::algo
   template<typename It, typename Compare>
   void Sort(It first, It last, Compare comp)
   {
-#ifdef WITH_EXECUTION
+// Disable parallel sorting for the moment
+// The underlying implementation in libTBB has a massive memory leak:
+// https://community.intel.com/t5/Intel-oneAPI-Threading-Building/std-sort-std-execution-par-unseq-has-a-memory-leak-on-Linux/m-p/1580910
+#if 0
+// #ifdef HAVE_PARALLEL_ALGORITHM
     std::sort(std::execution::par_unseq, first, last, comp);
 #else
     std::sort(first, last, comp);
-- 
GitLab