Skip to content

Commit

Permalink
[pstl] A hot compilation fix for MacOS, OpenMP backend; + full qualif…
Browse files Browse the repository at this point in the history
…ied names for some internal functions

Reviewed By: nadiasvertex, ldionne

Differential Revision: https://reviews.llvm.org/D112528
  • Loading branch information
MikeDvorskiy committed Oct 27, 2021
1 parent 9cc08cb commit 05a4b0d
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 19 deletions.
2 changes: 1 addition & 1 deletion pstl/include/pstl/internal/omp/parallel_for.h
Expand Up @@ -31,7 +31,7 @@ __parallel_for_body(_Index __first, _Index __last, _Fp __f)
_PSTL_PRAGMA(omp taskloop untied mergeable)
for (std::size_t __chunk = 0; __chunk < __policy.__n_chunks; ++__chunk)
{
__omp_backend::__process_chunk(__policy, __first, __chunk, __f);
__pstl::__omp_backend::__process_chunk(__policy, __first, __chunk, __f);
}
}

Expand Down
4 changes: 2 additions & 2 deletions pstl/include/pstl/internal/omp/parallel_invoke.h
Expand Up @@ -35,13 +35,13 @@ __parallel_invoke(_ExecutionPolicy&&, _F1&& __f1, _F2&& __f2)
{
if (omp_in_parallel())
{
__parallel_invoke_body(std::forward<_F1>(__f1), std::forward<_F2>(__f2));
__pstl::__omp_backend::__parallel_invoke_body(std::forward<_F1>(__f1), std::forward<_F2>(__f2));
}
else
{
_PSTL_PRAGMA(omp parallel)
_PSTL_PRAGMA(omp single nowait)
__parallel_invoke_body(std::forward<_F1>(__f1), std::forward<_F2>(__f2));
__pstl::__omp_backend::__parallel_invoke_body(std::forward<_F1>(__f1), std::forward<_F2>(__f2));
}
}

Expand Down
12 changes: 8 additions & 4 deletions pstl/include/pstl/internal/omp/parallel_merge.h
Expand Up @@ -50,11 +50,13 @@ __parallel_merge_body(std::size_t __size_x, std::size_t __size_y, _RandomAccessI

_PSTL_PRAGMA(omp task untied mergeable default(none)
firstprivate(__xs, __xm, __ys, __ym, __zs, __comp, __leaf_merge))
__parallel_merge_body(__xm - __xs, __ym - __ys, __xs, __xm, __ys, __ym, __zs, __comp, __leaf_merge);
__pstl::__omp_backend::__parallel_merge_body(__xm - __xs, __ym - __ys, __xs, __xm, __ys, __ym, __zs, __comp,
__leaf_merge);

_PSTL_PRAGMA(omp task untied mergeable default(none)
firstprivate(__xm, __xe, __ym, __ye, __zm, __comp, __leaf_merge))
__parallel_merge_body(__xe - __xm, __ye - __ym, __xm, __xe, __ym, __ye, __zm, __comp, __leaf_merge);
__pstl::__omp_backend::__parallel_merge_body(__xe - __xm, __ye - __ym, __xm, __xe, __ym, __ye, __zm, __comp,
__leaf_merge);

_PSTL_PRAGMA(omp taskwait)
}
Expand All @@ -77,14 +79,16 @@ __parallel_merge(_ExecutionPolicy&& /*__exec*/, _RandomAccessIterator1 __xs, _Ra

if (omp_in_parallel())
{
__parallel_merge_body(__size_x, __size_y, __xs, __xe, __ys, __ye, __zs, __comp, __leaf_merge);
__pstl::__omp_backend::__parallel_merge_body(__size_x, __size_y, __xs, __xe, __ys, __ye, __zs, __comp,
__leaf_merge);
}
else
{
_PSTL_PRAGMA(omp parallel)
{
_PSTL_PRAGMA(omp single nowait)
__parallel_merge_body(__size_x, __size_y, __xs, __xe, __ys, __ye, __zs, __comp, __leaf_merge);
__pstl::__omp_backend::__parallel_merge_body(__size_x, __size_y, __xs, __xe, __ys, __ye, __zs, __comp,
__leaf_merge);
}
}
}
Expand Down
24 changes: 13 additions & 11 deletions pstl/include/pstl/internal/omp/parallel_stable_sort.h
Expand Up @@ -12,6 +12,7 @@
#define _PSTL_INTERNAL_OMP_PARALLEL_STABLE_SORT_H

#include "util.h"
#include "parallel_merge.h"

