在一个while循环内调用tbb::parallel_for。

huangapple go评论57阅读模式
英文:

Calling tbb::parallel_for inside a while loop

问题

你的理解是正确的。在这段伪代码中,parallel_for 被嵌套在一个循环中,每次迭代循环都会调用 parallel_for 来处理不同的数据集。在第一次迭代中,所有线程完成执行后,才会进行下一次迭代的 parallel_for 调用。这是因为第二次迭代依赖于第一次迭代的结果。

希望这个解释对你有所帮助。

英文:

I would like to call tbb::parallel_for inside a while loop with different sets of data. Is my understanding correct that only after all the threads have finished executing in the 1st iteration of the while loop, the parallel_for in the next iteration of the while loop is called. This is because the 2nd iteration of the while loop is dependent on the results of the 1st iteration.
Please let me know.

I am thinking that the while loop is sequential in its processing and only after the 1st iteration threads have completed, the next iteration parallel_for is called

Here is some pseudo code: I am using a for loop instead of a while loop

map<int, vector<object*> > objmap;

for(auto objvec : objmap)
{
parallel_for(objVec.begin(),objectVec.end(),grainsize),
someObject,
simple_partitioner());
}

答案1

得分: 1

A tbb::parallel_for 在完成所有迭代之后才返回,除非它被取消,在这种情况下,它会等待取消机制完成。封闭的 while 循环是顺序的,因此第二次调用 tbb::parallel_for 从第一次调用中读取结果是安全的。

英文:

A tbb::parallel_for completes all iterations before returning, unless it is cancelled, in which case it waits until the cancellation machinery finishes. The enclosing while loop is sequential, so it's safe for the 2nd invocation of the tbb::parallel_for to read results from the 1st invocation.

huangapple
  • 本文由 发表于 2023年6月19日 08:09:05
  • 转载请务必保留本文链接:https://go.coder-hub.com/76502963.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定