我已经看到了传递指针的示例,但是我需要知道每个分区中有多少个元素。
我试图将设备矢量作为OutputIterator参数传递,如下所示:
#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());
当我尝试编译时出现此错误:
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]"
所以我的问题是:如何使用推力::: partition或推力::: partition_copy并知道每个分区中最终包含多少个元素?
我正在尝试使用推力库的partition_copy函数对数组进行分区。我已经看到了传递指针的示例,但是我需要知道每个分区中有多少个元素。什么...