thrust::discard_iterator
Defined in thrust/iterator/discard_iterator.h
-
template<typename System = use_default>
class discard_iterator : public detail::discard_iterator_base::type<use_default> discard_iterator
is an iterator which represents a special kind of pointer that ignores values written to it upon dereference. This iterator is useful for ignoring the output of certain algorithms without wasting memory capacity or bandwidth.discard_iterator
may also be used to count the size of an algorithm’s output which may not be known a priori.The following code snippet demonstrates how to use
discard_iterator
to ignore one of the output ranges of reduce_by_key#include <thrust/iterator/discard_iterator.h> #include <thrust/reduce.h> #include <thrust/device_vector.h> int main() { thrust::device_vector<int> keys(7), values(7); keys[0] = 1; keys[1] = 3; keys[2] = 3; keys[3] = 3; keys[4] = 2; keys[5] = 2; keys[6] = 1; values[0] = 9; values[1] = 8; values[2] = 7; values[3] = 6; values[4] = 5; values[5] = 4; values[6] = 3; thrust::device_vector<int> result(4); // we are only interested in the reduced values // use discard_iterator to ignore the output keys thrust::reduce_by_key(keys.begin(), keys.end(), values.begin(), thrust::make_discard_iterator(), result.begin()); // result is now [9, 21, 9, 3] return 0; }
See also
make_discard_iterator