namespace __pstl
{
Expand Down Expand Up @@ -44,12 +45,12 @@ __parallel_move_range(_RandomAccessIterator __first1, _RandomAccessIterator __la
}

// Perform parallel moving of larger chunks
auto __policy = __omp_backend::__chunk_partitioner(__first1, __last1);
auto __policy = __pstl::__omp_backend::__chunk_partitioner(__first1, __last1);

_PSTL_PRAGMA(omp taskloop)
for (std::size_t __chunk = 0; __chunk < __policy.__n_chunks; ++__chunk)
{
__omp_backend::__process_chunk(__policy, __first1, __chunk,
__pstl::__omp_backend::__process_chunk(__policy, __first1, __chunk,
[&](auto __chunk_first, auto __chunk_last)
{
auto __chunk_offset = __chunk_first - __first1;
Expand All @@ -67,7 +68,7 @@ struct __move_range
_OutputIterator
operator()(_RandomAccessIterator __first1, _RandomAccessIterator __last1, _OutputIterator __d_first) const
{
return __parallel_move_range(__first1, __last1, __d_first);
return __pstl::__omp_backend::__sort_details::__parallel_move_range(__first1, __last1, __d_first);
}
};
} // namespace __sort_details
Expand All @@ -91,23 +92,24 @@ __parallel_stable_sort_body(_RandomAccessIterator __xs, _RandomAccessIterator __
{
std::size_t __size = __xe - __xs;
auto __mid = __xs + (__size / 2);
__parallel_invoke_body([&]() { __parallel_stable_sort_body(__xs, __mid, __comp, __leaf_sort); },
[&]() { __parallel_stable_sort_body(__mid, __xe, __comp, __leaf_sort); });
__pstl::__omp_backend::__parallel_invoke_body(
[&]() { __parallel_stable_sort_body(__xs, __mid, __comp, __leaf_sort); },
[&]() { __parallel_stable_sort_body(__mid, __xe, __comp, __leaf_sort); });

// Perform a parallel merge of the sorted ranges into __output_data.
_VecType __output_data(__size);
_MoveValue __move_value;
_MoveRange __move_range;
__utils::__serial_move_merge __merge(__size);
__parallel_merge_body(
__pstl::__omp_backend::__parallel_merge_body(
__mid - __xs, __xe - __mid, __xs, __mid, __mid, __xe, __output_data.begin(), __comp,
[&__merge, &__move_value, &__move_range](_RandomAccessIterator __as, _RandomAccessIterator __ae,
_RandomAccessIterator __bs, _RandomAccessIterator __be,
_OutputIterator __cs, _Compare __comp)
{ __merge(__as, __ae, __bs, __be, __cs, __comp, __move_value, __move_value, __move_range, __move_range); });

// Move the values from __output_data back in the original source range.
__omp_backend::__sort_details::__parallel_move_range(__output_data.begin(), __output_data.end(), __xs);
__pstl::__omp_backend::__sort_details::__parallel_move_range(__output_data.begin(), __output_data.end(), __xs);
}
}

Expand All @@ -130,11 +132,11 @@ __parallel_stable_sort(_ExecutionPolicy&& /*__exec*/, _RandomAccessIterator __xs
{
if (__count <= __nsort)
{
__parallel_stable_sort_body(__xs, __xe, __comp, __leaf_sort);
__pstl::__omp_backend::__parallel_stable_sort_body(__xs, __xe, __comp, __leaf_sort);
}
else
{
__parallel_stable_partial_sort(__xs, __xe, __comp, __leaf_sort, __nsort);
__pstl::__omp_backend::__parallel_stable_partial_sort(__xs, __xe, __comp, __leaf_sort, __nsort);
}
}
else
Expand All @@ -143,11 +145,11 @@ __parallel_stable_sort(_ExecutionPolicy&& /*__exec*/, _RandomAccessIterator __xs
_PSTL_PRAGMA(omp single nowait)
if (__count <= __nsort)
{
__parallel_stable_sort_body(__xs, __xe, __comp, __leaf_sort);
__pstl::__omp_backend::__parallel_stable_sort_body(__xs, __xe, __comp, __leaf_sort);
}
else
{
__parallel_stable_partial_sort(__xs, __xe, __comp, __leaf_sort, __nsort);
__pstl::__omp_backend::__parallel_stable_partial_sort(__xs, __xe, __comp, __leaf_sort, __nsort);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion pstl/include/pstl/internal/omp/parallel_transform_reduce.h
Expand Up @@ -60,7 +60,7 @@ __transform_reduce_body(_RandomAccessIterator __first, _RandomAccessIterator __l
_PSTL_PRAGMA(omp taskloop shared(__accums))
for (std::size_t __chunk = 0; __chunk < __policy.__n_chunks; ++__chunk)
{
__omp_backend::__process_chunk(__policy, __first + __num_threads, __chunk,
__pstl::__omp_backend::__process_chunk(__policy, __first + __num_threads, __chunk,
[&](auto __chunk_first, auto __chunk_last)
{
auto __thread_num = omp_get_thread_num();
Expand Down

0 comments on commit 05a4b0d

Please sign in to comment.