title: How do you make a pair vector out of two arrays and then sort by the first element of the pair using CUDA/Thrust?
body: <p>Okay, this is going to be a mouthful.</p>
  
  <p>I have a pointer to serialized 2D array, pointer arithmetic aside, I want to make a vector of pairs out of (essentially) two arrays(that I plan to get out of the 2D array). However, I need to use the <em>Thrust</em> library.</p>
  
  <p><strong>This is so that I can use thrust::sort() on the vector, based on the values of the first element of the pair. On the Device.</strong></p>
  
  <p>So, I need a vector(preferably thrust::device_vector) of pairs (of size to match the size of arrayOne and arrayTwo obviously), where the first element of the pair is from arrayOne, the second from arrayTwo. So that I can then use thrust::sort() in order to sort by the <strong>first</strong> element of the pair.</p>
  
  <p>Sorry, for the lack of code, but I'm still trying to figure out the finer details of how to implement this, hence the question. I'll post my attempts as I go along. Thank you in advance!</p>
  
  <p><strong>#UPDATE</strong></p>
  
  <p>I think I actually got lucky and found the solution since I posted the question(sort of, it a better solution than using pair - which in turn was suggested to me from a previous question I asked),
  turns out Thrust actually provides exactly what I'm looking for by default:</p>
  
  <pre><code>#include &lt;thrust/sort.h&gt;
    ...
    const int N = 6;
    int    keys[N] = {  1,   4,   2,   8,   5,   7};
    char values[N] = {'a', 'b', 'c', 'd', 'e', 'f'};
    thrust::sort_by_key(keys, keys + N, values);
    // keys is now   {  1,   2,   4,   5,   7,   8}
    // values is now {'a', 'c', 'b', 'e', 'f', 'd'}
  </code></pre>
  
  <p>*taken from <a href="http://code.google.com/p/thrust/wiki/QuickStartGuide#Fancy_Iterators" rel="nofollow">http://code.google.com/p/thrust/wiki/QuickStartGuide#Fancy_Iterators</a>*</p>
  
  <p>So, now all I have to do is get two thrust::device_vectors out of the two arrays (that I have to get out of the 2D array). Happy.</p>