     }
 
     // initialize permutation to [0, 1, 2, ... ,N-1]
-    thrust::host_vector<int> permutation(N);
+    thrust::device_vector<int> permutation(N);
     thrust::sequence(permutation.begin(), permutation.end());
 
     // sort from least significant key to most significant keys

#include <thrust/host_vector.h>
#include <thrust/generate.h>
#include <thrust/sequence.h>
#include <thrust/sort.h>


    // Note: keys have not been modified
    // Note: permutation now maps unsorted keys to sorted order
  
    // permute the key arrays by the final permuation
    apply_permutation(lower,  permutation);
    apply_permutation(middle, permutation);
    apply_permutation(upper,  permutation);

    std::cout << "Sorted Keys" << std::endl;
    for(size_t i = 0; i < N; i++)
    {
        std::cout << "(" << upper[i] << "," << middle[i] << "," << lower[i] << ")" << std::endl;
    }

    return 0;
}

