Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Thrust: How to intentionally avoid passing a parameter into algorithm?

Suppose I want to do a thrust::reduce_by_key but I don't care about what the output keys are. Is there a way to save on any computation time and the memory allocation by somehow passing a null object (null pointer, perhaps) into the algorithm for that parameter so that it doesn't create a pointless list of output keys?

thrust::reduce_by_key(
    keys_input.begin(),
    keys_input.end(),
    values_input.begin(),
    null, //What can go here, if anything at all?
    values_output.begin(),
    thrust::equal_to<int>(),
    thrust::plus<int>());

Additional information: Maybe there is an even better way to do what I'm trying to accomplish. Essentially I already have a reduced set of keys stored in a vector so it would be redundant to store them over the existing set of reduced keys, which is why I don't care about the output keys.

like image 614
aiwyn Avatar asked Mar 18 '26 03:03

aiwyn


1 Answers

Discard iterator is designed for this.

https://thrust.github.io/doc/classthrust_1_1discard__iterator.html

thrust::reduce_by_key(keys.begin(), keys.end(),
                      values.begin(),
                      thrust::make_discard_iterator(),
                      result.begin());
like image 177
kangshiyin Avatar answered Mar 20 '26 16:03

kangshiyin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!