Summing elements with even or odd indices using CUDA Thrust

If i use

 float sum = thrust::transform_reduce(d_a.begin(), d_a.end(), conditional_operator(), 0.f, thrust::plus<float>());

I get the sum of all elements satisfying the condition conditional_operator(), as in Conditional abbreviation in CUDA .

But I can only summarize the elements d_a[0], d_a[2], d_a[4], d_a[6], .....?

I was thinking about changing the conditional operator, but it works on the elements in the array without reference to the index.

What can I do for this?

+4
source share
1 answer

There are two approaches that I can come up with to solve these kinds of problems:

, , , .

+5

Source: https://habr.com/ru/post/1538669/


All Articles