我开始使用推力。我只是写了一个简单的函数来填充向量,这里我有
template <class T> void fillzeros(T &v, int size)
{
v.reserve(size);
thrust::fill(v.begin(), v.end(), 0);
}
void main(void)
{
thrust::device_vector<float> V;
thrust::host_vector<float> W;
fillzeros(V, 100); // works
fillzeros(W, 100); // it doesn't compile, lots of error comes out
// if I want to crease W, I have to do
W = V; // so I must generate device vector in advance?
// I also try the following example shown in the thrust website, still don't compile
thrust::device_vector<int> vv(4);
thrust::fill(thrust::device, vv.begin(), vv.end(), 137);
}
看来我无法直接创建和分配 device_vector 。我必须先创建 host_vector 并将其分配给 device_vector。
顺便说一句,如果我将函数作为模板传递,如何确定函数中的向量类型?
ps 关于thrust::system::detail::generic::uninitialized_fill_n 的错误太多