Pair distribution function

Hello to all,

I am new to CUDA and I have a lot of doubts. :rolleyes:

I am working on atomistic simulation, moving to CUDA hoping that this would be better performances.

Now I am trying to write a simple program that basically should calculate pair distribution function, that is calculate the distance from each atom in space (described by three floating points: (x,y,z)) from every other one.
In C is something like this:
[i]
for(k = 0; k < (numberOfAtoms-1); k++){

		for(l = k + 1; l < numberOfAtoms; l ++) {

			results[k][l] = sqrt((x[k] - x[l]) * (x[k] - x[l]) + (y[k] - y[l]) * (y[k] - y[l]) + (z[k] - z[l]) * (z[k] - z[l]));

		}

	}[/i]

But I can figure how to this in a clever manner with CUDA… <img src=‘http://hqnveipbwb20/public/style_emoticons/<#EMO_DIR#>/crying.gif’ class=‘bbc_emoticon’ alt=’:’(’ />

Till now I have written a simple program that stores 3 arrays (x, y, z) in global memory and basically copied the C code into the kernel… It works… :haha:
It could be a good solution?
But here first question… What about number of threads??

Anyway, I don’t think this is the best solution… Maybe could be better to take one atom per time, store it in shared memory and calculate distances from every other one. This could be better also because pair distribution function (pdf) vector is very big, for nAtoms around few thousand I full card memory (GTX 295); in this way maybe I could cut pdf and calculate it in some steps. But no idea about how pratically doing this… :(

It would be great to me to receive any suggest! :yes:

Thank you to all,
have a good morning/day/evening/night!

Bye!

Have you looked at the n-body sample in the SDK? It solves almost exactly this problem using shared memory.

Thank you Simon!

No, I have not read it yet, now I am going to have a look!

Very kind, thank you!