Say I have a vector of keys
thrust::device_vector<int> keys(10);
keys[0] = 51; // ----->
keys[1] = 51;
keys[2] = 72; // ----->
keys[3] = 72;
keys[4] = 72;
keys[5] = 103; //----->
keys[6] = 103;
keys[7] = 504; // ------>
keys[8] = 504
keys[9] = 504 ;
I already know before hand that there are 4 distinct key values in
this vector. I want to populate the two device arrays
pidx[4] and pnum[4].
-
The
pidxarray gives me the first position of each distinct key in the
keys vector, namely the positions marked with---->in the code snippet above. So, in this example, I should havepidx[4] = {0, 2, 5, 7}. -
The
pnumarray gives me the number of occurrences of each key. So, in this example, I should have
pnum[4] = {2, 3, 2, 3}.
How would one perform the above operation with CUDA Thrust?
This is not the optimal solution, but I can’t figure out a better way.