aiwyn
aiwyn

Reputation: 278

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.

Upvotes: 3

Views: 134

Answers (1)

kangshiyin
kangshiyin

Reputation: 9771

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());

Upvotes: 4

Related Questions