Hacker News new | ask | show | jobs
by cwzwarich 27 days ago
`std::accumulate` is defined to have sequential semantics, so the analysis required to make it parallel is probably not that different than starting from the loop version. I guess you could have an alternate `accumulate_associative` that uses the same interface but assumes the reduction is associative and has unspecified evaluation order?
1 comments

C++ has std::reduce for that, which is std::accumulate except it's defined to operate without any specific ordering.
Thanks everyone, my C++ knowledge has been greatly expanded today.
And now you should probably also stop and consider whether adding elements one-by-one as opposed to recursively adding together sums of smaller subarrays has better or worse numerical behaviour in regards to e.g. rounding and stability.