OpenMPタスクに問題があります。私はompタスクを使って "for"ループの並列バージョンを作成しようとしています。しかし、このバージョンの実行時間は、ompのために使うベースバージョンの2倍に近く、この理由は分かりません。コードを見ては、ベローズ:バージョンOpenMPタスクの並列処理 - パフォーマンスの問題
OMP:
t.start();
#pragma omp parallel num_threads(threadsNumber)
{
for(int ts=0; ts<1000; ++ts)
{
#pragma omp for
for(int i=0; i<size; ++i)
{
array_31[i] = array_11[i] * array_21[i];
}
}
}
t.stop();
cout << "Time of omp for: " << t.time() << endl;
OMPタスクバージョン:タスクのバージョンで
t.start();
#pragma omp parallel num_threads(threadsNumber)
{
#pragma omp master
{
for(int ts=0; ts<1000; ++ts)
{
for(int th=0; th<threadsNumber; ++th)
{
#pragma omp task
{
for(int i=th*blockSize; i<th*blockSize+blockSize; ++i)
{
array_32[i] = array_12[i] * array_22[i];
}
}
}
#pragma omp taskwait
}
}
}
t.stop();
cout << "Time of omp task: " << t.time() << endl;
を私はのためのOMPと同様にループを分割します。各タスクは同じ量の反復を実行する必要があります。タスクの総量はスレッドの総量に等しい。
性能結果:
Time of omp for: 4.54871
Time of omp task: 8.43251
何が問題になることができますか?どちらのバージョンでも同様のパフォーマンスが得られますか?私が解決しようとする私の問題だけを説明したかったので、添付されたコードは簡単です。どちらのバージョンでも同じパフォーマンスが得られるとは思っていませんが、違いを減らしたいと思います。
お返事ありがとうございます。 よろしくお願いいたします。