shared memory

Hi… I have a question about a shared memory

I want to use shared memory like memory offset.

This is source code.

global static void test(short* a, short* b, short* c)
{
const int idx = threadIdx.x;
shared unsigned int ff;

{
	__syncthreads();

	c[ff] = a[idx] + b[idx];
	ff++;
}

}

I want ff to be 0, 1, 2, 3, …in each other thread.

But I can’t solve this problem.

IF execute it, the result does not correct. ff is 0, 1, 1, 1, …

How can I solve the problem… Please help me

Your ff variable is in shared memory, so all the threads in the block are reading and modifying it. You’re getting thread races since their contributions all interact and interfere.

It’s hard to say how to fix this, since it’s unclear what your goal is. Probably using something like c[idx]=a[idx]+b[idx] will work fine, but since you didn’t do that you probably hope to do something more complex.

I really can not understand your algorithm.
can you post your Pseudocode?
:)