Can I still rely on the order of the output elements when using par_unseq?
Clash Royale CLAN TAG#URR8PPP
up vote
14
down vote
favorite
After reading the documentation I'm still confused about the usage of par_unseq
. I know I can't tell anything about the order of execution because of threading and vectorization but can I still rely on the order of the outputs?
transform([x0, x1, x2], f) == [f(x0), f(x1), f(x2)]]
In order words, is this test ever going to fail?
std::vector<int> xs = 1, 2, 3, 4;
std::vector<int> ys(xs.size());
std::transform(
std::execution::par_unseq,
cbegin(xs), cend(xs),
begin(ys),
(int x) return x*x; );
std::vector<int> expected = 1, 4, 9, 16;
ASSERT_EQ(expected , ys);
c++ algorithm parallel-processing c++17
add a comment |Â
up vote
14
down vote
favorite
After reading the documentation I'm still confused about the usage of par_unseq
. I know I can't tell anything about the order of execution because of threading and vectorization but can I still rely on the order of the outputs?
transform([x0, x1, x2], f) == [f(x0), f(x1), f(x2)]]
In order words, is this test ever going to fail?
std::vector<int> xs = 1, 2, 3, 4;
std::vector<int> ys(xs.size());
std::transform(
std::execution::par_unseq,
cbegin(xs), cend(xs),
begin(ys),
(int x) return x*x; );
std::vector<int> expected = 1, 4, 9, 16;
ASSERT_EQ(expected , ys);
c++ algorithm parallel-processing c++17
As I understand it, the order of the outputs ofstd::transform
is part of its specification, and it should not change no matter the execution policy that is chosen.
– jdehesa
Sep 7 at 9:53
add a comment |Â
up vote
14
down vote
favorite
up vote
14
down vote
favorite
After reading the documentation I'm still confused about the usage of par_unseq
. I know I can't tell anything about the order of execution because of threading and vectorization but can I still rely on the order of the outputs?
transform([x0, x1, x2], f) == [f(x0), f(x1), f(x2)]]
In order words, is this test ever going to fail?
std::vector<int> xs = 1, 2, 3, 4;
std::vector<int> ys(xs.size());
std::transform(
std::execution::par_unseq,
cbegin(xs), cend(xs),
begin(ys),
(int x) return x*x; );
std::vector<int> expected = 1, 4, 9, 16;
ASSERT_EQ(expected , ys);
c++ algorithm parallel-processing c++17
After reading the documentation I'm still confused about the usage of par_unseq
. I know I can't tell anything about the order of execution because of threading and vectorization but can I still rely on the order of the outputs?
transform([x0, x1, x2], f) == [f(x0), f(x1), f(x2)]]
In order words, is this test ever going to fail?
std::vector<int> xs = 1, 2, 3, 4;
std::vector<int> ys(xs.size());
std::transform(
std::execution::par_unseq,
cbegin(xs), cend(xs),
begin(ys),
(int x) return x*x; );
std::vector<int> expected = 1, 4, 9, 16;
ASSERT_EQ(expected , ys);
c++ algorithm parallel-processing c++17
edited Sep 7 at 12:36


