Search code examples
cudathrust

CUDA thrust: how to realize "partition" that supports "stencil"?


Suppose there is an array of intergers:

A[]={2, 2, 9, 8, 5, 7, 0, 6}

and a stencil:

B[]={1, 0, 0, 1, 1, 1, 0, 1}

My question is how could we rearrange A[] according to B[] such that if B[i]==1, B[j]==0, then A[i] will be guaranteed to precede A[j] in the new array, which should look like:

C[]={2, 8, 5, 7, 6, 2, 9, 0}

PS: I found the "partition" function was almost the answer except that it only supported predicate. Is there any workaround?

Any hint is much appreciated!


Solution

  • This can be implemented using thrust::stable_sort_by_key().