【发布时间】:2018-12-23 10:59:55
【问题描述】:
我有代码,看起来像:
...
const N=10000;
std::array<std::pair <int,int>,N> nnt;
bool compar(std::pair<int,int> i, std::pair <int,int> j) {return (int)
(i.second) > (int)(j.second);}
...
int main(int argc, char **argv)
{
#pragma acc data create(...,nnt)
{
#pragma acc parallel loop
{...}
//the nnt array is filled here
//here i need to sort nnt allocated on gpu, using the
//comparator compar()
}
}
所以我需要对一组对进行排序,通过 OpenAcc 的 CUDA 分配在 GPU 上。 据我了解,我不太可能在 GPU 上对 std::pair 的 std::array 进行排序。
实际上,我需要将分配在 gpu 上的一个数组与分配在 gpu 上的另一个数组排序,i。 e.如果有
int a[N];
int b[N];
通过 CUDA 或 OpenAcc 分配或复制到 GPU,我需要按数组 b 的值对数组 a 进行排序,并且我需要在 GPU 上完成这种排序。可能有一些 CUDA 函数会有所帮助,或者可以使用 CUDA 推力排序函数(如推力::stable_sort),我不知道。有没有办法做到这一点?
【问题讨论】:
标签: sorting cuda gpgpu openacc