推力:如何有意避免将参数传递给算法?
Thrust: How to intentionally avoid passing a parameter into algorithm?
假设我想做一个 thrust::reduce_by_key
但我不关心输出键是什么。有没有一种方法可以通过某种方式将空对象(可能是空指针)传递到该参数的算法中,从而节省任何计算时间和内存分配,这样它就不会创建毫无意义的输出键列表?
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>());
其他信息:也许有更好的方法来完成我想要完成的事情。本质上,我已经在向量中存储了一组缩减键,因此将它们存储在现有的一组缩减键上是多余的,这就是我不关心输出键的原因。
丢弃迭代器就是为此而设计的。
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());
假设我想做一个 thrust::reduce_by_key
但我不关心输出键是什么。有没有一种方法可以通过某种方式将空对象(可能是空指针)传递到该参数的算法中,从而节省任何计算时间和内存分配,这样它就不会创建毫无意义的输出键列表?
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>());
其他信息:也许有更好的方法来完成我想要完成的事情。本质上,我已经在向量中存储了一组缩减键,因此将它们存储在现有的一组缩减键上是多余的,这就是我不关心输出键的原因。
丢弃迭代器就是为此而设计的。
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());