parallel_for_each
[algorithms.parallel_for_each]
ワーク項目を並列に処理する関数テンプレート。
// <oneapi/tbb/parallel_for_each.h> ヘッダーで定義
namespace oneapi {
namespace tbb {
template<typename InputIterator, typename Body>
void parallel_for_each( InputIterator first, InputIterator last, Body body );
template<typename InputIterator, typename Body>
void parallel_for_each( InputIterator first, InputIterator last, Body body, task_group_context& context );
template<typename Container, typename Body>
void parallel_for_each( Container& c, Body body );
template<typename Container, typename Body>
void parallel_for_each( Container& c, Body body, task_group_context& context );
template<typename Container, typename Body>
void parallel_for_each( const Container& c, Body body );
template<typename Container, typename Body> void parallel_for_each( const Container& c, Body body, task_group_context& context );
} // namespace tbb
} // namespace oneapi要件:
Bodyタイプは、ParallelForEachBody 要件を満たしている必要があります。InputIteratorタイプは、[input.iterators] ISO C++ 標準の 入力イテレーターの要件を満たしている必要があります。Containerタイプは、ContainerBasedSequence 要件を満たしている必要があります。
parallel_for_each テンプレートには 2 つの形式があります。
シーケンス形式の parallel_for_each(first, last, body) は、関数オブジェクトの body をシーケンス [first,last) に適用します。項目は並列に処理されます。
コンテナー形式の parallel_for_each(c, body) は、 parallel_for_each(std::begin(c), std::end(c), body) を同等です。
すべてのオーバーロードは task_group_context オブジェクトを受け入れることが可能であるため、アルゴリズムのタスクはこのコンテキストで実行されます。デフォルトでは、アルゴリズムは自身がバインドされているコンテキストで実行されます。
feeder クラス
feeder タイプの第 2 引数がある場合、追加のワーク項目を body に追加できます。 この関数は、body(x) が入力シーケンス内、または feeder::add メソッドによって追加されたすべての項目 x を返すと終了します。
例
次のコードは、引数が 2 つの形式の operator() を使用するボディーを示します。
struct MyBody {
void operator()(item_t item, parallel_do_feeder<item_t>& feeder ) {
for each new piece of work implied by item do {
item_t new_item = initializer;
feeder.add(new_item);
}
}
};