Noob: particle system

Hi,

I’m noob with CUDA, but I try to create my own particle simulation, and I have problem with putting particles in right order. I want put particles in cube (they should look like cube of particles), usually i use this code (I have 8k particles, 3D):

int aa= 0;

	for(int xx = -10; xx <10; xx +=1 )

		for(int yy = -10; yy < 10; yy +=1)

			for(int zz = -10; zz < 10; zz +=1)

			{	

				particle[aa].r = Vector(xx, yy, zz);

				aa++;

			}

Now my .cu file:

__device__ float3 tab[8000];

__global__ void kernel(int n)

{

	int idx = blockIdx.x * blockDim.x + threadIdx.x;   //(0, 20)

	int aa = 0;

	if(idx < n)

	{

		for(int i = 0; i < 20; i++)

			for(int j = 0; j < 20; j++)

				tab[aa++].r = make_float3(idx, i, j);

	}

}

Can someone help me, or explain me what I’m doing wrong.

Sry for my English and thx for help.

You are only accessing the first 400 indices of your tab array. Changing tab[aa++] to tab[400*idx+aa++] should correct this.

Thx for your response, but still it doesn’t work. Now I can see 1 k particles:/

Any other sugestions?

Yes, instead of launching 20 threads, launch 8000 threads and let each one fill an index in the array. Like:

z = idx/400

y = (idx - z*400)/20

x = idx - z400 - y20

tab[idx] = make_float3(x,y,z)