-
-
Notifications
You must be signed in to change notification settings - Fork 542
[parallel] Add projection support to hpx::is_sorted, hpx::is_sorted_until, and hpx::is_partitioned CPOs #7220
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
aneek22112007-tech
wants to merge
25
commits into
TheHPXProject:master
Choose a base branch
from
aneek22112007-tech:fix/is-sorted-is-partitioned-projection
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 9 commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
f91eb8d
[parallel] Add projection support to hpx::is_sorted, hpx::is_sorted_u…
dasaneek007-cpu 01e66d6
Remove inline comments from is_sorted_projection test
dasaneek007-cpu 118ce13
Fix is_sorted_until cross-chunk cancellation indexing bug
dasaneek007-cpu b1223a9
Fix clang-format issues in test file
dasaneek007-cpu 4e02198
Fix ambiguity in is_sorted and is_partitioned overloads and update tr…
dasaneek007-cpu aba2785
Apply clang-format
dasaneek007-cpu ccca6a4
Fix formatting, missing templates, and parallel logic for is_sorted a…
dasaneek007-cpu 4809671
Fix data races in parallel algorithms by ensuring per-chunk loops are…
dasaneek007-cpu 0bf482f
Fix iterator vs value type mismatch in util::loop_n callbacks
dasaneek007-cpu cdeb015
Fix segmented algorithm dispatch and standardize projection support f…
dasaneek007-cpu a0ba9ef
Address maintainer feedback for is_sorted and is_partitioned
dasaneek007-cpu eccc0e0
Merge branch 'master' into fix/is-sorted-is-partitioned-projection
aneek22112007-tech fff9af3
Stabilize is_sorted and is_partitioned for segmented iterators
dasaneek007-cpu 5f6a1f9
Fix CI failures: fix formatting, add missing includes, and resolve ma…
dasaneek007-cpu bab99a9
Address maintainer feedback: rename partition_status enums and remove…
dasaneek007-cpu c99a4d4
Resolve merge conflicts with upstream/master
dasaneek007-cpu 65cebbd
Fix clang-format: restore unmodified files to upstream state
dasaneek007-cpu 485facf
Merge branch 'master' into fix/is-sorted-is-partitioned-projection
aneek22112007-tech 93c17cb
Fix is_sorted and is_partitioned projection support and cleanup expor…
dasaneek007-cpu e588d25
Merge branch 'master' into fix/is-sorted-is-partitioned-projection
aneek22112007-tech 58b8b8f
Apply clang-format to projection support files
dasaneek007-cpu b2322b6
Fix export macros in projection traits and apply formatting
dasaneek007-cpu 2c30820
Comprehensive clang-format pass for all modified algorithm files
dasaneek007-cpu 01ea3cc
Final cleanup of CMakeLists.txt and test registration for projection …
dasaneek007-cpu be5aff9
Finalizing is_sorted and is_partitioned parallel algorithms: fix canc…
dasaneek007-cpu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| // Copyright (c) 2020 ETH Zurich | ||
| // Copyright (c) 2015 Daniel Bourgeois | ||
| // Copyright (c) 2017-2025 Hartmut Kaiser | ||
| // Copyright (c) 2017-2026 Hartmut Kaiser | ||
| // | ||
| // SPDX-License-Identifier: BSL-1.0 | ||
| // Distributed under the Boost Software License, Version 1.0. (See accompanying | ||
|
|
@@ -111,6 +111,7 @@ namespace hpx { | |
| #else | ||
|
|
||
| #include <hpx/config.hpp> | ||
| #include <hpx/algorithms/traits/projected.hpp> | ||
| #include <hpx/modules/executors.hpp> | ||
| #include <hpx/modules/functional.hpp> | ||
| #include <hpx/modules/iterator_support.hpp> | ||
|
|
@@ -120,6 +121,7 @@ namespace hpx { | |
| #include <hpx/parallel/util/detail/algorithm_result.hpp> | ||
| #include <hpx/parallel/util/detail/sender_util.hpp> | ||
| #include <hpx/parallel/util/invoke_projected.hpp> | ||
|
|
||
| #include <hpx/parallel/util/loop.hpp> | ||
| #include <hpx/parallel/util/partitioner.hpp> | ||
|
|
||
|
|
@@ -138,29 +140,8 @@ namespace hpx::parallel { | |
| namespace detail { | ||
|
|
||
| /// \cond NOINTERNAL | ||
| HPX_CXX_CORE_EXPORT template <typename T> | ||
| inline bool sequential_is_partitioned(std::vector<T>&& res) | ||
| { | ||
| auto first = res.begin(); | ||
| auto const last = res.end(); | ||
| while (first != last && hpx::unwrap(*first)) | ||
| { | ||
| ++first; | ||
| } | ||
| if (first != last) | ||
| { | ||
| ++first; | ||
| while (first != last) | ||
| { | ||
| if (hpx::unwrap(*first)) | ||
| return false; | ||
| ++first; | ||
| } | ||
| } | ||
| return true; | ||
| } | ||
|
|
||
| HPX_CXX_CORE_EXPORT template <typename Iter, typename Sent> | ||
| template <typename Iter, typename Sent> | ||
| struct is_partitioned | ||
| : public algorithm<is_partitioned<Iter, Sent>, bool> | ||
| { | ||
|
|
@@ -184,8 +165,7 @@ namespace hpx::parallel { | |
| static decltype(auto) parallel(ExPolicy&& policy, Iter_ first, | ||
| Sent_ last, Pred&& pred, Proj&& proj) | ||
| { | ||
| using difference_type = | ||
| typename std::iterator_traits<Iter_>::difference_type; | ||
| using difference_type = hpx::traits::iter_difference_t<Iter_>; | ||
| using result = util::detail::algorithm_result<ExPolicy, bool>; | ||
| constexpr bool has_scheduler_executor = | ||
| hpx::execution_policy_has_scheduler_executor_v<ExPolicy>; | ||
|
|
@@ -215,29 +195,49 @@ namespace hpx::parallel { | |
| -> intermediate_result_t { | ||
| bool fst_bool = HPX_INVOKE(pred_projected, *part_begin); | ||
| if (part_count == 1) | ||
| return fst_bool; | ||
| return fst_bool ? 1 : 0; | ||
|
|
||
| util::loop_n<std::decay_t<ExPolicy>>(++part_begin, | ||
| bool is_mixed = false; | ||
| util::loop_n<hpx::execution::sequenced_policy>(++part_begin, | ||
| --part_count, tok, | ||
| [&fst_bool, &pred_projected, &tok]( | ||
| Iter_ const& a) mutable -> void { | ||
| [&fst_bool, &is_mixed, &pred_projected, &tok]( | ||
| auto const& a) mutable -> void { | ||
| if (fst_bool != hpx::invoke(pred_projected, *a)) | ||
| { | ||
| if (fst_bool) | ||
| { | ||
| fst_bool = false; | ||
| is_mixed = true; | ||
| } | ||
| else | ||
| { | ||
| tok.cancel(); | ||
| } | ||
| } | ||
| }); | ||
|
|
||
| return fst_bool; | ||
| if (tok.was_cancelled()) | ||
| return 3; | ||
|
|
||
| return is_mixed ? 2 : (fst_bool ? 1 : 0); | ||
| }; | ||
|
|
||
| auto f2 = [tok](auto&& results) -> bool { | ||
| if (tok.was_cancelled()) | ||
| return false; | ||
| return sequential_is_partitioned( | ||
| HPX_FORWARD(decltype(results), results)); | ||
|
|
||
| auto it = std::find_if(hpx::util::begin(results), | ||
| hpx::util::end(results), | ||
| [](intermediate_result_t x) { return x != 1; }); | ||
|
|
||
| if (it == hpx::util::end(results)) | ||
| return true; | ||
|
|
||
| if (*it == 2) | ||
| ++it; | ||
|
|
||
| return std::all_of(it, hpx::util::end(results), | ||
| [](intermediate_result_t x) { return x == 0; }); | ||
| }; | ||
|
|
||
| return util::partitioner<ExPolicy, bool, | ||
|
|
@@ -258,7 +258,10 @@ namespace hpx { | |
| template <typename FwdIter, typename Pred> | ||
| // clang-format off | ||
| requires ( | ||
| std::forward_iterator<FwdIter> | ||
| std::forward_iterator<FwdIter> && | ||
| hpx::is_invocable_v<Pred, | ||
| hpx::traits::iter_value_t<FwdIter> | ||
| > | ||
| ) | ||
| // clang-format on | ||
| friend bool tag_fallback_invoke( | ||
|
|
@@ -273,7 +276,10 @@ namespace hpx { | |
| // clang-format off | ||
| requires ( | ||
| hpx::is_execution_policy_v<ExPolicy> && | ||
| std::forward_iterator<FwdIter> | ||
| std::forward_iterator<FwdIter> && | ||
| hpx::is_invocable_v<Pred, | ||
| hpx::traits::iter_value_t<FwdIter> | ||
| > | ||
| ) | ||
| // clang-format on | ||
| friend decltype(auto) tag_fallback_invoke(hpx::is_partitioned_t, | ||
|
|
@@ -283,6 +289,48 @@ namespace hpx { | |
| .call(HPX_FORWARD(ExPolicy, policy), first, last, | ||
| HPX_MOVE(pred), hpx::identity_v); | ||
| } | ||
|
|
||
| template <typename FwdIter, typename Pred, | ||
| typename Proj = hpx::identity> | ||
| // clang-format off | ||
| requires ( | ||
| std::forward_iterator<FwdIter> && | ||
| hpx::parallel::traits::is_projected_v<Proj, FwdIter> && | ||
| hpx::is_invocable_v<Pred, | ||
| hpx::util::invoke_result_t<Proj, | ||
| hpx::traits::iter_value_t<FwdIter>> | ||
| > | ||
| ) | ||
| // clang-format on | ||
| friend bool tag_fallback_invoke(hpx::is_partitioned_t, FwdIter first, | ||
| FwdIter last, Pred pred, Proj proj) | ||
| { | ||
| return hpx::parallel::detail::is_partitioned<FwdIter, FwdIter>() | ||
| .call(hpx::execution::seq, first, last, HPX_MOVE(pred), | ||
| HPX_MOVE(proj)); | ||
| } | ||
|
|
||
| template <typename ExPolicy, typename FwdIter, typename Pred, | ||
| typename Proj = hpx::identity> | ||
| // clang-format off | ||
| requires ( | ||
| hpx::is_execution_policy_v<ExPolicy> && | ||
| std::forward_iterator<FwdIter> && | ||
| hpx::parallel::traits::is_projected_v<Proj, FwdIter> && | ||
| hpx::is_invocable_v<Pred, | ||
| hpx::util::invoke_result_t<Proj, | ||
| hpx::traits::iter_value_t<FwdIter>> | ||
| > | ||
| ) | ||
| // clang-format on | ||
| friend decltype(auto) tag_fallback_invoke(hpx::is_partitioned_t, | ||
| ExPolicy&& policy, FwdIter first, FwdIter last, Pred pred, | ||
| Proj proj) | ||
| { | ||
| return hpx::parallel::detail::is_partitioned<FwdIter, FwdIter>() | ||
| .call(HPX_FORWARD(ExPolicy, policy), first, last, | ||
| HPX_MOVE(pred), HPX_MOVE(proj)); | ||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please revert the API changes. |
||
| } is_partitioned{}; | ||
| } // namespace hpx | ||
|
|
||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use an
enum classfor this.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed. I've introduced enum class partition_status to handle the different partitioning states clearly.