atomicAdd() function problem

If I have 100 threads, after computing some of threads(maybe 3) get results which i need(maybe 0).
Could I use atomicAdd() to get the threads number which I need?

You should only use atomicAdd if you have multiple threads operating concurrently that are all adding to the same memory address.

I don’t understand the rest of your question about finding a thread’s number.

global void kernel( int* vec, int* count )
int j;
unsigned int tx = threadIdx.x;
if ( tx < NUM )
j = atomicAdd( count, 1 );
vec[j] = tx;
So all the threads index number could be found in the array(vec)?

There’s no need to have an array vec[] in your code, since all it does is store numbers 0, 1, 2, …

I suggest reading the part on atomicAdd from here:

For the first argument of atomicAdd you are giving it count when you should be giving it an address. Perhaps &vec[x] where x is the element of vec that you wish to change.