有没有类似于PPL在TBB中的任务延续? 我知道手册册分配tbb::task
S的水平低TBB方法和手动分配也延续任务和手动管理裁判计数他们:英特尔TBB中的任务继续TBB
struct FibContinuation: public task {
long* const sum;
long x, y;
FibContinuation(long* sum_) : sum(sum_) {}
task* execute() {
*sum = x+y;
return NULL;
}
};
struct FibTask: public task {
const long n;
long* const sum;
FibTask(long n_, long* sum_) :
n(n_), sum(sum_)
{}
task* execute() {
if(n<CutOff) {
*sum = SerialFib(n);
return NULL;
} else {
// long x, y; This line removed
FibContinuation& c =
*new(allocate_continuation()) FibContinuation(sum);
FibTask& a = *new(c.allocate_child()) FibTask(n-2,&c.x);
FibTask& b = *new(c.allocate_child()) FibTask(n-1,&c.y);
// Set ref_count to "two children plus one for the wait".
c.set_ref_count(2);
spawn(b);
spawn(a);
// *sum = x+y; This line removed
return NULL;
}
}
};
这简直太可怕了。 您必须事先知道您将产卵多少个孩子,并手动设置参考计数。这是很脆弱的编码...
PPL的规定延续的方式就是这么简单:
create_task([]()->bool
{
// compute something then return a bool result
return true
}).then([](bool aComputedResult)
{
// do something with aComputedResult
});
你如何做到这一点的TBB?
只是一些随机的想法。提升期货有'然后',我认为自1.53以来,可能不是所有的方法都实现了,而其他方法可能有一些错误。检查文档。 TBB没有类似的东西,接近的就是TBB流程图。您可以为您的消息创建流程方案,TBB将尽可能并行化。虽然这不像'then'那么简单,但它也更强大。最后,我想提到的是,TBB并不关注基于任务的并行性,而是关注将数据并行问题提取出来的算法模式。 – inf
@bamboon嗯,我会给一个想法,谢谢你回答 –
问题是比较两种不同语言方言的实现,并抱怨一个而不是其他问题的具体问题的脆弱性。 TBB例子可以循环两次新的增量产卵,现在脆弱性消失了。可能还有更高效的spawn_all()或者其他东西! – mabraham