Skip to content

Commit

Permalink
permit (expected side) overlaps on relocation
Browse files Browse the repository at this point in the history
  • Loading branch information
isidorostsa committed Dec 8, 2023
1 parent 84afafa commit 4fa59fd
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ namespace hpx {
#include <hpx/parallel/util/partitioner_with_cleanup.hpp>
#include <hpx/parallel/util/result_types.hpp>
#include <hpx/parallel/util/zip_iterator.hpp>
#include <hpx/type_support/construct_at.hpp>
#include <hpx/type_support/is_contiguous_iterator.hpp>
#include <hpx/type_support/uninitialized_relocation_primitives.hpp>

#include <algorithm>
Expand Down Expand Up @@ -739,10 +739,37 @@ namespace hpx::experimental {
FwdIter>::get(HPX_MOVE(dest));
}

// If running in non-sequenced execution policy, we must check
// that the ranges are not overlapping in the left
if constexpr (!hpx::is_sequenced_execution_policy_v<ExPolicy>)
{
// if we can check for overlapping ranges
if constexpr (hpx::traits::is_contiguous_iterator_v<InIter> &&
hpx::traits::is_contiguous_iterator_v<FwdIter>)
{
auto dest_last = std::next(dest, count);
auto last = std::next(first, count);
// if it is not overlapping in the left direction
if (!((first < dest_last) && (dest_last < last)))
{
// use parallel version
return parallel::util::get_second_element(
hpx::parallel::detail::uninitialized_relocate_n<
parallel::util::in_out_result<InIter,
FwdIter>>()
.call(HPX_FORWARD(ExPolicy, policy), first,
count, dest));
}
// if it is we continue to use the sequential version
}
// else we assume that the ranges are overlapping, and continue
// to use the sequential version
}

return parallel::util::get_second_element(
hpx::parallel::detail::uninitialized_relocate_n<
parallel::util::in_out_result<InIter, FwdIter>>()
.call(HPX_FORWARD(ExPolicy, policy), first,
.call(hpx::execution::seq, first,
static_cast<std::size_t>(count), dest));
}
} uninitialized_relocate_n{};
Expand Down Expand Up @@ -825,10 +852,37 @@ namespace hpx::experimental {
FwdIter>::get(HPX_MOVE(dest));
}

// If running in non-sequenced execution policy, we must check
// that the ranges are not overlapping in the left
if constexpr (!hpx::is_sequenced_execution_policy_v<ExPolicy>)
{
// if we can check for overlapping ranges
if constexpr (hpx::traits::is_contiguous_iterator_v<InIter1> &&
hpx::traits::is_contiguous_iterator_v<FwdIter>)
{
auto dest_last = std::next(dest, count);
// if it is not overlapping in the left direction
if (!((first < dest_last) && (dest_last < last)))
{
// use parallel version
return parallel::util::get_second_element(
hpx::parallel::detail::uninitialized_relocate_n<
parallel::util::in_out_result<InIter1,
FwdIter>>()
.call(HPX_FORWARD(ExPolicy, policy), first,
count, dest));
}
// if it is we continue to use the sequential version
}
// else we assume that the ranges are overlapping, and continue
// to use the sequential version
}

// sequential execution policy
return parallel::util::get_second_element(
hpx::parallel::detail::uninitialized_relocate_n<
parallel::util::in_out_result<InIter1, FwdIter>>()
.call(HPX_FORWARD(ExPolicy, policy), first, count, dest));
.call(hpx::execution::seq, first, count, dest));
}
} uninitialized_relocate{};

Expand Down Expand Up @@ -897,12 +951,6 @@ namespace hpx::experimental {
"Relocating from this source type to this destination type is "
"ill-formed");

if constexpr (!hpx::is_sequenced_execution_policy_v<ExPolicy>)
{
/*What should go here?*/
static_assert(false);
}

auto count = std::distance(first, last);

// if count is representing a negative value, we do nothing
Expand All @@ -912,11 +960,37 @@ namespace hpx::experimental {
BiIter2>::get(HPX_MOVE(dest_last));
}

