Writing to several global memory locations from the same kernel

If I have a kernel where each thread writes to a number of different locations in global memory, and some threads will write to the same location as others, what happens? Do the writes get serialised?

Basically, what I want to do is this

//index of this thread

int thrIndex = ...calculate index

for (int i=0; i<limit; ++i)


    int otherindex = ... calculate index    

   float4 force = //... calculate value of force;


    globalArray[thrIndex] += force;

    globalArray[otherIndex] -= force;


where “otherindex” could be the “thrIndex” of another thread.

Is this possible? Or am I going about this the wrong way? Any suggestions appreciated.



The programming guide says your only guarantee is that “one write will succeed.”

Which thread “wins” is NOT defined, nor is the expectation that you might be able to read transient values or anything.

Also, because your writes are “random” you’re going to have slow memory access, since the writes by parallel threads will have to be serialized since they can’t be coalesced.