I am interested in implementing particle codes on GPU’s using CUDA for some fluid simulation purposes.
My particle will need to have information like position, mass, momentum, position and some other physical parameters. In all my simulation will have N particles N>=10^5
My question is what is the most efficient way to represent data for these particles?
Do I represent the physical quantities over several arrays like mass[N] , momentum[N], positionx[N]
…. or do I create a
struct particle
{
mass M;
pressure p;
.
.
}
and then create an array out of these structs. Please advise.
Using separate arrays is preferred to using an array of structures. Using contiguous memory for each quantity allows for memory coalescing, whereas reading an arbitrary sized structure does not. Some quantities which are normally read as a tuple (say positions or velocity components) are probably best stored using one of the GPU intrinsic vector types (float2, float4) and read in a single memory transaction. This will maximise memory throughput.