I am trying to partition an array with the thrust library's partition_copy function.
I have seen examples where pointers are passed, but I need to know how many elements are in each partition.
What I have tried is to pass device vectors as the OutputIterator parameters, something like this:
#include <thrust/device_vector.h>
#include <thrust/device_ptr.h>
#include <thrust/partition.h>
struct is_even {
__host__ __device__ bool operator()(const int &x) {
return (x % 2) == 0;
}
};
int N;
int *d_data;
cudaMalloc(&d_data, N*sizeof(int));
//... Some data is put in the d_data array
thrust::device_ptr<int> dptr_data(d_data);
thrust::device_vector<int> out_true(N);
thrust::device_vector<int> out_false(N);
thrust::partition_copy(dptr_data, dptr_data + N, out_true, out_false, is_even());
When I try to compile I get this error:
error: class "thrust::iterator_system<thrust::device_vector<int, thrust::device_allocator<int>>>" has no member "type"
detected during instantiation of "thrust::pair<OutputIterator1, OutputIterator2> thrust::partition_copy(InputIterator, InputIterator, OutputIterator1, OutputIterator2, Predicate) [with InputIterator=thrust::device_ptr<int>, OutputIterator1=thrust::device_vector<int, thrust::device_allocator<int>>, OutputIterator2=thrust::device_vector<int, thrust::device_allocator<int>>, Predicate=leq]"
So my question is: How can you use either thrust::partition or thrust::partition_copy and know how many elements you ended up with in each partition?