0

I've already learnt about the Parallel Sum Reduction technique. However, I want to know if it is possible to add up different values from different Threads to a same __global variable like this :

float a = ...; // Assign different a values for each Thread

Gvar[1] += a; // Do the sum simultaneously to the same global variable index

Thanks

1 Answer 1

0

For updating the same global memory location from different work-groups you will need to use atomic functions.

You can do so from different work-items in the same group, but this is usually a bad idea. It is almost always more efficient to perform reduction in local memory within the group and only update a global memory location once in each work-group.

Note that most atomic functions are not available for floating-point data types, so you will need to either use integer types or an alternative method to solve your problem.

Sign up to request clarification or add additional context in comments.

1 Comment

That's all i needed to know. Thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.