短い外側のループと長い内側のループを実行する必要があります。前者ではなく後者を並列化したいと思います。その理由は、内側のループが実行された後に更新される配列があるためです。私が使用しているコードは次のとおりです
#pragma omp parallel{
for(j=0;j<3;j++){
s=0;
#pragma omp for reduction(+:s)
for(i=0;i<10000;i++)
s+=1;
A[j]=s;
}
}
これは実際にハングします。以下は問題なく機能しますが、新しい並列領域を開始するオーバーヘッドは避けたいと思います。
for(j=0;j<3;j++){
s=0;
#pragma omp parallel for reduction(+:s)
for(i=0;i<10000;i++)
s+=1;
A[j]=s;
}
これを行う正しい(そして最速の)方法は何ですか?