1 // -*- C++ -*-
2 // -*-===----------------------------------------------------------------------===//
3 //
4 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
5 //
6 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
7 // See https://llvm.org/LICENSE.txt for license information.
8 //
9 //===----------------------------------------------------------------------===//
10
11 #ifndef _PSTL_INTERNAL_OMP_PARALLEL_INVOKE_H
12 #define _PSTL_INTERNAL_OMP_PARALLEL_INVOKE_H
13
14 #include "util.h"
15
16 namespace __pstl
17 {
18 namespace __omp_backend
19 {
20
21 template <typename _F1, typename _F2>
22 void
__parallel_invoke_body(_F1 && __f1,_F2 && __f2)23 __parallel_invoke_body(_F1&& __f1, _F2&& __f2)
24 {
25 _PSTL_PRAGMA(omp taskgroup)
26 {
27 _PSTL_PRAGMA(omp task untied mergeable) { std::forward<_F1>(__f1)(); }
28 _PSTL_PRAGMA(omp task untied mergeable) { std::forward<_F2>(__f2)(); }
29 }
30 }
31
32 template <class _ExecutionPolicy, typename _F1, typename _F2>
33 void
__parallel_invoke(__pstl::__internal::__openmp_backend_tag,_ExecutionPolicy &&,_F1 && __f1,_F2 && __f2)34 __parallel_invoke(__pstl::__internal::__openmp_backend_tag, _ExecutionPolicy&&, _F1&& __f1, _F2&& __f2)
35 {
36 if (omp_in_parallel())
37 {
38 __pstl::__omp_backend::__parallel_invoke_body(std::forward<_F1>(__f1), std::forward<_F2>(__f2));
39 }
40 else
41 {
42 _PSTL_PRAGMA(omp parallel)
43 _PSTL_PRAGMA(omp single nowait)
44 __pstl::__omp_backend::__parallel_invoke_body(std::forward<_F1>(__f1), std::forward<_F2>(__f2));
45 }
46 }
47
48 } // namespace __omp_backend
49 } // namespace __pstl
50 #endif // _PSTL_INTERNAL_OMP_PARALLEL_INVOKE_H
51