// illustrations of thrust::gather(); permutes an array according to a
// map array

#include <stdio.h>
#include <thrust/device_vector.h>
#include <thrust/gather.h>

int main()
{  int x[5] = {12,13,5,8,88};
   int n=5;
   // copy x to device vector
   thrust::device_vector<int> hx(x,x+n);
   // allocate map vector
   thrust::device_vector<int> hm(n);
   // allocate vector for output of gather
   thrust::device_vector<int> hdst(n);
   // example map
   int m[5] = {3,2,4,1,0};
   thrust::copy(m,m+n,hm.begin());
   thrust::gather(hm.begin(),hm.end(),hx.begin(),hdst.begin());
   // the original x[3] should now be at position 0, the original x[2]
   // now at position 1, etc., i.e. 8,5,88,13,12; check it:
   for (int i = 0; i < 5; i++) printf("%d\n",hdst[i]);
}
