Skip to content
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

Merged
merged 22 commits into from
Jul 11, 2017
Merged

Conversation

hkaiser
Copy link
Member

@hkaiser hkaiser commented Jul 1, 2017

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:

  • consistently using hpx::util::invoke to call predicates
  • all lambda function now have explicit return types specified

@hkaiser hkaiser added this to the 1.1.0 milestone Jul 1, 2017
@hkaiser hkaiser changed the title Adapting iterator rquirements for parallel algorithms Adapting iterator requirements for parallel algorithms Jul 1, 2017
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)"
Copy link
Member

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

Copy link
Member Author

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.

Copy link
Member

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?

Copy link
Member

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.

Copy link
Member Author

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.

>::type
copy(ExPolicy && policy, InIter first, InIter last, OutIter dest)
copy(ExPolicy && policy, FwdIter first, FwdIter last, OutIter dest)
Copy link
Member

@taeguk taeguk Jul 4, 2017

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.

Copy link
Member Author

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'.

Copy link
Member

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'.

Copy link
Member Author

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...

Copy link
Member

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.

Copy link
Member

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)

/// \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.
Copy link
Member

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.

Copy link
Member Author

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_HOST_DEVICE
static hpx::util::unused_type
sequential(ExPolicy, InIter first, InIter last,
sequential(ExPolicy, FwdIter first, FwdIter last,
Copy link
Member

@taeguk taeguk Jul 4, 2017

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.

Copy link
Member Author

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.

Copy link
Member

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 taeguk mentioned this pull request Jul 8, 2017
10 tasks
@hkaiser
Copy link
Member Author

hkaiser commented Jul 8, 2017

@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,
Copy link
Member

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.

Copy link
Member

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.

Copy link
Member Author

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)
Copy link
Member

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.

Copy link
Member Author

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,
Copy link
Member

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)
Copy link
Member

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,
Copy link
Member

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
Copy link
Member

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
Copy link
Member

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
Copy link
Member

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)
Copy link
Member

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,
Copy link
Member

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
Copy link
Member

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

Copy link
Member

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.

Copy link
Member

@taeguk taeguk left a 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.

@hkaiser hkaiser merged commit c3d8bdf into master Jul 11, 2017
@hkaiser hkaiser deleted the fixing_2699 branch July 11, 2017 18:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Iterator requirements are different from standard in parallel copy_if.
3 participants