Skip to content

Commit

Permalink
Merge pull request #6494 from zhekemist/add-sr-unit-tests
Browse files Browse the repository at this point in the history
Add unit test cases and fixes for the S/R versions of the parallel algorithms
  • Loading branch information
hkaiser authored Sep 3, 2024
2 parents e43a4ec + e35074d commit f4ff6e8
Show file tree
Hide file tree
Showing 143 changed files with 8,571 additions and 1,175 deletions.
6 changes: 2 additions & 4 deletions .circleci/tests.unit1.algorithms
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

tests.unit.modules.algorithms.algorithms.adjacentdifference
tests.unit.modules.algorithms.algorithms.adjacentdifference_sender
tests.unit.modules.algorithms.algorithms.adjacentfind
tests.unit.modules.algorithms.algorithms.adjacentfind_binary
tests.unit.modules.algorithms.algorithms.all_of
Expand All @@ -31,7 +30,6 @@ tests.unit.modules.algorithms.algorithms.exclusive_scan_validate
tests.unit.modules.algorithms.algorithms.fill
tests.unit.modules.algorithms.algorithms.filln
tests.unit.modules.algorithms.algorithms.find
tests.unit.modules.algorithms.algorithms.find_sender
tests.unit.modules.algorithms.algorithms.findend
tests.unit.modules.algorithms.algorithms.findfirstof
tests.unit.modules.algorithms.algorithms.findfirstof_binary
Expand All @@ -40,7 +38,6 @@ tests.unit.modules.algorithms.algorithms.findifnot
tests.unit.modules.algorithms.algorithms.foreach
tests.unit.modules.algorithms.algorithms.foreach_executors
tests.unit.modules.algorithms.algorithms.foreach_prefetching
tests.unit.modules.algorithms.algorithms.foreach_sender
tests.unit.modules.algorithms.algorithms.foreach_scheduler
tests.unit.modules.algorithms.algorithms.foreachn
tests.unit.modules.algorithms.algorithms.foreachn_exception
Expand All @@ -53,7 +50,6 @@ tests.unit.modules.algorithms.algorithms.for_loop_n
tests.unit.modules.algorithms.algorithms.for_loop_n_strided
tests.unit.modules.algorithms.algorithms.for_loop_reduction
tests.unit.modules.algorithms.algorithms.for_loop_reduction_async
tests.unit.modules.algorithms.algorithms.for_loop_sender
tests.unit.modules.algorithms.algorithms.for_loop_strided
tests.unit.modules.algorithms.algorithms.generate
tests.unit.modules.algorithms.algorithms.generaten
Expand All @@ -74,3 +70,5 @@ tests.unit.modules.algorithms.algorithms.min_element
tests.unit.modules.algorithms.algorithms.minmax_element
tests.unit.modules.algorithms.algorithms.mismatch
tests.unit.modules.algorithms.algorithms.mismatch_binary
tests.unit.modules.algorithms.algorithms.move
tests.unit.modules.algorithms.algorithms.nth_element
5 changes: 0 additions & 5 deletions .circleci/tests.unit2.algorithms
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
# Distributed under the Boost Software License, Version 1.0. (See accompanying
# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

