C++ Logo


Advanced search

Re: std::ranges APIs with Execution Policy

From: Giannis Gonidelis <gonidelis_at_[hidden]>
Date: Wed, 8 Dec 2021 00:39:48 +0000
Dear all,

That is exactly my point. Anything less than RandomAccessIterator​ is insufficient for parallelism.


Giannis Gonidelis
Research Assistant
STE||AR Group - CCT
Louisiana State University

From: Std-Proposals <std-proposals-bounces_at_[hidden]> on behalf of Jason McKesson via Std-Proposals <std-proposals_at_[hidden]>
Sent: Wednesday, December 8, 2021 2:11 AM
To: std-proposals_at_[hidden] <std-proposals_at_[hidden]>
Cc: Jason McKesson <jmckesson_at_[hidden]>
Subject: Re: [std-proposals] std::ranges APIs with Execution Policy

On Tue, Dec 7, 2021 at 6:59 PM JIMMY HU via Std-Proposals
<std-proposals_at_[hidden]> wrote:
> Hi Giannis,
> Thank you for your reply and providing the great references.
> I've checked the hpx library, the similar declaration is already in line 175~179 in hpx/libs/core/algorithms/include/hpx/parallel/container_algorithms/for_each.hpp.
> Reply to your question:
> > 1. You propose std::input_iterator and ranges::input_range as the prospective API. What would the benefit be on parallelizing the ranges algorithms if the supported iterator was just an InputIt? AFAIAC you cannot impose parallelization without a RandomAccessIterator.
> The usages of std::input_iterator and ranges::input_range is referenced from the existing std::ranges::for_each call signature (https://en.cppreference.com/w/cpp/algorithm/ranges/for_each), I want to keep the constraints of the remain parameters constantly.

OK, but... how?

The parallel algorithms didn't change their iterator requirements on a
whim. They changed them to make parallelism possible. Forward
iterators are iterators across a sequence of values that continue to
exist after the iterator has moved on. Input iterators *are not*.
They're specifically allowed to destroy any referenced element after
the iterator is incremented. Copying an input iterator does not create
two distinct iterators that can be incremented and worked with
independently. And so forth.

So how can you have a parallel version of `for_each` operate on pure
input iterators? How can different threads access different elements
in the sequence, when the iterator is permitted to destroy and reclaim
those elements once it is incremented?
Std-Proposals mailing list

Received on 2021-12-07 18:40:51