5

コンテナーの要素をループするには、通常、次のように反復子を使用します。

container<type> myContainer;
// fill up the container
container<type>::iterator it;
for(it=myContainer.begin(); it!=myContainer.end(); ++it) {
   //do stuff to the elements of the container
}

ここで、OpenMP を使用してループを並列化したい場合は、次のようなことを試してみてください。

container<type> myContainer;
// fill up the container
container<type>::iterator it, it_begin=myContainer.begin(), it_end=myContainer.end();
#pragma omp parallel for default(none) private(it) shared(it_begin, it_end)
for(it=it_begin; it!=it_end; ++it) {
   //do stuff to the elements of the container
}

ただし、上記のコードを実行すると、コンテナーに変更が加えられません。ただし、コンテナーで一般的なインデックスを使用すると、並列コードは正常に機能します。私が疑問に思っているのは、OpenMP のコンテキストで反復子を使用できるかどうか、または反復ループをインデックス付きループに変換する必要があるかどうかです。

4

1 に答える 1

4

STLイテレータの並列化は、OpenMP3.0でのみ許可されています。コンパイラはどのバージョンのOpenMPをサポートしていますか?

于 2010-06-30T16:55:02.893 に答える