Question about the sorting method
Dear,
I am reading the code and now I have a question. When computing 'BeginEndCell', particles are sorted by their cell index, then the position of start and end particle in each cell can be found.
My question is that, when particles are sorted by their cell indices, are other associated values stored in memory, like position, velocity and density, sorted at the same time in this procedure? I tried to find the answer by reading thrust::stable_sort_by_key but still have no clue.
If other associated values are also sorted then it explains everything, but if not, how can the kernels computing interactions access the corresponding properties of a particle, since the order of the particle is different from the order in previous step?
Please help me. Thanks.
I am reading the code and now I have a question. When computing 'BeginEndCell', particles are sorted by their cell index, then the position of start and end particle in each cell can be found.
My question is that, when particles are sorted by their cell indices, are other associated values stored in memory, like position, velocity and density, sorted at the same time in this procedure? I tried to find the answer by reading thrust::stable_sort_by_key but still have no clue.
If other associated values are also sorted then it explains everything, but if not, how can the kernels computing interactions access the corresponding properties of a particle, since the order of the particle is different from the order in previous step?
Please help me. Thanks.
Comments
Yes, other values are sorted. the Thrust sort routine is used to sort a single "key" array, the results of this are then used just after to sort the actual data arrays within a single kernel call.
Best regards.
Could you please tell me in which kernel the associated values are reordered? In the same routine thrust::stable_sort_by_key or in later routines? Because I see the next routine is cudiv::CalcBeginEndCell, which is used to calculate the position of start and end in a cell.
Off the top of my head, look for the kernel "KerSortData", this is where everything is re ordered according to the sorted key array.
Best regards.
I was also reading the same parts of the code.
I would like to ask you why in void Sort (JCellDivGpu_ker.cu) you are using only the thrust::stable_sort_by_key and not also thrust::sort_by_key (if !stable)
What I mean is:
void Sort(unsigned* keys,unsigned* values,unsigned size,bool stable){
if(size){
thrust::device_ptr dev_keysg(keys);
thrust::device_ptr dev_valuesg(values);
if(!stable)thrust::stable_sort_by_key(dev_keysg,dev_keysg+size,dev_valuesg);
else thrust::stable_sort_by_key(dev_keysg,dev_keysg+size,dev_valuesg);
}
}
Many thanks for any feedback
e
Best regards.