Compiler errors 置换迭代器不工作时的推力擦除

Compiler errors 置换迭代器不工作时的推力擦除,compiler-errors,cuda,permutation,thrust,erase,Compiler Errors,Cuda,Permutation,Thrust,Erase,我有一个设备向量a。我有一个映射M。我想用映射M擦除元素。 我尝试了下面的方法,但它没有给编译错误重载函数的实例 #include <thrust/sequence.h> #include <thrust/execution_policy.h> #include <thrust/iterator/permutation_iterator.h> #include <thrust/fill.h> void erase_value_using_map(

我有一个设备向量a。我有一个映射M。我想用映射M擦除元素。 我尝试了下面的方法,但它没有给编译错误重载函数的实例

#include <thrust/sequence.h>
#include <thrust/execution_policy.h>
#include <thrust/iterator/permutation_iterator.h>
#include <thrust/fill.h>

void erase_value_using_map( thrust::device_vector<int>& A, thrust::device_vector<int> Map)
{

A.erase(thrust::make_permutation_iterator(A.begin(), Map.begin()),
        thrust::make_permutation_iterator(A.begin(), Map.end()));

}

int main(int argc, char * argv[])
{
thrust::device_vector<int> A(20);
thrust::sequence(thrust::device, A.begin(), A.end(),0);  // x components of the 'A' vectors

thrust::device_vector<int> Map(10);
Map[0]=2;Map[1]=4;Map[2]=8;Map[3]=10;Map[4]=11;Map[5]=13;Map[6]=15;Map[7]=17;Map[8]=19;Map[9]=6;

erase_value_using_map(A, Map);

return 0;
}
错误消息:

error: no instance of overloaded function "thrust::device_vector<T, Alloc>::erase [with T=int, Alloc=thrust::device_malloc_allocator<int>]" matches the argument list
            argument types are: (thrust::permutation_iterator<thrust::detail::normal_iterator<thrust::device_ptr<int>>, thrust::detail::normal_iterator<thrust::device_ptr<int>>>, thrust::permutation_iterator<thrust::detail::normal_iterator<thrust::device_ptr<int>>, thrust::detail::normal_iterator<thrust::device_ptr<int>>>)
            object type is: thrust::device_vector<int, thrust::device_malloc_allocator<int>>

我使用Talonmes建议的gatheras找到了解决方案,并调整了大小

#include <thrust/gather.h>
#include <thrust/device_vector.h>
#include <thrust/execution_policy.h>

int main()
{

thrust::device_vector<int> d_values(10);
d_values[0]=0;d_values[1]=10;d_values[2]=20;d_values[3]=30;d_values[4]=40;
d_values[5]=50;d_values[6]=60;d_values[7]=70;d_values[8]=80;d_values[9]=90;

thrust::device_vector<int> d_map(7);
d_map[0]=0;d_map[1]=2;d_map[2]=4;d_map[3]=6;d_map[4]=8;d_map[5]=1;d_map[6]=3;

thrust::device_vector<int> d_output(10);
thrust::gather(thrust::device,
               d_map.begin(), d_map.end(),
               d_values.begin(),
               d_output.begin());

d_output.resize(d_map.size());

return 0;
}

它显然不受支持,即使编译也没有意义。置换迭代器是一种构造,其值在解引用时按指定顺序从源向量返回值。但是,设想迭代器值是源向量中的有效迭代器是不合逻辑的。此外,您尝试使用开始/结束迭代器显然是失败的。文档中清楚地描述了置换迭代器的语义,这显然不是它的用例。那么,我如何有选择地删除设备向量的一些成员呢?它必须使用擦除,但还需要其他一些算法。有什么提示吗?如果不使用单独的设备_vectorI,我怀疑有一种方法通常是作为聚集操作来完成的,因此完全相反的意义——复制您想要的值,而不是删除您不想要的值可能是另一种选择使用推力::分区将您想要保留的值移动到向量的开头。然后使用向量擦除方法本身。