What is the quickest way to judge an array contains a given value or not.I want to set a global flag, once a thread find the value, set the flag is true. But it is time-costuming for other threads to search for once the flag is true. How to skip searching actions from other threads once the flag is true?
Generally you can read in one element per thread, use the warp voting function to determine if any thread in the warp contains the value:
float val = d_ptr[ idx ] ;
int valueInThisWarp = __any( val == givenValue );
if( valueInThisWarp )
d_global_flag = 1;
Now to speed this up you may have few blocks searching through many elements ( many elements per thread), hence there will be fewer active threads after the value has been found.