2 次元配列で熱力学シミュレーションを行っています。配列は 1024x1024 です。while ループは、指定された回数だけ、または goodTempChange が false になるまで反復します。goodTempChange は、定義された EPSILON 値よりも大きいブロックの温度変化に基づいて、true または false に設定されます。配列内のすべてのブロックがその値を下回っている場合、プレートは静止しています。プログラムは動作します。コードに問題はありません。私の問題は、シリアル コードが openmp コードを水から完全に吹き飛ばしていることです。どうしてか分かりません。希望する正方形の周囲の上下左右の 4 つのブロックの平均である平均計算以外はすべて削除しようとしましたが、それでもシリアル コードによって破壊されています。私は以前にopenmpをやったことがなく、自分が持っていることをするためにオンラインでいくつかのものを調べました。可能な限り最も効率的な方法で重要な領域内に変数を配置しました。競合状態はありません。何が悪いのか本当にわかりません。どんな助けでも大歓迎です。ありがとう。
while(iterationCounter < DESIRED_ITERATIONS && goodTempChange) {
goodTempChange = false;
if((iterationCounter % 1000 == 0) && (iterationCounter != 0)) {
cout << "Iteration Count Highest Change Center Plate Temperature" << endl;
cout << "-----------------------------------------------------------" << endl;
cout << iterationCounter << " "
<< highestChange << " " << newTemperature[MID][MID] << endl;
cout << endl;
}
highestChange = 0;
if(iterationCounter != 0)
memcpy(oldTemperature, newTemperature, sizeof(oldTemperature));
for(int i = 1; i < MAX-1; i++) {
#pragma omp parallel for schedule(static)
for(int j = 1; j < MAX-1; j++) {
bool tempGoodChange = false;
double tempHighestChange = 0;
newTemperature[i][j] = (oldTemperature[i-1][j] + oldTemperature[i+1][j] +
oldTemperature[i][j-1] + oldTemperature[i][j+1]) / 4;
if((iterationCounter + 1) % 1000 == 0) {
if(abs(oldTemperature[i][j] - newTemperature[i][j]) > highestChange)
tempHighestChange = abs(oldTemperature[i][j] - newTemperature[i][j]);
if(tempHighestChange > highestChange) {
#pragma omp critical
{
if(tempHighestChange > highestChange)
highestChange = tempHighestChange;
}
}
}
if(abs(oldTemperature[i][j] - newTemperature[i][j]) > EPSILON
&& !tempGoodChange)
tempGoodChange = true;
if(tempGoodChange && !goodTempChange) {
#pragma omp critical
{
if(tempGoodChange && !goodTempChane)
goodTempChange = true;
}
}
}
}
iterationCounter++;
}