public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/110512] New: C++20 random access iterators run sequentially with PSTL
@ 2023-07-01 18:00 gonzalo.gadeschi at gmail dot com
  2023-07-01 20:08 ` [Bug libstdc++/110512] " redi at gcc dot gnu.org
                   ` (10 more replies)
  0 siblings, 11 replies; 12+ messages in thread
From: gonzalo.gadeschi at gmail dot com @ 2023-07-01 18:00 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110512

            Bug ID: 110512
           Summary: C++20 random access iterators run sequentially with
                    PSTL
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: gonzalo.gadeschi at gmail dot com
  Target Milestone: ---

See https://github.com/llvm/llvm-project/issues/63447

The problem is the following:

std::vector<int> x(n), y(n);
auto ids = std::views::iota((int)0, (int)x.size());
std::for_each(std::execution::par_unseq, ids.begin(), ids.end(), [x = x.data(),
y = y.data()](int i) {
    x[i] = y[i];
});

Iterators from C++20 ranges model the C++20 random_access_iterator concept, but
do not necessarily have a random access iterator tag. They are not recognized
by the PSTL as random access iterators (but forward iterators), causing the
parallel algorithms to fall back to sequential execution.

This is significantly impacting the performance a couple of large HPC
applications.

A quick and dirty workaround is to modify pstl/executors_impls.hpp by changing
the random_access_iterator<IteratorType> to:

template <typename _IteratorType>
struct __is_random_access_iterator<_IteratorType> {
    static constexpr bool value = (
        (bool)std::is_same_v<typename
std::iterator_traits<_IteratorType>::iterator_category,
std::random_access_iterator_tag>
        || (bool)::std::random_access_iterator<_IteratorType>
    );
    typedef std::integral_constant<bool, value> type;
};

Since llvm-project/pstl has been forked by libc++, it does no longer make sense
to try to patch pstl upstream to fix this issue.

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2024-05-07  7:41 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-01 18:00 [Bug libstdc++/110512] New: C++20 random access iterators run sequentially with PSTL gonzalo.gadeschi at gmail dot com
2023-07-01 20:08 ` [Bug libstdc++/110512] " redi at gcc dot gnu.org
2023-07-01 20:11 ` redi at gcc dot gnu.org
2023-07-02  9:30 ` gonzalo.gadeschi at gmail dot com
2023-07-02 10:24 ` redi at gcc dot gnu.org
2023-07-18 12:29 ` gonzalo.gadeschi at gmail dot com
2024-01-09 23:15 ` redi at gcc dot gnu.org
2024-01-09 23:38 ` redi at gcc dot gnu.org
2024-01-10 10:43 ` redi at gcc dot gnu.org
2024-01-10 11:06 ` redi at gcc dot gnu.org
2024-01-11 22:50 ` redi at gcc dot gnu.org
2024-05-07  7:41 ` rguenth at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).