我正在尝试执行thrust::reduce_by_key使用 zip 和排列迭代器。即在几个“虚拟”排列数组的压缩数组上执行此操作。我在编写 functor 的语法时遇到了麻烦density_update。
但首先是问题的设置。
这是我的函数调用:
thrust::reduce_by_key( dflagt,
dflagtend,
thrust::make_zip_iterator(
thrust::make_tuple(
thrust::make_permutation_iterator(dmasst, dmapt),
thrust::make_permutation_iterator(dvelt, dmapt),
thrust::make_permutation_iterator(dmasst, dflagt),
thrust::make_permutation_iterator(dvelt, dflagt)
)
),
thrust::make_discard_iterator(),
danswert,
thrust::equal_to<int>(),
density_update()
)
dmapt,dflagt属于thrust::device_ptr<int>和dvelt,dmasst并且danst属于
thrust::device_ptr<double>.
(它们是我原始 cuda 数组的推力包装器)
数组mapt和flagt都是索引向量,我需要从中执行从数组dmasst和dvelt.
在减少步骤之后,我打算将我的数据写入danswert数组。由于在减少中使用了多个数组,显然我使用的是 zip 迭代器。
我的问题在于编写density_update二元运算的函子。
struct density_update
{
typedef thrust::device_ptr<double> ElementIterator;
typedef thrust::device_ptr<int> IndexIterator;
typedef thrust::permutation_iterator<ElementIterator,IndexIterator> PIt;
typedef thrust::tuple< PIt , PIt , PIt, PIt> Tuple;
__host__ __device__
double operator()(const Tuple& x , const Tuple& y)
{
return thrust::get<0>(*x) * (thrust::get<1>(*x) - thrust::get<3>(*x)) + \
thrust::get<0>(*y) * (thrust::get<1>(*y) - thrust::get<3>(*y));
}
};
返回的值是double。为什么二元运算看起来像上面的仿函数并不重要。我只想知道我将如何在语法上更正上述内容。如上所示,代码引发了许多编译错误。我不确定我哪里出错了。
我在 Ubuntu 10.10 上的 GTX 570 上使用 CUDA 4.0