У меня есть два набора A & B из 20 и 10 целых чисел соответственно.B является подмножеством A. Мне нужно найти бесплатный набор B. Я использую thrust :: set_difference, чтобы найти разницу в наборе, однако он не может быть скомпилирован с сообщением: warning: calling a __host__ function from a __host__ __device__ function is not allowed
Мой код такойниже.Я не знаю, почему этот простой код не компилируется.
#include <thrust/sequence.h>
#include <thrust/execution_policy.h>
#include <thrust/set_operations.h>
#include <thrust/device_vector.h>
thrust::device_vector<int> find_complimentary_set(thrust::device_vector<int> A, thrust::device_vector<int> B)
{
thrust::sort(thrust::device, A.begin(), A.end());
thrust::sort(thrust::device, B.begin(), B.end());
int N=A.size()-B.size();
thrust::device_vector<int> complimentary_set(N);
**// the following line causes the compilation error**
thrust::set_difference(thrust::device, A.begin(), A.end(), B.begin(), B.end(), complimentary_set);
return complimentary_set;
}
int main(int argc, char * argv[])
{
int N=20;
thrust::device_vector<int> A(N);
thrust::sequence(thrust::device, A.begin(), A.end(),0);
thrust::device_vector<int> B(10);
B[0]=2;B[1]=4;B[2]=8;B[3]=10;B[4]=11;B[5]=13;B[6]=15;B[7]=17;B[8]=19;B[9]=6;
find_complimentary_set(A, B);
return 0;
}
Моя ошибка компиляции огромна.Я нашел 8 ошибок в них, которые я перечислю ниже:
/usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/system/cuda/detail/detail/set_operation.inl(517): error: no operator "+" matches these operands
operand types are: thrust::device_vector<int, thrust::device_malloc_allocator<int>> + thrust::reference<signed long, thrust::pointer<signed long, thrust::system::cuda::detail::par_t, thrust::use_default, thrust::use_default>, thrust::use_default>
/usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/system/cuda/detail/detail/set_operation.inl(648): error: no operator "+" matches these operands
operand types are: thrust::device_vector<int, thrust::device_malloc_allocator<int>> + signed long
/usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/system/detail/sequential/set_operations.h(64): error: no operator "*" matches these operands
operand types are: * thrust::device_vector<int, thrust::device_malloc_allocator<int>>
/usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/system/detail/sequential/set_operations.h(66): error: no operator "++" matches these operands
operand types are: ++ thrust::device_vector<int, thrust::device_malloc_allocator<int>>
/usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/iterator/iterator_traits.h(49): error: class "thrust::device_vector<int, thrust::device_malloc_allocator<int>>" has no member "iterator_category"
/usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/system/detail/sequential/general_copy.h(106): error: no operator "++" matches these operands
operand types are: ++ thrust::device_vector<int, thrust::device_malloc_allocator<int>>
/usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/system/detail/sequential/general_copy.h(76): error: no operator "*" matches these operands
operand types are: * thrust::device_vector<int, thrust::device_malloc_allocator<int>>