BartoszKP
26.1k106299
26.1k106299
asked Sep 7 at 9:43
TimW
7,25612229
7,25612229
As I understand it, the order of the outputs ofstd::transform
is part of its specification, and it should not change no matter the execution policy that is chosen.
– jdehesa
Sep 7 at 9:53
add a comment |Â
As I understand it, the order of the outputs ofstd::transform
is part of its specification, and it should not change no matter the execution policy that is chosen.
– jdehesa
Sep 7 at 9:53
As I understand it, the order of the outputs of
std::transform
is part of its specification, and it should not change no matter the execution policy that is chosen.– jdehesa
Sep 7 at 9:53
As I understand it, the order of the outputs of
std::transform
is part of its specification, and it should not change no matter the execution policy that is chosen.– jdehesa
Sep 7 at 9:53
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
11
down vote
accepted
The Standard, [alg.transform], reads:
Effects: Assigns through every iterator
i
in the range[result,result + (last1 - first1))
a new corresponding value equal toop(*(first1 + (i - result))
orbinary_op(*(first1 + (i - result)), *(first2 + (i - result)))
.
and (thanks, @Caleth), [algorithms.parallel.overloads]:
Unless otherwise specified, the semantics of
ExecutionPolicy
algorithm overloads are identical to their overloads without.
So, yes, you can rely on the order in the output.
2
You also have "Unless otherwise specified, the semantics of ExecutionPolicy algorithm overloads are identical to their overloads without" in [algorithms.parallel.overloads]
– Caleth
Sep 7 at 9:55
@Caleth, thanks, added to the answer.
– Evg
Sep 7 at 9:59
Thanks, en.cppreference.com/w/cpp/algorithm/transform doesn't mention this behavior but is seems that the standard is very clear on this
– TimW
Sep 7 at 10:03
add a comment |Â
up vote
2
down vote
No, your test is never going to fail because even if order of execution changes, ys[0...3] = xs[0...3] * xs[0...3] = 1*1, 2*2, 3*3, 4*4;
won't change.
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
11
down vote
accepted
The Standard, [alg.transform], reads:
Effects: Assigns through every iterator
i
in the range[result,result + (last1 - first1))
a new corresponding value equal toop(*(first1 + (i - result))
orbinary_op(*(first1 + (i - result)), *(first2 + (i - result)))
.
and (thanks, @Caleth), [algorithms.parallel.overloads]:
Unless otherwise specified, the semantics of
ExecutionPolicy
algorithm overloads are identical to their overloads without.
So, yes, you can rely on the order in the output.
2
You also have "Unless otherwise specified, the semantics of ExecutionPolicy algorithm overloads are identical to their overloads without" in [algorithms.parallel.overloads]
– Caleth
Sep 7 at 9:55
@Caleth, thanks, added to the answer.
– Evg
Sep 7 at 9:59
Thanks, en.cppreference.com/w/cpp/algorithm/transform doesn't mention this behavior but is seems that the standard is very clear on this
– TimW
Sep 7 at 10:03
add a comment |Â
up vote
11
down vote
accepted
The Standard, [alg.transform], reads:
Effects: Assigns through every iterator
i
in the range[result,result + (last1 - first1))
a new corresponding value equal toop(*(first1 + (i - result))
orbinary_op(*(first1 + (i - result)), *(first2 + (i - result)))
.
and (thanks, @Caleth), [algorithms.parallel.overloads]:
Unless otherwise specified, the semantics of
ExecutionPolicy
algorithm overloads are identical to their overloads without.
So, yes, you can rely on the order in the output.
2
You also have "Unless otherwise specified, the semantics of ExecutionPolicy algorithm overloads are identical to their overloads without" in [algorithms.parallel.overloads]
– Caleth
Sep 7 at 9:55
@Caleth, thanks, added to the answer.
– Evg
Sep 7 at 9:59
Thanks, en.cppreference.com/w/cpp/algorithm/transform doesn't mention this behavior but is seems that the standard is very clear on this
– TimW
Sep 7 at 10:03
add a comment |Â
up vote
11
down vote
accepted
up vote
11
down vote
accepted
The Standard, [alg.transform], reads:
Effects: Assigns through every iterator
i
in the range[result,result + (last1 - first1))
a new corresponding value equal toop(*(first1 + (i - result))
orbinary_op(*(first1 + (i - result)), *(first2 + (i - result)))
.
and (thanks, @Caleth), [algorithms.parallel.overloads]:
Unless otherwise specified, the semantics of
ExecutionPolicy
algorithm overloads are identical to their overloads without.
So, yes, you can rely on the order in the output.
The Standard, [alg.transform], reads:
Effects: Assigns through every iterator
i
in the range[result,result + (last1 - first1))
a new corresponding value equal toop(*(first1 + (i - result))
orbinary_op(*(first1 + (i - result)), *(first2 + (i - result)))
.
and (thanks, @Caleth), [algorithms.parallel.overloads]:
Unless otherwise specified, the semantics of
ExecutionPolicy
algorithm overloads are identical to their overloads without.
So, yes, you can rely on the order in the output.
edited Sep 7 at 10:01
answered Sep 7 at 9:53
Evg
2,2501130
2,2501130
2
You also have "Unless otherwise specified, the semantics of ExecutionPolicy algorithm overloads are identical to their overloads without" in [algorithms.parallel.overloads]
– Caleth
Sep 7 at 9:55
@Caleth, thanks, added to the answer.
– Evg
Sep 7 at 9:59
Thanks, en.cppreference.com/w/cpp/algorithm/transform doesn't mention this behavior but is seems that the standard is very clear on this
– TimW
Sep 7 at 10:03
add a comment |Â
2
You also have "Unless otherwise specified, the semantics of ExecutionPolicy algorithm overloads are identical to their overloads without" in [algorithms.parallel.overloads]
– Caleth
Sep 7 at 9:55
@Caleth, thanks, added to the answer.
– Evg
Sep 7 at 9:59
Thanks, en.cppreference.com/w/cpp/algorithm/transform doesn't mention this behavior but is seems that the standard is very clear on this
– TimW
Sep 7 at 10:03
2
2
You also have "Unless otherwise specified, the semantics of ExecutionPolicy algorithm overloads are identical to their overloads without" in [algorithms.parallel.overloads]
– Caleth
Sep 7 at 9:55
You also have "Unless otherwise specified, the semantics of ExecutionPolicy algorithm overloads are identical to their overloads without" in [algorithms.parallel.overloads]
– Caleth
Sep 7 at 9:55
@Caleth, thanks, added to the answer.
– Evg
Sep 7 at 9:59
@Caleth, thanks, added to the answer.
– Evg
Sep 7 at 9:59
Thanks, en.cppreference.com/w/cpp/algorithm/transform doesn't mention this behavior but is seems that the standard is very clear on this
– TimW
Sep 7 at 10:03
Thanks, en.cppreference.com/w/cpp/algorithm/transform doesn't mention this behavior but is seems that the standard is very clear on this
– TimW
Sep 7 at 10:03
add a comment |Â
up vote
2
down vote
No, your test is never going to fail because even if order of execution changes, ys[0...3] = xs[0...3] * xs[0...3] = 1*1, 2*2, 3*3, 4*4;
won't change.
add a comment |Â
up vote
2
down vote
No, your test is never going to fail because even if order of execution changes, ys[0...3] = xs[0...3] * xs[0...3] = 1*1, 2*2, 3*3, 4*4;
won't change.
add a comment |Â
up vote
2
down vote
up vote
2
down vote
No, your test is never going to fail because even if order of execution changes, ys[0...3] = xs[0...3] * xs[0...3] = 1*1, 2*2, 3*3, 4*4;
won't change.
No, your test is never going to fail because even if order of execution changes, ys[0...3] = xs[0...3] * xs[0...3] = 1*1, 2*2, 3*3, 4*4;
won't change.
answered Sep 7 at 9:52


Swordfish
1,566415
1,566415
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f52219796%2fcan-i-still-rely-on-the-order-of-the-output-elements-when-using-par-unseq%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
As I understand it, the order of the outputs of
std::transform
is part of its specification, and it should not change no matter the execution policy that is chosen.– jdehesa
Sep 7 at 9:53