What are practical uses for STL's 'partial_sum'?

前端 未结 11 1707
耶瑟儿~
耶瑟儿~ 2021-02-04 03:47

What/where are the practical uses of the partial_sum algorithm in STL?

What are some other interesting/non-trivial examples or use-cases?

11条回答
  •  醉话见心
    2021-02-04 04:44

    Partial sums are often useful in parallel algorithms. Consider the code

    for (int i=0; N>i; ++i) {
      sum += x[i];
      do_something(sum);
    }
    

    If you want to parallelise this code, you need to know the partial sums. I am using GNUs parallel version of partial_sum for something very similar.

提交回复
热议问题