title: Concurrently sorting many arrays with CUDA Thrust
body: <p>I need to sort <code>20+</code> arrays, already on the GPU, each of the same length, by the same keys. I can not use <code>sort_by_key()</code> directly since it sorts the keys as well (making them useless to sort the next array). Here is what I tried instead:</p>
  
  <pre><code>thrust::device_vector&lt;int&gt;  indices(N); 
  thrust::sequence(indices.begin(),indices.end());
  thrust::sort_by_key(keys.begin(),keys.end(),indices.begin());
  
  thrust::gather(indices.begin(),indices.end(),a_01,a_01);
  thrust::gather(indices.begin(),indices.end(),a_02,a_02);
  ...
  thrust::gather(indices.begin(),indices.end(),a_20,a_20);
  </code></pre>
  
  <p>This does not seem to work since <code>gather()</code> expects a different array for the output than for the input, i.e. this works:</p>
  
  <pre><code>thrust::gather(indices.begin(),indices.end(),a_01,o_01);
  ...
  </code></pre>
  
  <p>However, I would prefer to not allocate <code>20+</code> extra arrays for this task. I know that there is a solution using a thrust::tuple, thrust::zip_iterator and thrust::sort_by_keys(), similiar to <a href="http://choorucode.wordpress.com/2011/06/27/thrust-compact-multiple-vectors-using-predicate/" rel="nofollow">here</a>. However, I can only combine up to <code>10</code> arrays in a tuple, s.t. I would need to duplicate the key vector again. How would you tackle this task?</p>