Using device variable by multiple threads on CUDA
        Posted  
        
            by ashagi
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by ashagi
        
        
        
        Published on 2010-03-16T04:43:22Z
        Indexed on 
            2010/03/16
            7:56 UTC
        
        
        Read the original article
        Hit count: 378
        
I am playing around with cuda.
At the moment I have a problem. I am testing a large array for particular responses, and when I get the response, I have to copy the data onto another array.
For example, my test array of 5 elements looks like this: 
[ ][ ][v1][ ][ ][v2]
Result must look like this: 
[v1][v2]
The problem is how do I calculate the address of the second array to store the result? All elements of the first array are checked in parallel.
I am thinking to declare a device variable int addr = 0. Every time I find a response, I will increment the addr. But I am not sure about that because it means that addr may be accessed by multiple threads at the same time. Will that cause problems? Or will the thread wait until another thread finishes using that variable?
© Stack Overflow or respective owner