こんにちは私はopenMPでこのコードの計算を並列化しようとしています。有限差分法を用いた流体力学渦度の計算である。私はそうするためにAlternating direction暗黙の方法を使用しています。openMP交互方向暗黙のメソッド
私はその実行をスピードアップしたいと思います。 (ここではNx = Ny = 100)
問題は、openMpを使用するとコードをスピードアップするのではなく速度を落とすことです。私は共有変数を指定しようとしましたが、これはあまり役に立ちません。
すべてのベストvoid ADI(double vort[][Ny], double psi[][Ny], double n[][Ny],
double cls[][Ny],double AAx[], double BBx[], double CCx[], double DDx[],
double AAy[], double BBy[], double CCy[], double DDy[],
double cx[][Ny], double cy[][Ny], double epsx[][Ny], double epsy[][Ny],
double vortx[], double vorty[Ny-2], double dx, double Dxs, double coefMass,
double coefMasCls)
{
////////////calcul sur y////////////
//calcul coef ADI
int i=0, j=0;
#pragma omp parallel for private(Dxs,i) shared(psi,vort)
for (i=0; i<Nx; i++) //Boundary condition sur x
{
vort[i][0]=(psi[i][0]-psi[i][1])*2/Dxs;
vort[i][Ny-1] = (psi[i][Ny-1]-psi[i][Ny-2])*2/Dxs;
}
#pragma omp parallel for private(Dxs,j) shared(psi,vort)
for (j=0; j<Ny; j++) //Boundary condition
{
vort[0][j] = (psi[0][j]-psi[1][j])*2/Dxs;
vort[Nx-1][j] = (psi[Nx-1][j]-psi[Nx-2][j])*2/Dxs;
}
for (j=1; j<Ny-1; j++) //interior points
{
#pragma omp parallel for private(coefMasCls,coefMasCls,i) shared(psi,vort,n,cls)
for (i=1; i<Nx-1; i++) //interior points
{
vort[i][j] = vort[i][j] - coefMass * (n[i+1][j]-n[i-1][j])- coefMasCls * (cls[i+1][j]-cls[i-1][j]);;
}
//i=0;
//vort[i][j] = vort[i][j] + coefMass*(n[1][j]-n[1][j]);
//i=Nx-1;
//vort[i][j] = vort[i][j] + coefMass*(n[Nx-2][j]-n[Nx-2][j]);
}
for (i=1; i<Nx-1; i++) //interior points
{
for (j=1; j<Ny-1; j++) //interior points
{
AAy[j] = -.5 * (.5 * (1 + epsy[i][j]) * cy[i][j-1] + dx);
BBy[j] = 1 + dx + .5 * epsy[i][j] * cy[i][j];
CCy[j] = .5 * (.5 * (1 - epsy[i][j]) * cy[i][j+1] - dx);
DDy[j] = .5 * (.5 * (1 + epsx[i][j]) * cx[i-1][j] + dx) * vort[i-1][j]
+ (1 - dx - .5 * epsx[i][j] * cx[i][j]) * vort[i][j]
+ .5 * (- .5 * (1 - epsx[i][j]) * cx[i+1][j] + dx) * vort[i+1][j];
vorty[j] = vort[i][j];
}
DDy[1]=DDy[1] - AAy[1] * vort[i][0]; //the AA[0] are not taken into account in the tridiag methode. Include it in the second hand
DDy[Ny-2]=DDy[Ny-2] - CCy[Ny-2]* vort[i][Ny-1]; //moving boundary condition
//DDy[Ny-3]= DDy[Ny-3]; //vorticity nul on the free slip boundary condition
tridiag(AAy, BBy, CCy, DDy, vorty, Ny-1); //ne calcul pas le point en 0 et en Ny-1
for (j=1; j<Ny-1; j++)
{
vort[i][j]=vorty[j];
}
}
////////////calcul sur x //////////
//calcul coef ADI
for (j=1; j<Ny-1; j++)
{
for (i=1; i<Nx-1; i++)
{
AAx[i] = -.5* (.5 * (1 + epsx[i][j]) * cx[i-1][j] + dx);
BBx[i] = 1 + dx + .5 * epsx[i][j] * cx[i][j];
CCx[i] = .5 * (.5 * (1 - epsx[i][j]) * cx[i+1][j] - dx) ;
DDx[i]= .5 * (.5 * (1 + epsy[i][j]) * cy[i][j-1] + dx) * vort[i][j-1]
+ (1 - dx - .5 * epsy[i][j] * cy[i][j]) * vort[i][j]
+ .5 * (-.5 * (1 - epsy[i][j]) * cy[i][j+1] + dx) * vort[i][j+1];
vortx[i]=vort[i][j];
}
DDx[1] = DDx[1] - AAx[1]* vort[0][j];
DDx[Nx-2] = DDx[Nx-2] - CCx[Nx-2] * vort[Nx-1][j];
tridiag(AAx, BBx, CCx, DDx, vortx, Nx-1); //ne calcul pas le point en 0 et en Nx-1
for (i=1; i<Nx-1; i++)
{
vort[i][j]=vortx[i];
}
}
}
あなたは個々のループ上のパフォーマンスへの影響を分離し、ベクトル化に悪影響を及ぼすかどうかを確認しましたか? theadsと親和性の数を最適化する? – tim18