// illustration of thrust::scatter(); permutes an array according to a
// map array

#include <stdio.h>
#include <thrust/device_vector.h>
#include <thrust/scatter.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::scatter(hx.begin(),hx.end(),hm.begin(),hdst.begin());
   // the original x[0] should now be at position 3, the original x[1]
   // now at position 2, etc., i.e. 88,8,13,12;,5 check it:
   for (int i = 0; i < 5; i++) printf("%d\n",hdst[i]);
}
