Skip to content

Instantly share code, notes, and snippets.

@pcpratts
Created January 18, 2014 21:35
Show Gist options
  • Select an option

  • Save pcpratts/8496848 to your computer and use it in GitHub Desktop.

Select an option

Save pcpratts/8496848 to your computer and use it in GitHub Desktop.
CUDA __syncthreads not operating as hoped
#include <stdio.h>
__global__ void sync_test(void)
{
printf("a\n");
if(threadIdx.x == 0){
__syncthreads();
__syncthreads();
} else {
__syncthreads();
}
printf("b\n");
if(threadIdx.x != 0){
printf("c\n");
__syncthreads();
}
}
int main(void)
{
sync_test<<<1, 4>>>();
cudaDeviceSynchronize();
return 0;
}
/* prints:
a
a
a
a
b
b
b
b
c
c
c
*/
/* desired:
a
a
a
a
b
b
b
c
c
c
b
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment