Comments (6)
Should
generate
andgenerate_n
also be parallelized?
Your sample program is a great demonstration of why generate
and generate_n
can't be meaningfully parallelized: the function object is almost always stateful, and evaluations almost always order-dependent. I suspect the writer of this program would be very unhappy if the library spawned 16 threads with their own copies of the lambda resulting in all elements of v_c
being equal to v_a[0] + v_b[0]
.
from stl.
Should generate
and generate_n
also be parallelized?
Here's how I try to compensate lack of transform
with unseq
#include <vector>
#include <execution>
std::vector<int> v_a(16);
std::vector<int> v_b(16);
std::vector<int> v_c(16);
void sum(int* c, int* a, int* b)
{
std::generate_n(std::execution::unseq, c, 16, [=]() mutable {
return *(a++) + *(b++);
});
}
int main()
{
sum(v_c.data(), v_a.data(), v_b.data());
}
from stl.
Why does execution policy parameter even exist for them?
from stl.
Why does execution policy parameter even exist for them?
Because the 'design' process for the parallel algorithms was 'if nobody can come up with a reason why it can't be parallelized, without looking at real implementations, in 10 minutes, it gets a parallel one'. Note that partial_sort
has such an overload too even though it is a heap algorithm and none of the other heap algorithms got parallel overloads.
from stl.
I'm trying to make this work without #pragma
in my code:
#include <vector>
std::vector<int> v_a(16);
std::vector<int> v_b(16);
std::vector<int> v_c(16);
void sum(int c[], int a[], int b[])
{
#pragma loop(ivdep)
for (int i = 0; i < 16; i++)
{
c[i] = a[i] + b[i];
}
}
int main()
{
sum(v_c.data(), v_a.data(), v_b.data());
}
Note that without a pragma the compilers still emits SIMD version, but goes to it conditionally at runtime.
Now that this is useless:
void sum(int * c, int* a, int * b)
{
std::transform(std::execution::unseq, a, a + 16, b, c, std::plus{});
}
As well as this:
void sum(int* c, int* a, int* b)
{
std::for_each(std::execution::unseq, c, c + 16, [=](int& v) {
v = a[&v - c] + b[&v - c];
});
}
How else I can say it?
from stl.
I don't believe we have a way to say that without a pragma at this time. It's really on the optimizer team if they want to consume the unseq signal and they have declined to do so as of yet.
from stl.
Related Issues (20)
- <atomic> : A standard macro is not exported when using the std module HOT 3
- <yvals.h> : Can't be used alongside the std module HOT 1
- unresolved external symbol __isa_available HOT 2
- `to_string( stacktrace )` gets stuck if first called during DLL loading HOT 4
- `<algorithm>`: `minmax_element()` crashes for NaNs HOT 1
- `.gitignore`: Support more IDEs? HOT 2
- <random>: uniform_*_distribution Not Satisfy RandomNumberDistribution Named Requirements HOT 1
- compile STL error: Problem HOT 8
- Azure PowerShell: For `New-AzGalleryImageDefinition`, `'TrustedLaunch'` and `'TrustedLaunchSupported'` aren't synonyms
- ARM64 `__popcnt` intrinsics
- `<cassert>` has no include guard HOT 2
- `<algorithm>`: `reverse_copy` is mistakenly vectorized for `pair<int&, int&>` on 32-bit targets HOT 11
- `<atomic>`: `atomic_ref<void*>` and `atomic<void*>` lack `difference_type`
- Sporadic STL-ASan-CI failures mentioning `__asan_wrap_memmove`
- GitHub migration
- Maintainer priorities
- `<yvals_core.h>`: Update `_MSVC_STL_UPDATE` to June 2024
- Unskip sized deallocation tests with clang HOT 2
- Should `std::error_code::message` respect the locale set by the user? HOT 3
- Regarding `vector::emplace_back` and `vector::push_back` behaviour HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from stl.