// If running in non-sequence execution policy, we must check
// that the ranges are not overlapping in the right
if constexpr (!hpx::is_sequenced_execution_policy_v<ExPolicy>)
{
// if we can check for overlapping ranges
if constexpr (hpx::traits::is_contiguous_iterator_v<BiIter1> &&
hpx::traits::is_contiguous_iterator_v<BiIter2>)
{
auto dest_first = std::prev(dest_last, count);
// if it is not overlapping in the right direction
if (!((first < dest_first) && (dest_first < last)))
{
// use parallel version
return parallel::util::get_second_element(
hpx::parallel::detail::
uninitialized_relocate_backward<parallel::util::
in_out_result<BiIter1, BiIter2>>()
.call(HPX_FORWARD(ExPolicy, policy), first,
last, dest_last));
}
// if it is we continue to use the sequential version
}
// else we assume that the ranges are overlapping, and continue
// to use the sequential version
}

// sequential execution policy
return parallel::util::get_second_element(
hpx::parallel::detail::uninitialized_relocate_backward<
parallel::util::in_out_result<BiIter1, BiIter2>>()
.call(
HPX_FORWARD(ExPolicy, policy), first, last, dest_last));
.call(hpx::execution::seq, first, last, dest_last));
}
} uninitialized_relocate_backward{};
} // namespace hpx::experimental
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -361,13 +361,11 @@ void test()
return;
}

// template <typename Ex>
// void test_overlapping(Ex&& ex)
template <typename Ex>
void test_overlapping()
{
using Ex = hpx::execution::sequenced_policy;

static_assert(std::is_same_v<Ex, hpx::execution::sequenced_policy>);
// using Ex = hpx::execution::sequenced_policy;
// static_assert(std::is_same_v<Ex, hpx::execution::sequenced_policy>);

constexpr int offset = 4;

Expand Down Expand Up @@ -515,7 +513,8 @@ int hpx_main()
test<hpx::execution::sequenced_policy>();
test<hpx::execution::parallel_policy>();

test_overlapping();
test_overlapping<hpx::execution::sequenced_policy>();
test_overlapping<hpx::execution::parallel_policy>();

return hpx::local::finalize();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -361,13 +361,11 @@ void test()
return;
}

// template <typename Ex>
// void test_overlapping(Ex&& ex)
template <typename Ex>
void test_overlapping()
{
using Ex = hpx::execution::sequenced_policy;

static_assert(std::is_same_v<Ex, hpx::execution::sequenced_policy>);
// using Ex = hpx::execution::sequenced_policy;
// static_assert(std::is_same_v<Ex, hpx::execution::sequenced_policy>);

constexpr int offset = 4;

Expand Down Expand Up @@ -514,7 +512,8 @@ int hpx_main()
test<hpx::execution::sequenced_policy>();
test<hpx::execution::parallel_policy>();

test_overlapping();
test_overlapping<hpx::execution::sequenced_policy>();
test_overlapping<hpx::execution::parallel_policy>();

return hpx::local::finalize();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -361,13 +361,11 @@ void test()
return;
}

// template <typename Ex>
// void test_overlapping(Ex&& ex)
template <typename Ex>
void test_overlapping()
{
using Ex = hpx::execution::sequenced_policy;

static_assert(std::is_same_v<Ex, hpx::execution::sequenced_policy>);
// using Ex = hpx::execution::sequenced_policy;
// static_assert(std::is_same_v<Ex, hpx::execution::sequenced_policy>);

constexpr int offset = 4;

Expand Down Expand Up @@ -515,7 +513,8 @@ int hpx_main()
test<hpx::execution::sequenced_policy>();
test<hpx::execution::parallel_policy>();

test_overlapping();
test_overlapping<hpx::execution::sequenced_policy>();
test_overlapping<hpx::execution::parallel_policy>();

return hpx::local::finalize();
}
Expand Down

0 comments on commit 4fa59fd

Please sign in to comment.