-
-
Notifications
You must be signed in to change notification settings - Fork 428
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
Adapting iterator requirements for parallel algorithms #2733
Conversation
- flyby: simplified destroy
…thms/is_heap.hpp - flyby: add return types to lambdas
CMakeLists.txt
Outdated
@@ -912,6 +912,14 @@ if(HPX_WITH_INCLUSIVE_SCAN_COMPATIBILITY) | |||
hpx_add_config_define(HPX_HAVE_INCLUSIVE_SCAN_COMPATIBILITY) | |||
endif() | |||
|
|||
# HPX_WITH_ALGORITHM_INPUT_ITERATOR_SUPPORT: introduced in V1.1.0 | |||
hpx_option(HPX_WITH_ALGORITHM_INPUT_ITERATOR_SUPPORT BOOL | |||
"Enable old overloads for inclkusive_scan (default: OFF)" |
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.
There is a typo here. should read inclusive_scan
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.
That's already fixed on master.
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.
This PR will bring the typo back though, no?
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.
I think you are referring to a different option.
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.
Yah, you are right, this was a copy & paste problem to begin with. Should be fixed now.
hpx/parallel/algorithms/copy.hpp
Outdated
>::type | ||
copy(ExPolicy && policy, InIter first, InIter last, OutIter dest) | ||
copy(ExPolicy && policy, FwdIter first, FwdIter last, OutIter dest) |
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.
Why didn't you change OutIter
? As I think, dest
is forward iterator, too.
This comment is applied on other many codes, too.
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.
I just left the type-name as OutIter
, the requirements are updated to 'forward iterator'.
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.
Is there any specific reason to left the type-name as OutIter
?
As I think, FwdIter
seems better because FwdIter
can imply 'forward iterator'.
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.
No specific reason, no. I guess I wanted to keep it clear that this parameter is used as a destination iterator...
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.
@hkaiser I understand your intention. But, using OutIter
seems not clear because it can't imply forward iterator. As I think, an user can know that it is used as a destination iterator through parameter name.
This naming issue may be tiny thing, but I want to clarify because the naming will be used from all PRs in future.
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.
In cppreference.com, FwdIter
is used for destination iterator.
And in c++ standard document, you search keyword 'copy_backward', then you can find that such naming way is used.
(http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3797.pdf)
hpx/parallel/algorithms/copy.hpp
Outdated
/// \tparam OutIter The type of the iterator representing the | ||
/// destination range (deduced). | ||
/// This iterator type must meet the requirements of an | ||
/// output iterator. | ||
/// forward iterator. |
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.
Why is naming inconsistent to documentation?
The parameter type is OutIter
. But, it is illustrated to forward iterator
in documentation.
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.
I just left the type-name as OutIter
, the requirements are updated to 'forward iterator'.
hpx/parallel/algorithms/fill.hpp
Outdated
HPX_HOST_DEVICE | ||
static hpx::util::unused_type | ||
sequential(ExPolicy, InIter first, InIter last, | ||
sequential(ExPolicy, FwdIter first, FwdIter last, |
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.
Apart from adapting the parallel algorithm interface to the standard, this sequential function requires just InputIterator. So I think that InIter
is correct in this position. How do you think?
This comment is applied to many spots in this PR, too.
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.
Yes, this could be left as InIter
, but it will never be called with an input iterator... Not sure how to proceed.
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.
Right, it will never be called with an input iterator. But, regardless of execution flow, as one independent function, clarifying iterator requirements seems better. If anyone refer this function for another implementation, he(she) may misunderstand that this function only works with forward iterator.
@taeguk Ok, I'm done with the renaming, please review. |
static typename util::detail::algorithm_result< | ||
ExPolicy, Iter | ||
>::type | ||
parallel(ExPolicy && policy, FwdIter first, FwdIter last, | ||
parallel(ExPolicy && policy, FwdIter1 first, FwdIter1 last, |
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.
There is tiny inconsistent thing.
When there is only one forward iterator type in parameters,
FwdIter
is used in some places, but FwdIter1
is used in others.
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.
As I think,
when there is only one forward iterator type in parameters,
changing naming from FwdIter1
to FwdIter
is better.
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.
ok.
inline typename std::enable_if< | ||
execution::is_execution_policy<ExPolicy>::value, | ||
typename util::detail::algorithm_result<ExPolicy, bool>::type | ||
>::type | ||
none_of(ExPolicy && policy, InIter first, InIter last, F && f) | ||
none_of(ExPolicy && policy, FwdIter first, FwdIter last, F && f) |
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.
There is tiny inconsistent thing.
When there is only one forward iterator type in parameters,
FwdIter
is used in some places, but FwdIter1
is used in others.
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.
This one is actually correct, I believe.
>::type | ||
transfer_(ExPolicy && policy, InIter first, InIter last, OutIter dest, | ||
transfer_(ExPolicy && policy, FwdIter first, FwdIter last, OutIter dest, |
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.
Still, there is OutIter
in here. Maybe this is your mistake.
>::type | ||
transfer(ExPolicy && policy, InIter first, InIter last, OutIter dest) | ||
transfer(ExPolicy && policy, FwdIter first, FwdIter last, OutIter dest) |
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.
Still, there is OutIter
in here. Maybe this is your mistake.
>::type | ||
transfer_(ExPolicy && policy, InIter first, InIter last, OutIter dest, | ||
transfer_(ExPolicy && policy, FwdIter first, FwdIter last, OutIter dest, |
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.
Still, there is OutIter
in here. Maybe this is your mistake.
!hpx::traits::is_random_access_iterator<OutIter>::value | ||
!hpx::traits::is_random_access_iterator<FwdIter1>::value || | ||
!hpx::traits::is_random_access_iterator<FwdIter2>::value || | ||
!hpx::traits::is_random_access_iterator<FwdIter3>::value |
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.
Why is hpx::traits::is_random_access_iterator
used instead of hpx::traits::is_forward_iterator
?
And, this typedef of is_seq should be inside conditional macro above as I think.
This is applied to other places like set algorithms.
@@ -84,7 +85,7 @@ namespace hpx { namespace parallel { inline namespace v1 | |||
/// It describes the manner in which the execution | |||
/// of the algorithm may be parallelized and the manner | |||
/// in which it executes the swap operations. | |||
/// \tparam ForwardIter1 The type of the first range of iterators to swap | |||
/// \tparam FwdIter1 The type of the first range of iterators to swap |
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.
More spaces are needed for beauty.
/// input iterator. | ||
/// \tparam OutIter The type of the iterator representing the | ||
/// forward iterator. | ||
/// \tparam FwdIter3 se The type of the iterator representing the |
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.
what is it? :)
sequential(ExPolicy, InIter first, InIter last, | ||
OutIter dest, Conv && conv, T && init, Op && op) | ||
FwdIter2 dest, Conv && conv, T && init, Op && op) |
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.
Maybe FwdIter2
should be changed to OutIter
.
>::type | ||
transfer_(ExPolicy&& policy, InIter first, InIter last, OutIter dest, | ||
transfer_(ExPolicy&& policy, FwdIter first, FwdIter last, OutIter dest, |
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.
Is it okay to use OutIter
as naming in here?
This review is applied in other places in this file.
/// if the execution policy is of type | ||
/// \a sequenced_task_policy or | ||
/// \a parallel_task_policy and | ||
/// returns \a tagged_pair<tag::in(BidirIter), tag::out(OutIter)> | ||
/// returns \a tagged_pair<tag::in(BidirIter), tag::out(FwdIter)> | ||
/// otherwise. | ||
/// The \a copy algorithm returns the pair of the input iterator |
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.
Tiny typo
\a copy -> \a reverse_copy
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.
But it is so tiny. So, I'll approve this PR.
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.
Thank you for your efforts to fix the issue which I suggested.
This makes the iterator requirements of the parallel algorithms conforming to C++17. It mainly strengthens those requirements by not allowing pure input or output iterators.
This fixes #2699.
This also applies some flyby changes:
hpx::util::invoke
to call predicates