Parallel C++ algorithms run sequentially
Bug #2030797 reported by
Gonzalo
This bug affects 1 person
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
gcc |
In Progress
|
Medium
|
|||
gcc-13 (Ubuntu) |
New
|
Undecided
|
Unassigned |
Bug Description
Parallel C++ algorithms run sequentially when C++20 iterators are used with libstdc++, causing significant performance degradation on multicore systems (10-100x) when run on Ubuntu Linux.
Patch to GCC available here: https:/
Changed in gcc: | |
importance: | Unknown → Medium |
status: | Unknown → Confirmed |
Changed in gcc: | |
status: | Confirmed → In Progress |
To post a comment you must log in.
See https:/ /github. com/llvm/ llvm-project/ issues/ 63447
The problem is the following:
std::vector<int> x(n), y(n); :iota(( int)0, (int)x.size()); each(std: :execution: :par_unseq, ids.begin(), ids.end(), [x = x.data(), y = y.data()](int i) {
auto ids = std::views:
std::for_
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> access_ iterator< _IteratorType> {
(bool) std::is_ same_v< typename std::iterator_ traits< _IteratorType> ::iterator_ category, std::random_ access_ iterator_ tag> :std::random_ access_ iterator< _IteratorType> constant< bool, value> type;
struct __is_random_
static constexpr bool value = (
|| (bool):
);
typedef std::integral_
};
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.