Can I still rely on the order of the output elements when using par_unseq?

The name of the pictureThe name of the pictureThe name of the pictureClash 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);






share|improve this question






















  • 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














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);






share|improve this question






















  • 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












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);






share|improve this question














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);








share|improve this question













share|improve this question




share|improve this question








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 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















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












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 to op(*(first1 + (i - result)) or binary_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.






share|improve this answer


















  • 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


















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.






share|improve this answer




















    Your Answer





    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: false,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













     

    draft saved


    draft discarded


















    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






























    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 to op(*(first1 + (i - result)) or binary_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.






    share|improve this answer


















    • 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















    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 to op(*(first1 + (i - result)) or binary_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.






    share|improve this answer


















    • 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













    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 to op(*(first1 + (i - result)) or binary_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.






    share|improve this answer














    The Standard, [alg.transform], reads:




    Effects: Assigns through every iterator i in the range [result,result + (last1 - first1)) a new corresponding value equal to op(*(first1 + (i - result)) or binary_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.







    share|improve this answer














    share|improve this answer



    share|improve this answer








    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













    • 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













    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.






    share|improve this answer
























      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.






      share|improve this answer






















        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.






        share|improve this answer












        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.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Sep 7 at 9:52









        Swordfish

        1,566415




        1,566415



























             

            draft saved


            draft discarded















































             


            draft saved


            draft discarded














            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













































































            Comments

            Popular posts from this blog

            What does second last employer means? [closed]

            List of Gilmore Girls characters

            Confectionery