sort each row in a matrix?

Are there CUDA library to sort each row in a matrix simultaneously?

if I use thrust sort library, I have to sequentially call thrust sort function to sort each row, if there are 10000 rows, I need to make 10000 sequential calls. This is not efficient.

Any help on this?

Thanks a lot!

Hi Zhao,

You can try sort in ArrayFire.

Here is a snippet of code that can help understand it:

array a = randu(4, 3); // random matrix of 4 rows and 3 columns

array b = sort(a, 0); // Sort along the columns

array c = sort(a, 1); // Sort along the rows

print(a);

print(b);

print(c);

outputs

a =

           0.7402        0.9251        0.4702 

           0.9210        0.4464        0.5132 

           0.0390        0.6673        0.7762 

           0.9690        0.1099        0.2948 

b =

           0.0390        0.1099        0.2948 

           0.7402        0.4464        0.4702 

           0.9210        0.6673        0.5132 

           0.9690        0.9251        0.7762 

c =

           0.4702        0.7402        0.9251 

           0.4464        0.5132        0.9210 

           0.0390        0.6673        0.7762 

           0.1099        0.2948        0.9690

thanks for your reply!

Actually, I’ve tried ArrayFire and installed successfully.

However, when I tried example codes, it always gave “segmentation fault” info. No clue about it.

I run ArrayFire on a GPU cluster through Putty~