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

Check the swappable requirement for the parallel_sort algorithm #656

Merged
merged 11 commits into from
Dec 6, 2021

Conversation

ivankochin
Copy link
Contributor

@ivankochin ivankochin commented Nov 15, 2021

Description

The oneTBB spec contains the swappable requirement for the iterators, but this requirement isn't handled by the C++ constraints in the implementation. This patch enables these constraints for all the overloads to improve the diagnostic and also extends the testing.

  • - git commit message contains appropriate signed-off-by string (see CONTRIBUTING.md for details)

Type of change

  • bug fix - change which fixes an issue
  • new feature - change which adds functionality
  • tests - change in tests
  • infrastructure - change in infrastructure and CI
  • documentation - documentation update

Tests

  • added - required for new features and for some bug fixes

Documentation

uxlfoundation/oneAPI-spec#391

Breaks backward compatibility

  • Yes

Notify the following users

@kboyarinov

Signed-off-by: Kochin Ivan kochin.ivan@intel.com

Kochin Ivan added 5 commits November 15, 2021 15:08
… test with custom swap

Signed-off-by: Kochin Ivan <kochin.ivan@intel.com>
Signed-off-by: Kochin Ivan <kochin.ivan@intel.com>
…ng tests

Signed-off-by: Kochin Ivan <kochin.ivan@intel.com>
Signed-off-by: Kochin Ivan <kochin.ivan@intel.com>
Signed-off-by: Kochin Ivan <kochin.ivan@intel.com>
Kochin Ivan added 3 commits November 16, 2021 09:48
Signed-off-by: Kochin Ivan <kochin.ivan@intel.com>
Signed-off-by: Kochin Ivan <kochin.ivan@intel.com>
Signed-off-by: Kochin Ivan <kochin.ivan@intel.com>
@ivankochin ivankochin force-pushed the dev/ivankochin/parallel-sort-check-swappable-req branch from 50c4fdd to 594a6ad Compare November 16, 2021 18:18
include/oneapi/tbb/parallel_sort.h Outdated Show resolved Hide resolved
void parallel_sort( RandomAccessIterator begin, RandomAccessIterator end ) {
parallel_sort(begin, end, std::less<typename std::iterator_traits<RandomAccessIterator>::value_type>());
}

template<typename Range>
using range_value_type = typename std::iterator_traits<range_iterator_type<Range>>::value_type;
Copy link
Contributor

Choose a reason for hiding this comment

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

May be we can move this helper to _range_common.h and simplify tbb::parallel_for_each constraints? The same for iter_value_type

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think so, As I know the parallel_for_each algorithm checks the requirements on reference types instead of value types.

test/common/concepts_common.h Outdated Show resolved Hide resolved

template <bool EnableBegin, bool EnableEnd>
using NonSwappableValue = ParallelSortValue</*MovableV = */true, /*MoveAssignableV = */true, /*ComparableV = */true>;
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems like ParallelSortValue<true, true, true> is swappable...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I understand it and don't use this value in testing. So I just forgot to remove it from here. Thanks!

test/tbb/test_parallel_for_each.cpp Show resolved Hide resolved
test/tbb/test_parallel_sort.cpp Outdated Show resolved Hide resolved
test/tbb/test_parallel_sort.cpp Outdated Show resolved Hide resolved
Signed-off-by: Kochin Ivan <kochin.ivan@intel.com>
@ivankochin ivankochin requested a review from kboyarinov December 2, 2021 06:48
include/oneapi/tbb/parallel_sort.h Outdated Show resolved Hide resolved
@@ -240,7 +250,9 @@ void parallel_sort( RandomAccessIterator begin, RandomAccessIterator end, const
/** @ingroup algorithms **/
template<typename RandomAccessIterator>
__TBB_requires(std::random_access_iterator<RandomAccessIterator> &&
less_than_comparable<typename std::iterator_traits<RandomAccessIterator>::value_type>)
less_than_comparable<iter_value_type<RandomAccessIterator>> &&
std::swappable<iter_value_type<RandomAccessIterator>> &&
Copy link
Contributor

Choose a reason for hiding this comment

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

Seems unnecessary, same as above

include/oneapi/tbb/parallel_sort.h Outdated Show resolved Hide resolved
@@ -258,7 +272,9 @@ void parallel_sort( Range&& rng, const Compare& comp ) {
/** @ingroup algorithms **/
template<typename Range>
__TBB_requires(container_based_sequence<Range, std::random_access_iterator_tag> &&
less_than_comparable<typename std::iterator_traits<range_iterator_type<Range>>::value_type>)
less_than_comparable<range_value_type<Range>> &&
std::swappable<range_value_type<Range>> &&
Copy link
Contributor

Choose a reason for hiding this comment

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

Seems unnecessary, same as above

test/common/concepts_common.h Outdated Show resolved Hide resolved
test/common/concepts_common.h Outdated Show resolved Hide resolved
test/common/concepts_common.h Outdated Show resolved Hide resolved
test/common/concepts_common.h Show resolved Hide resolved
test/tbb/test_parallel_sort.cpp Outdated Show resolved Hide resolved
test/tbb/test_parallel_sort.cpp Outdated Show resolved Hide resolved
Signed-off-by: Kochin Ivan <kochin.ivan@intel.com>
@ivankochin ivankochin requested a review from kboyarinov December 6, 2021 10:43
Signed-off-by: Kochin Ivan <kochin.ivan@intel.com>
Copy link
Contributor

@kboyarinov kboyarinov left a comment

Choose a reason for hiding this comment

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

LGTM

@ivankochin ivankochin merged commit 4eec89f into master Dec 6, 2021
@ivankochin ivankochin deleted the dev/ivankochin/parallel-sort-check-swappable-req branch December 6, 2021 14:43
kboyarinov pushed a commit that referenced this pull request Dec 27, 2021
Signed-off-by: Kochin Ivan <kochin.ivan@intel.com>
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.

2 participants