Skip to content

Commit

Permalink
Multiple fixes for constraints (#465)
Browse files Browse the repository at this point in the history
* Fix a typo in chmap, temporary rename concept range

* Rename range concept, add workaround for Windows

* Reimplement with respect to prospective destructors

* Fix fibonacci
  • Loading branch information
kboyarinov committed Jun 30, 2021
1 parent a3635ce commit 4a23d00
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 61 deletions.
4 changes: 2 additions & 2 deletions examples/test_all/fibonacci/fibonacci.cpp
Expand Up @@ -211,8 +211,8 @@ struct IntHashCompare {
bool equal(const int j, const int k) const {
return j == k;
}
unsigned long hash(const int k) const {
return (unsigned long)k;
std::size_t hash(const int k) const {
return (std::size_t)k;
}
};
//! NumbersTable type based on concurrent_hash_map
Expand Down
2 changes: 1 addition & 1 deletion include/oneapi/tbb/concurrent_hash_map.h
Expand Up @@ -455,7 +455,7 @@ class hash_map_iterator {
, typename M
>
__TBB_requires(tbb::detail::hash_compare<HashCompare, Key> &&
ch_map_rw_scoped_lockable<MutexType>)
ch_map_rw_scoped_lockable<M>)
#else
>
__TBB_requires(tbb::detail::hash_compare<HashCompare, Key>)
Expand Down
12 changes: 6 additions & 6 deletions include/oneapi/tbb/detail/_range_common.h
Expand Up @@ -95,12 +95,12 @@ template <typename T>
concept splittable = std::constructible_from<T, T&, tbb::detail::split>;

template <typename Range>
concept range = std::copy_constructible<Range> &&
splittable<Range> &&
requires( const std::remove_reference_t<Range>& range ) {
{ range.empty() } -> relaxed_convertible_to<bool>;
{ range.is_divisible() } -> relaxed_convertible_to<bool>;
};
concept tbb_range = std::copy_constructible<Range> &&
splittable<Range> &&
requires( const std::remove_reference_t<Range>& range ) {
{ range.empty() } -> relaxed_convertible_to<bool>;
{ range.is_divisible() } -> relaxed_convertible_to<bool>;
};

template <typename Iterator>
constexpr bool iterator_concept_helper( std::input_iterator_tag ) {
Expand Down
22 changes: 11 additions & 11 deletions include/oneapi/tbb/parallel_for.h
Expand Up @@ -226,79 +226,79 @@ class parallel_for_body_wrapper : detail::no_assign {
//! Parallel iteration over range with default partitioner.
/** @ingroup algorithms **/
template<typename Range, typename Body>
__TBB_requires(range<Range> && parallel_for_body<Body, Range>)
__TBB_requires(tbb_range<Range> && parallel_for_body<Body, Range>)
void parallel_for( const Range& range, const Body& body ) {
start_for<Range,Body,const __TBB_DEFAULT_PARTITIONER>::run(range,body,__TBB_DEFAULT_PARTITIONER());
}

//! Parallel iteration over range with simple partitioner.
/** @ingroup algorithms **/
template<typename Range, typename Body>
__TBB_requires(range<Range> && parallel_for_body<Body, Range>)
__TBB_requires(tbb_range<Range> && parallel_for_body<Body, Range>)
void parallel_for( const Range& range, const Body& body, const simple_partitioner& partitioner ) {
start_for<Range,Body,const simple_partitioner>::run(range,body,partitioner);
}

//! Parallel iteration over range with auto_partitioner.
/** @ingroup algorithms **/
template<typename Range, typename Body>
__TBB_requires(range<Range> && parallel_for_body<Body, Range>)
__TBB_requires(tbb_range<Range> && parallel_for_body<Body, Range>)
void parallel_for( const Range& range, const Body& body, const auto_partitioner& partitioner ) {
start_for<Range,Body,const auto_partitioner>::run(range,body,partitioner);
}

//! Parallel iteration over range with static_partitioner.
/** @ingroup algorithms **/
template<typename Range, typename Body>
__TBB_requires(range<Range> && parallel_for_body<Body, Range>)
__TBB_requires(tbb_range<Range> && parallel_for_body<Body, Range>)
void parallel_for( const Range& range, const Body& body, const static_partitioner& partitioner ) {
start_for<Range,Body,const static_partitioner>::run(range,body,partitioner);
}

//! Parallel iteration over range with affinity_partitioner.
/** @ingroup algorithms **/
template<typename Range, typename Body>
__TBB_requires(range<Range> && parallel_for_body<Body, Range>)
__TBB_requires(tbb_range<Range> && parallel_for_body<Body, Range>)
void parallel_for( const Range& range, const Body& body, affinity_partitioner& partitioner ) {
start_for<Range,Body,affinity_partitioner>::run(range,body,partitioner);
}

//! Parallel iteration over range with default partitioner and user-supplied context.
/** @ingroup algorithms **/
template<typename Range, typename Body>
__TBB_requires(range<Range> && parallel_for_body<Body, Range>)
__TBB_requires(tbb_range<Range> && parallel_for_body<Body, Range>)
void parallel_for( const Range& range, const Body& body, task_group_context& context ) {
start_for<Range,Body,const __TBB_DEFAULT_PARTITIONER>::run(range, body, __TBB_DEFAULT_PARTITIONER(), context);
}

//! Parallel iteration over range with simple partitioner and user-supplied context.
/** @ingroup algorithms **/
template<typename Range, typename Body>
__TBB_requires(range<Range> && parallel_for_body<Body, Range>)
__TBB_requires(tbb_range<Range> && parallel_for_body<Body, Range>)
void parallel_for( const Range& range, const Body& body, const simple_partitioner& partitioner, task_group_context& context ) {
start_for<Range,Body,const simple_partitioner>::run(range, body, partitioner, context);
}

//! Parallel iteration over range with auto_partitioner and user-supplied context.
/** @ingroup algorithms **/
template<typename Range, typename Body>
__TBB_requires(range<Range> && parallel_for_body<Body, Range>)
__TBB_requires(tbb_range<Range> && parallel_for_body<Body, Range>)
void parallel_for( const Range& range, const Body& body, const auto_partitioner& partitioner, task_group_context& context ) {
start_for<Range,Body,const auto_partitioner>::run(range, body, partitioner, context);
}

//! Parallel iteration over range with static_partitioner and user-supplied context.
/** @ingroup algorithms **/
template<typename Range, typename Body>
__TBB_requires(range<Range> && parallel_for_body<Body, Range>)
__TBB_requires(tbb_range<Range> && parallel_for_body<Body, Range>)
void parallel_for( const Range& range, const Body& body, const static_partitioner& partitioner, task_group_context& context ) {
start_for<Range,Body,const static_partitioner>::run(range, body, partitioner, context);
}

//! Parallel iteration over range with affinity_partitioner and user-supplied context.
/** @ingroup algorithms **/
template<typename Range, typename Body>
__TBB_requires(range<Range> && parallel_for_body<Body, Range>)
__TBB_requires(tbb_range<Range> && parallel_for_body<Body, Range>)
void parallel_for( const Range& range, const Body& body, affinity_partitioner& partitioner, task_group_context& context ) {
start_for<Range,Body,affinity_partitioner>::run(range,body,partitioner, context);
}
Expand All @@ -308,7 +308,7 @@ template <typename Index, typename Function, typename Partitioner>
void parallel_for_impl(Index first, Index last, Index step, const Function& f, Partitioner& partitioner) {
if (step <= 0 )
throw_exception(exception_id::nonpositive_step); // throws std::invalid_argument
else if (last > first) {
else if (first < last) {
// Above "else" avoids "potential divide by zero" warning on some platforms
Index end = (last - first - Index(1)) / step + Index(1);
blocked_range<Index> range(static_cast<Index>(0), end);
Expand Down

0 comments on commit 4a23d00

Please sign in to comment.