Contents

mThrust demo 03

sample usage of sort function on mThrust object
clear all
dx=Thrust.randn(10^6) % set random vector on GPU device
dx = 

 thrust::device_vector<double>[1000000]
 2.1741  -1.80139  1.05034  0.546891  0.508632  
 . . .
 -0.0486268  -0.322886  0.403298  -0.447404  0.559804  

Computation on device

dy=sort(dx)
dz=sort(dx,'mode','descend')
dy = 

 thrust::device_vector<double>[1000000]
 -4.88114  -4.69934  -4.50768  -4.43196  -4.37628  
 . . .
 4.33256  4.34042  4.36677  4.52094  4.53414  

dz = 

 thrust::device_vector<double>[1000000]
 4.53414  4.52094  4.36677  4.34042  4.33256  
 . . .
 -4.37628  -4.43196  -4.50768  -4.69934  -4.88114  
[dy,dI]=sort(dx)
dx(dI)==dy
dy = 

 thrust::device_vector<double>[1000000]
 -4.88114  -4.69934  -4.50768  -4.43196  -4.37628  
 . . .
 4.33256  4.34042  4.36677  4.52094  4.53414  

dI = 

 thrust::device_vector<int>[1000000]
 637398  594845  483962  319798  899835  
 . . .
 813296  170164  199525  2369  162902  

ans = 

 thrust::device_vector<logical>[1000000]
 1  1  1  1  1  
 . . .
 1  1  1  1  1  
[dz,dJ]=sort(dx,'mode','descend')
dx(dJ)==dz
dz = 

 thrust::device_vector<double>[1000000]
 4.53414  4.52094  4.36677  4.34042  4.33256  
 . . .
 -4.37628  -4.43196  -4.50768  -4.69934  -4.88114  

dJ = 

 thrust::device_vector<int>[1000000]
 162902  2369  199525  170164  813296  
 . . .
 899835  319798  483962  594845  637398  

ans = 

 thrust::device_vector<logical>[1000000]
 1  1  1  1  1  
 . . .
 1  1  1  1  1  

inline sort

dx.sort()
dx
dx = 

 thrust::device_vector<double>[1000000]
 -4.88114  -4.69934  -4.50768  -4.43196  -4.37628  
 . . .
 4.33256  4.34042  4.36677  4.52094  4.53414