The parallel partial_sort narrows the range to [first, c_last) after
partitioning around a pivot, and calls itself on that part. When it did,
it returned what the recursive call returned, which is the end of the
narrowed range. The overloads documented to return last therefore
returned an iterator somewhere inside the range whenever the sorted
part had at least 4096 elements, which depends on the data: for 10007
elements it came back at 5612.
The early returns and the case that splits in two already return last.
Do the same for the call that narrows the range.
The existing tests only used ranges too small to reach that path. Add
one that does, for the synchronous and the task policy.
Signed-off-by: Arubik <102335860+ArubikU@users.noreply.github.com>
Fixes #8237
Proposed Changes
detail::parallel_partial_sortnarrows the range to[first, c_last)after partitioning, and calls itself on that part. It returned what that call returned, the end of the narrowed range, so the overloads documented to returnlastreturned an iterator inside the range once the sorted part had at least 4096 elements.last, as the early returns and the branch that splits in two already do.test_partial_sort_large_returns_lastinpartial_sort.cpp: 10007 and 100000 elements,parandpar(task), checking the returned iterator and the sorted prefix.Any background context you want to provide?
The existing tests check the returned iterator, but with sizes below the 4096-element threshold, so they never reach the narrowing path. The reproducer and the numbers (for 10007 elements it came back at 5612) are in #8237.
Checked with GCC 15.2 (C++20, local runtime): the new test fails without the change (both policies) and passes with it.
partial_sort_test,partial_sort_copy_testandpartial_sort_sender_testpass.I found this with a differential test of
hpx::rangesagainststd::ranges; happy to share it if it is of use.Checklist
Not all points below apply to all pull requests.