Synchronize threads.

Hi forum

Can somebody help me with this 2 questions?

  1. Im running an app in the kerner. The grid only uses 1 thread by block, now I need synchronize all threads before perform a new operation. How can I do it?

  2. Later the all threads are synchronized I need increases a var (to simulate a clock cycle). How can I handle this var.

my general scheme is this

__global__ void kernel(......)
	tid = .....
	for (int i=0; i <100000; i++)
		if (tid % 2 == 0)
			//call function1
			//call function 2
		//here I need increases the var, but only when all threads are synchronized

thanks in advanced

You can’t syncronize threads of different blocks. The only way to do that is finishing this kernel and launching a new one.
Anyway, in your case, it seems quite hard to syncronize efficiently. Maybe you should think about how to resolve your problem in a parallel way.