Question about the sorting method

edited February 2014 in Old versions
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.

Comments

  • Hello,

    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.
  • Thank you, SLongshaw.

    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.
  • Hi,

    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.
  • Thank you very much!
  • Dear all,

    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
  • Hello, the thrust library provides two sorting algorithms, one that is designed to be as fast as possible but does not guarantee order of results in the case of two values being sorted being the same and one that does but may be slightly slower. The section of code you are seeing simply allows one or the other to be used depending on whether the appropriate input parameter is passed to the executable.

    Best regards.
Sign In or Register to comment.