tests.unit.modules.algorithms.algorithms.move
tests.unit.modules.algorithms.algorithms.nth_element
tests.unit.modules.algorithms.algorithms.none_of
tests.unit.modules.algorithms.algorithms.parallel_sort
tests.unit.modules.algorithms.algorithms.partial_sort
Expand All @@ -15,7 +13,6 @@ tests.unit.modules.algorithms.algorithms.partition_copy
tests.unit.modules.algorithms.algorithms.reduce_
tests.unit.modules.algorithms.algorithms.reduce_by_key
tests.unit.modules.algorithms.algorithms.remove
tests.unit.modules.algorithms.algorithms.remove
tests.unit.modules.algorithms.algorithms.remove1
tests.unit.modules.algorithms.algorithms.remove2
tests.unit.modules.algorithms.algorithms.remove_if
Expand All @@ -28,10 +25,8 @@ tests.unit.modules.algorithms.algorithms.replace_copy
tests.unit.modules.algorithms.algorithms.replace_copy_if
tests.unit.modules.algorithms.algorithms.reverse
tests.unit.modules.algorithms.algorithms.reverse_copy
tests.unit.modules.algorithms.algorithms.reverse_sender
tests.unit.modules.algorithms.algorithms.rotate
tests.unit.modules.algorithms.algorithms.rotate_copy
tests.unit.modules.algorithms.algorithms.rotate_sender
tests.unit.modules.algorithms.algorithms.search
tests.unit.modules.algorithms.algorithms.searchn
tests.unit.modules.algorithms.algorithms.set_difference
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,27 +276,34 @@ namespace hpx::parallel {
util::detail::algorithm_result<ExPolicy, FwdIter2>;
using difference_type =
typename std::iterator_traits<FwdIter1>::difference_type;

constexpr bool scheduler_policy =
constexpr bool has_scheduler_policy =
hpx::execution_policy_has_scheduler_executor_v<ExPolicy>;

if constexpr (!scheduler_policy)
FwdIter1 prev = first;
difference_type count;

if (first == last)
{
if (first == last)
if constexpr (!has_scheduler_policy)
{
return result::get(HPX_MOVE(dest));
}
else
{
count = static_cast<difference_type>(0);
}
}
else
{
count = detail::distance(first, last) - 1;

difference_type count = detail::distance(first, last) - 1;

FwdIter1 prev = first;
hpx::traits::proxy_value_t<
typename std::iterator_traits<FwdIter1>::value_type>
tmp = *first++;
*dest++ = HPX_MOVE(tmp);
hpx::traits::proxy_value_t<
typename std::iterator_traits<FwdIter1>::value_type>
tmp = *first++;
*dest++ = HPX_MOVE(tmp);
}

if constexpr (!scheduler_policy)
if constexpr (!has_scheduler_policy)
{
if (count == 0)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,18 +173,24 @@ namespace hpx::parallel {

template <typename ExPolicy, typename FwdIter, typename Sent_,
typename Pred, typename Proj>
static util::detail::algorithm_result_t<ExPolicy, FwdIter> parallel(
ExPolicy&& orgpolicy, FwdIter first, Sent_ last, Pred&& pred,
Proj&& proj)
static decltype(auto) parallel(ExPolicy&& orgpolicy, FwdIter first,
Sent_ last, Pred&& pred, Proj&& proj)
{
using zip_iterator = hpx::util::zip_iterator<FwdIter, FwdIter>;
using difference_type =
typename std::iterator_traits<FwdIter>::difference_type;
using result =
util::detail::algorithm_result<ExPolicy, FwdIter>;

if (first == last)
constexpr bool has_scheduler_executor =
hpx::execution_policy_has_scheduler_executor_v<ExPolicy>;

if constexpr (!has_scheduler_executor)
{
return util::detail::algorithm_result<ExPolicy,
FwdIter>::get(HPX_MOVE(last));
if (first == last)
{
return result::get(HPX_MOVE(last));
}
}

decltype(auto) policy = parallel::util::adapt_placement_mode(
Expand All @@ -209,10 +215,15 @@ namespace hpx::parallel {
};

auto f2 = [tok, count, first, last](
auto&& data) mutable -> FwdIter {
// make sure iterators embedded in function object that is
// attached to futures are invalidated
util::detail::clear_container(data);
auto&&... data) mutable -> FwdIter {
static_assert(sizeof...(data) < 2);
if constexpr (sizeof...(data) == 1)
{
// make sure iterators embedded in function object that
// is attached to futures are invalidated
util::detail::clear_container(data...);
}

difference_type adj_find_res = tok.get_data();
if (adj_find_res != count)
{
Expand All @@ -222,9 +233,16 @@ namespace hpx::parallel {
{
first = last;
}
return HPX_MOVE(first);
return first;
};

if constexpr (has_scheduler_executor)
{
// underflow prevention for the upcoming call
if (count == 0)
++count;
}

using partitioner_type =
util::partitioner<policy_type, FwdIter, void>;
return partitioner_type::call_with_index(
Expand Down Expand Up @@ -269,10 +287,8 @@ namespace hpx {
hpx::traits::is_forward_iterator_v<FwdIter>
)>
// clang-format on
friend typename parallel::util::detail::algorithm_result<ExPolicy,
FwdIter>::type
tag_fallback_invoke(hpx::adjacent_find_t, ExPolicy&& policy,
FwdIter first, FwdIter last, Pred pred = Pred())
friend decltype(auto) tag_fallback_invoke(hpx::adjacent_find_t,
ExPolicy&& policy, FwdIter first, FwdIter last, Pred pred = Pred())
{
static_assert(hpx::traits::is_forward_iterator_v<FwdIter>,
"Requires at least a forward iterator");
Expand Down
Loading

0 comments on commit f4ff6e8

Please sign in to comment.