Skip to content

Commit a4f253f

Browse files
committed
Allow using counting_iterator with datapar policies
Signed-off-by: Hartmut Kaiser <hartmut.kaiser@gmail.com>
1 parent 9c8f564 commit a4f253f

20 files changed

Lines changed: 453 additions & 187 deletions

.github/workflows/linux_crosscompile_arm_eve_sve_release.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ jobs:
5050
cmake --build build --target core
5151
cmake --build build --target tests.unit.modules.algorithms.datapar_algorithms
5252
cmake --build build --target tests.regressions.modules.algorithms.for_each_datapar
53+
cmake --build build --target tests.regressions.modules.algorithms.counting_iterator_datapar
5354
- name: Test
5455
shell: bash
5556
run: |

.github/workflows/linux_crosscompile_arm_sve_release.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ jobs:
5050
cmake --build build --target core
5151
cmake --build build --target tests.unit.modules.algorithms.datapar_algorithms
5252
cmake --build build --target tests.regressions.modules.algorithms.for_each_datapar
53+
cmake --build build --target tests.regressions.modules.algorithms.counting_iterator_datapar
5354
- name: Test
5455
shell: bash
5556
run: |

libs/core/algorithms/include/hpx/parallel/algorithms/count.hpp

Lines changed: 19 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -272,9 +272,9 @@ namespace hpx::parallel {
272272
count_iteration& operator=(count_iteration&&) = default;
273273

274274
template <typename Iter>
275-
HPX_HOST_DEVICE HPX_FORCEINLINE constexpr
276-
typename std::iterator_traits<Iter>::difference_type
277-
operator()(Iter part_begin, std::size_t part_size)
275+
HPX_HOST_DEVICE HPX_FORCEINLINE constexpr std::iterator_traits<
276+
Iter>::difference_type
277+
operator()(Iter part_begin, std::size_t part_size)
278278
{
279279
typename std::iterator_traits<Iter>::difference_type ret = 0;
280280
util::loop_n<execution_policy_type>(part_begin, part_size,
@@ -283,8 +283,8 @@ namespace hpx::parallel {
283283
}
284284

285285
template <typename Iter>
286-
HPX_HOST_DEVICE HPX_FORCEINLINE constexpr void operator()(Iter curr,
287-
typename std::iterator_traits<Iter>::difference_type& ret)
286+
HPX_HOST_DEVICE HPX_FORCEINLINE constexpr void operator()(
287+
Iter curr, std::iterator_traits<Iter>::difference_type& ret)
288288
{
289289
ret += traits::count_bits(
290290
HPX_INVOKE(op_, HPX_INVOKE(proj_, *curr)));
@@ -295,7 +295,7 @@ namespace hpx::parallel {
295295
HPX_CXX_CORE_EXPORT template <typename Value>
296296
struct count : public algorithm<count<Value>, Value>
297297
{
298-
typedef Value difference_type;
298+
using difference_type = Value;
299299

300300
constexpr count() noexcept
301301
: algorithm<count, Value>("count")
@@ -430,20 +430,16 @@ namespace hpx {
430430
private:
431431
template <typename ExPolicy, typename FwdIter,
432432
typename T = typename std::iterator_traits<FwdIter>::value_type>
433-
// clang-format off
434-
requires (
435-
hpx::is_execution_policy_v<ExPolicy> &&
436-
hpx::traits::is_iterator_v<FwdIter>
437-
)
438-
// clang-format on
433+
requires(hpx::is_execution_policy_v<ExPolicy> &&
434+
hpx::traits::is_iterator_v<FwdIter>)
439435
friend decltype(auto) tag_fallback_invoke(count_t, ExPolicy&& policy,
440436
FwdIter first, FwdIter last, T const& value)
441437
{
442438
static_assert(std::forward_iterator<FwdIter>,
443439
"Required at least forward iterator.");
444440

445441
using difference_type =
446-
typename std::iterator_traits<FwdIter>::difference_type;
442+
std::iterator_traits<FwdIter>::difference_type;
447443

448444
return hpx::parallel::detail::count<difference_type>().call(
449445
HPX_FORWARD(ExPolicy, policy), first, last, value,
@@ -452,19 +448,15 @@ namespace hpx {
452448

453449
template <typename InIter,
454450
typename T = typename std::iterator_traits<InIter>::value_type>
455-
// clang-format off
456-
requires (
457-
hpx::traits::is_iterator_v<InIter>
458-
)
459-
// clang-format on
460-
friend typename std::iterator_traits<InIter>::difference_type
461-
tag_fallback_invoke(count_t, InIter first, InIter last, T const& value)
451+
requires(hpx::traits::is_iterator_v<InIter>)
452+
friend decltype(auto) tag_fallback_invoke(
453+
count_t, InIter first, InIter last, T const& value)
462454
{
463455
static_assert(std::input_iterator<InIter>,
464456
"Required at least input iterator.");
465457

466458
using difference_type =
467-
typename std::iterator_traits<InIter>::difference_type;
459+
std::iterator_traits<InIter>::difference_type;
468460

469461
return hpx::parallel::detail::count<difference_type>().call(
470462
hpx::execution::seq, first, last, value, hpx::identity_v);
@@ -494,30 +486,25 @@ namespace hpx {
494486
"Required at least forward iterator.");
495487

496488
using difference_type =
497-
typename std::iterator_traits<FwdIter>::difference_type;
489+
std::iterator_traits<FwdIter>::difference_type;
498490

499491
return hpx::parallel::detail::count_if<difference_type>().call(
500492
HPX_FORWARD(ExPolicy, policy), first, last, HPX_MOVE(f),
501493
hpx::identity_v);
502494
}
503495

504496
template <typename InIter, typename F>
505-
// clang-format off
506-
requires (
507-
hpx::traits::is_iterator_v<InIter> &&
497+
requires(hpx::traits::is_iterator_v<InIter> &&
508498
hpx::is_invocable_v<F,
509-
typename std::iterator_traits<InIter>::value_type
510-
>
511-
)
512-
// clang-format on
513-
friend typename std::iterator_traits<InIter>::difference_type
514-
tag_fallback_invoke(count_if_t, InIter first, InIter last, F f)
499+
typename std::iterator_traits<InIter>::value_type>)
500+
friend decltype(auto) tag_fallback_invoke(
501+
count_if_t, InIter first, InIter last, F f)
515502
{
516503
static_assert(std::input_iterator<InIter>,
517504
"Required at least input iterator.");
518505

519506
using difference_type =
520-
typename std::iterator_traits<InIter>::difference_type;
507+
std::iterator_traits<InIter>::difference_type;
521508

522509
return hpx::parallel::detail::count_if<difference_type>().call(
523510
hpx::execution::seq, first, last, HPX_MOVE(f), hpx::identity_v);

0 commit comments

Comments
 (0)