[libcxx-commits] [PATCH] D99836: [pstl] Implement OpenMP backend

Christopher Nelson via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Tue Sep 7 04:13:37 PDT 2021


nadiasvertex updated this revision to Diff 371034.
nadiasvertex added a comment.

The previous patch was somehow broken. I have regenerated it.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D99836/new/

https://reviews.llvm.org/D99836

Files:
  libcxx/cmake/Modules/DefineLinkerScript.cmake
  pstl/CMakeLists.txt
  pstl/CREDITS.txt
  pstl/include/__pstl_config_site.in
  pstl/include/pstl/internal/parallel_backend.h
  pstl/include/pstl/internal/pstl_config.h


Index: pstl/include/pstl/internal/pstl_config.h
===================================================================
--- pstl/include/pstl/internal/pstl_config.h
+++ pstl/include/pstl/internal/pstl_config.h
@@ -18,7 +18,7 @@
 #define _PSTL_VERSION_MINOR ((_PSTL_VERSION % 1000) / 10)
 #define _PSTL_VERSION_PATCH (_PSTL_VERSION % 10)
 
-#if !defined(_PSTL_PAR_BACKEND_SERIAL) && !defined(_PSTL_PAR_BACKEND_TBB)
+#if !defined(_PSTL_PAR_BACKEND_SERIAL) && !defined(_PSTL_PAR_BACKEND_TBB) && !defined(_PSTL_PAR_BACKEND_OMP)
 #    error "A parallel backend must be specified"
 #endif
 
@@ -96,7 +96,9 @@
 #endif
 
 // Should be defined to 1 for environments with a vendor implementation of C++17 execution policies
-#define _PSTL_CPP17_EXECUTION_POLICIES_PRESENT (_MSC_VER >= 1912)
+#define _PSTL_CPP17_EXECUTION_POLICIES_PRESENT                                                                         \
+    (_MSC_VER >= 1912 && _MSVC_LANG >= 201703L) ||                                                                     \
+        (_GLIBCXX_RELEASE >= 9 && __GLIBCXX__ >= 20190503 && __cplusplus >= 201703L)
 
 #if (defined(_MSC_VER) && _MSC_VER >= 1900) || \
     __cplusplus >= 201300L || \
Index: pstl/include/pstl/internal/parallel_backend.h
===================================================================
--- pstl/include/pstl/internal/parallel_backend.h
+++ pstl/include/pstl/internal/parallel_backend.h
@@ -24,6 +24,12 @@
 {
 namespace __par_backend = __tbb_backend;
 }
+#elif defined(_PSTL_PAR_BACKEND_OMP)
+#    include "parallel_backend_omp.h"
+namespace __pstl
+{
+namespace __par_backend = __omp_backend;
+}
 #else
 _PSTL_PRAGMA_MESSAGE("Parallel backend was not specified");
 #endif
Index: pstl/include/__pstl_config_site.in
===================================================================
--- pstl/include/__pstl_config_site.in
+++ pstl/include/__pstl_config_site.in
@@ -11,6 +11,7 @@
 
 #cmakedefine _PSTL_PAR_BACKEND_SERIAL
 #cmakedefine _PSTL_PAR_BACKEND_TBB
+#cmakedefine _PSTL_PAR_BACKEND_OMP
 #cmakedefine _PSTL_HIDE_FROM_ABI_PER_TU
 
 #endif // __PSTL_CONFIG_SITE
Index: pstl/CREDITS.txt
===================================================================
--- pstl/CREDITS.txt
+++ pstl/CREDITS.txt
@@ -15,3 +15,7 @@
 N: Thomas Rodgers
 E: trodgers at redhat.com
 D: Identifier name transformation for inclusion in a Standard C++ library.
+
+N: Christopher Nelson
+E: nadiasvertex at gmail.com
+D: Add support for an OpenMP backend.
\ No newline at end of file
Index: pstl/CMakeLists.txt
===================================================================
--- pstl/CMakeLists.txt
+++ pstl/CMakeLists.txt
@@ -43,6 +43,10 @@
     message(STATUS "Parallel STL uses TBB ${TBB_VERSION} (interface version: ${TBB_INTERFACE_VERSION})")
     target_link_libraries(ParallelSTL INTERFACE TBB::tbb)
     set(_PSTL_PAR_BACKEND_TBB ON)
+elseif (PSTL_PARALLEL_BACKEND STREQUAL "omp")
+    message(STATUS "Parallel STL uses the omp backend")
+    target_compile_options(ParallelSTL INTERFACE "-fopenmp=libomp")
+    set(_PSTL_PAR_BACKEND_OMP ON)
 else()
     message(FATAL_ERROR "Requested unknown Parallel STL backend '${PSTL_PARALLEL_BACKEND}'.")
 endif()
Index: libcxx/cmake/Modules/DefineLinkerScript.cmake
===================================================================
--- libcxx/cmake/Modules/DefineLinkerScript.cmake
+++ libcxx/cmake/Modules/DefineLinkerScript.cmake
@@ -31,7 +31,7 @@
   set(link_libraries)
   if (interface_libs)
     foreach(lib IN LISTS interface_libs)
-      if ("${lib}" STREQUAL "cxx-headers")
+      if ("${lib}" MATCHES "cxx-headers|ParallelSTL")
         continue()
       endif()
       # If ${lib} is not a target, we use a dummy target which we know will


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D99836.371034.patch
Type: text/x-patch
Size: 3707 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20210907/11382a5a/attachment.bin>


More information about the libcxx-commits mailing list