I’m observing a strange __syncthreads behavior. Please can anyone tell me what’s going on.
I thought the second __syncthreads in line 6 of thread0 should block until all other threads reach the last __syncthreads in line 15.
“__syncthreads() is allowed in conditional code but only if the conditional evaluates identically across the entire thread block, otherwise the code execution is likely to hang or produce unintended side effects.”
Therefore, if you execute your code with more than 32 threads, it will lock on the __syncthreads calls.
__syncthreads() is you garden variety thread barrier. Any thread reaching the barrier waits until all of the other threads in that block also reach it.
pay atention to the words “also reach it”.
You program :
printf("a\n");
if(threadIdx.x == 0)
{
__syncthreads(); // this command only impact on thread 0
__syncthreads(); //this command only impact on thread 0
}
else
{
__syncthreads(); // this command impact on thread 1,2,3
}
printf("b\n");
if(threadIdx.x != 0)
{
printf("c\n");
__syncthreads();// this command impact on thread 1,2,3
}