Thrust
|
◆ count_if() [1/2]
template<typename DerivedPolicy , typename InputIterator , typename Predicate >
The algorithm's execution is parallelized as determined by
The following code snippet demonstrates how to use #include <thrust/count.h> #include <thrust/device_vector.h> #include <thrust/execution_policy.h> ... struct is_odd { __host__ __device__ bool operator()(int &x) { return x & 1; } }; ... // fill a device_vector with even & odd numbers thrust::device_vector<int> vec(5); vec[0] = 0; vec[1] = 1; vec[2] = 2; vec[3] = 3; vec[4] = 4; // count the odd elements in vec // result == 2 |