Couldn't the ID of thread be assigned to other variable?

I write the code like this

void initBlob(const unsigned char *in, unsigned char *out, size_t *indexTab, int total2D)
	size_t i = blockIdx.x * blockDim.x + threadIdx.x;

	if(i < total2D)
		out[i] = in[i];
		if(255 == in[i])
			indexTab[i] = i;
			printf("index[%d] = %d ",i, indexTab[i]);

but the value of indexTab[i] always be an zero. what’ wrong here, please help me.

Is it possible that 255 == in[i] only when i == 0? Could you post more code, or the output of your program?

A size_t is a 64-bit quantity on a 64-bit platform.

But the %d printf format specifier indicates printing of a 32-bit quantity.

Make indexTab an int quantity instead of a size_t quantity, or else change the printf format specifier to %lu

and don’t forget to change “size_t i” definition too