Skip to content
Open
Show file tree
Hide file tree
Changes from 12 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 Apr 22, 2026
01e66d6
Remove inline comments from is_sorted_projection test
dasaneek007-cpu Apr 22, 2026
118ce13
Fix is_sorted_until cross-chunk cancellation indexing bug
dasaneek007-cpu Apr 22, 2026
b1223a9
Fix clang-format issues in test file
dasaneek007-cpu Apr 23, 2026
4e02198
Fix ambiguity in is_sorted and is_partitioned overloads and update tr…
dasaneek007-cpu Apr 23, 2026
aba2785
Apply clang-format
dasaneek007-cpu Apr 23, 2026
ccca6a4
Fix formatting, missing templates, and parallel logic for is_sorted a…
dasaneek007-cpu Apr 23, 2026
4809671
Fix data races in parallel algorithms by ensuring per-chunk loops are…
dasaneek007-cpu Apr 23, 2026
0bf482f
Fix iterator vs value type mismatch in util::loop_n callbacks
dasaneek007-cpu Apr 23, 2026
cdeb015
Fix segmented algorithm dispatch and standardize projection support f…
dasaneek007-cpu Apr 24, 2026
a0ba9ef
Address maintainer feedback for is_sorted and is_partitioned
dasaneek007-cpu Apr 24, 2026
eccc0e0
Merge branch 'master' into fix/is-sorted-is-partitioned-projection
aneek22112007-tech Apr 24, 2026
fff9af3
Stabilize is_sorted and is_partitioned for segmented iterators
dasaneek007-cpu Apr 24, 2026
5f6a1f9
Fix CI failures: fix formatting, add missing includes, and resolve ma…
dasaneek007-cpu Apr 24, 2026
bab99a9
Address maintainer feedback: rename partition_status enums and remove…
dasaneek007-cpu Apr 27, 2026
c99a4d4
Resolve merge conflicts with upstream/master
dasaneek007-cpu Apr 27, 2026
65cebbd
Fix clang-format: restore unmodified files to upstream state
dasaneek007-cpu Apr 27, 2026
485facf
Merge branch 'master' into fix/is-sorted-is-partitioned-projection
aneek22112007-tech Apr 28, 2026
93c17cb
Fix is_sorted and is_partitioned projection support and cleanup expor…
dasaneek007-cpu Apr 28, 2026
e588d25
Merge branch 'master' into fix/is-sorted-is-partitioned-projection
aneek22112007-tech Apr 28, 2026
58b8b8f
Apply clang-format to projection support files
dasaneek007-cpu Apr 28, 2026
b2322b6
Fix export macros in projection traits and apply formatting
dasaneek007-cpu Apr 28, 2026
2c30820
Comprehensive clang-format pass for all modified algorithm files
dasaneek007-cpu Apr 28, 2026
01ea3cc
Final cleanup of CMakeLists.txt and test registration for projection …
dasaneek007-cpu Apr 28, 2026
be5aff9
Finalizing is_sorted and is_partitioned parallel algorithms: fix canc…
dasaneek007-cpu Apr 29, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Expand Down Expand Up @@ -111,6 +111,8 @@ namespace hpx {
#else

#include <hpx/config.hpp>
#include <hpx/algorithms/traits/projected.hpp>
#include <hpx/modules/execution.hpp>
#include <hpx/modules/executors.hpp>
#include <hpx/modules/functional.hpp>
#include <hpx/modules/iterator_support.hpp>
Expand All @@ -120,6 +122,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>

Expand All @@ -136,36 +139,22 @@ namespace hpx::parallel {
////////////////////////////////////////////////////////////////////////////
// is_partitioned
namespace detail {
enum class partition_status : std::uint8_t
{
false_ = 0,
Comment thread
hkaiser marked this conversation as resolved.
Outdated
true_ = 1,
mixed = 2,
cancelled = 3
};

/// \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>
{
constexpr is_partitioned() noexcept
: algorithm<is_partitioned, bool>("is_partitioned")
: algorithm<is_partitioned<Iter, Sent>, bool>("is_partitioned")
{
}

Expand All @@ -184,8 +173,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>;
Expand All @@ -208,36 +196,68 @@ namespace hpx::parallel {
util::invoke_projected<Pred, Proj> pred_projected(
HPX_FORWARD(Pred, pred), HPX_FORWARD(Proj, proj));
util::cancellation_token<> tok;
using intermediate_result_t = std::uint8_t;
using intermediate_result_t = partition_status;

auto f1 = [tok, pred_projected = HPX_MOVE(pred_projected)](
Iter_ part_begin, std::size_t part_count) mutable
-> intermediate_result_t {
bool fst_bool = HPX_INVOKE(pred_projected, *part_begin);
if (part_count == 1)
return fst_bool;
return fst_bool ? partition_status::true_ :
partition_status::false_;

bool is_mixed = false;

using local_policy = std::conditional_t<
hpx::is_unsequenced_execution_policy_v<
std::decay_t<ExPolicy>>,
hpx::execution::unsequenced_policy,
hpx::execution::sequenced_policy>;
Comment thread
hkaiser marked this conversation as resolved.
Outdated

util::loop_n<std::decay_t<ExPolicy>>(++part_begin,
--part_count, tok,
[&fst_bool, &pred_projected, &tok](
Iter_ const& a) mutable -> void {
util::loop_n<local_policy>(++part_begin, --part_count, tok,
[&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 partition_status::cancelled;

return is_mixed ? partition_status::mixed :
(fst_bool ? partition_status::true_ :
partition_status::false_);
};

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), [](partition_status x) {
return x != partition_status::true_;
});

if (it == hpx::util::end(results))
return true;

if (*it == partition_status::mixed)
++it;

return std::all_of(it, hpx::util::end(results),
[](partition_status x) {
return x == partition_status::false_;
});
};

return util::partitioner<ExPolicy, bool,
Expand All @@ -258,7 +278,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(
Expand All @@ -273,7 +296,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,
Expand All @@ -283,6 +309,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));
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please revert the API changes.

} is_partitioned{};
} // namespace hpx

Expand Down
Loading
Loading