Skip to content

Commit

Permalink
[oneDPL][ranges][merge] changes in __brick_merge_out_lim
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeDvorskiy committed Jan 28, 2025
1 parent 14bfc8f commit 66a26b6
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 25 deletions.
45 changes: 22 additions & 23 deletions include/oneapi/dpl/pstl/algorithm_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -2949,38 +2949,37 @@ __pattern_remove_if(__parallel_tag<_IsVector> __tag, _ExecutionPolicy&& __exec,
// merge
//------------------------------------------------------------------------

template <typename It1, typename It2, typename ItOut, typename _Comp>
std::pair<It1, It2>
__brick_merge_out_lim(It1 __it_1, It1 __it_1_e, It2 __it_2, It2 __it_2_e, ItOut __it_out, ItOut __it_out_e,
template <typename _Iterator1, typename _Iterator2, typename _Iterator3, typename _Comp>
std::pair<_Iterator1, _Iterator2>
__brick_merge_out_lim(_Iterator1 __x, _Iterator1 __x_e, _Iterator2 __y, _Iterator2 __y_e, _Iterator3 __i, _Iterator3 __j,
_Comp __comp, /* __is_vector = */ std::false_type)
{
while (__it_1 != __it_1_e && __it_2 != __it_2_e)
for (_Iterator3 __k = __i; __k < __j; ++__k)
{
if (std::invoke(__comp, *__it_1, *__it_2))
if (__x == __x_e)
{
assert(__y != __y_e);
*__k = *__y;
++__y;
}
else if (__y == __y_e)
{
assert(__x != __x_e);
*__k = *__x;
++__x;
}
else if (std::invoke(__comp, *__x, *__y))
{
*__it_out = *__it_1;
++__it_out, ++__it_1;
*__k = *__x;
++__x;
}
else
{
*__it_out = *__it_2;
++__it_out, ++__it_2;
*__k = *__y;
++__y;
}
if (__it_out == __it_out_e)
return {__it_1, __it_2};
}

if (__it_1 == __it_1_e)
{
for (; __it_2 != __it_2_e && __it_out != __it_out_e; ++__it_2, ++__it_out)
*__it_out = *__it_2;
}
else
{
for (; __it_1 != __it_1_e && __it_out != __it_out_e; ++__it_1, ++__it_out)
*__it_out = *__it_1;
}
return {__it_1, __it_2};
return {__x, __y};
}

template <typename It1, typename It2, typename ItOut, typename _Comp>
Expand Down
4 changes: 2 additions & 2 deletions include/oneapi/dpl/pstl/parallel_backend_tbb.h
Original file line number Diff line number Diff line change
Expand Up @@ -713,6 +713,8 @@ class __root_task : public __task
};
#endif // TBB_INTERFACE_VERSION <= 12000

inline constexpr _SizeType __merge_cut_off = 2000;

template <typename _RandomAccessIterator1, typename _RandomAccessIterator2, typename _Compare, typename _Cleanup,
typename _LeafMerge>
class __merge_func
Expand All @@ -732,8 +734,6 @@ class __merge_func
_LeafMerge _M_leaf_merge;
_SizeType _M_nsort; //number of elements to be sorted for partial_sort algorithm

static const _SizeType __merge_cut_off = 2000;

bool _root; //means a task is merging root task
bool _x_orig; //"true" means X(or left ) subrange is in the original container; false - in the buffer
bool _y_orig; //"true" means Y(or right) subrange is in the original container; false - in the buffer
Expand Down

0 comments on commit 66a26b6

Please sign in to comment.