推力相当于cilk :: reducer_list_append

时间:2012-06-28 12:54:14

标签: thrust cilk cilk-plus

我有一个n个区间或域的列表。我想将每个间隔并行细分为k个部分,形成一个新的列表(无序)。但是,大部分细分都不会通过某些标准,也不应该添加到新列表中。

cilk :: reducer_list_append将并行缩减的概念扩展为使用push_back形成列表。这样我就可以并行收集有效的子间隔。

完成任务的主要方法是什么?我怀疑有一种方法是形成一个大的nxk列表,然后使用并行过滤器和流压缩?但我真的希望有一个减少列表附加操作,因为nxk确实非常大。

1 个答案:

答案 0 :(得分:1)

我是这个论坛的新手,但也许你会发现其中一些很有用.. 如果您没有修复Thrust,您还可以查看Arrayfire。 我最近才了解它,并且可以解决这类问题。

例如,使用arrayfire,您可以评估每个间隔的选择标准 并行使用gfor构造,即。考虑:

// # of intervals n and # of subintervals k
const int n = 10, k = 5;

// this array represets original intervals
array A = seq(n); // A = 0,1,2,...,n-1

// for each interval A[i], subI[i] counts # of subintervals       
array subI = zeros(n);  

gfor(array i, n) {  // in parallel for all intervals
    // here evaluate your predicate for interval's subdivision
    array pred = A(i)*A(i) + 1234;
    subI(i) = pred % (k + 1);
}

//array acc = accum(subI);
int n_total = sum<float>(subI); // compute the total # of intervals
// this array keeps intervals after subdivision
array B = zeros(n_total);

std::cout << "total # of subintervals: " << n_total << "\n";
print(A);
print(subI);

gfor(array i, n_total) {
    // populate the array of new intervals
B(i) = ...
}
print(B);

当然,这取决于你的间隔的表示方式 你用于细分的标准..