对不起,我刚开始学习OpenMP,所以我有点困惑。 我正在分析我的分子动力学模拟和代码的一部分,我试图找到水分子(或离子)和蛋白质之间的最近距离。这是非常耗时的部分,因为我有大约50万个原子和大约25000个帧。通过单个CPU需要1周(对于一组计算,不仅是距离)。OpenMP for loop不会给出正确的结果
我改变了这部分代码通过的OpenMP并行,这是非常快,但有一个小错误;与单个CPU代码相比,90%的结果(距离)是正确的,10%是错误的。 这是我的代码的一部分,它计算的最近距离:
...
for (i=0; i< number of frames(25000))
...
// XP,YP,ZP protein coordinates; malloc allocation in the code
// XI,YI,ZI Sodium molecule coordinates; malloc allocation
// LX,LY,LZ the dimension of simulation box, malloc allocation
// dimI defined as a temporary closest distance, filled with very large constant,
// malloc allocation
// NSOD number of Sodium molecules
// rhos keeping the closest distance for each Sodium for each frame.
…
...int l=0,kk=0;
#pragma omp parallel for shared(XI,YI,ZI,XP,YP,ZP,LX,LY,LZ,qq,dimI,distI,rhos,xmin,ymin,zmin,i) private(kk,l)
for (l=0; l < NSOD; l++){
// this part relocates every thing inside a box with dimension LX*LY*LZ. xmin, ymin and zmin are the boundaries of the box.
if (XI[l]!=0.0 || YI[l]!=0.0 || ZI[l]!=0.0){
if (XI[l] < xmin) XI[l] += ceil((xmin - XI[l])/LX[i-1]) * LX[i-1];
if (XI[l] > xmax) XI[l] -= ceil((XI[l] - xmax)/LX[i-1]) * LX[i-1];
if (YI[l] < ymin) YI[l] += ceil((ymin - YI[l])/LY[i-1]) * LY[i-1];
if (YI[l] > ymax) YI[l] -= ceil((YI[l] - ymax)/LY[i-1]) * LY[i-1];
if (ZI[l] < zmin) ZI[l] += ceil((zmin - ZI[l])/LZ[i-1]) * LZ[i-1];
if (ZI[l] > zmax) ZI[l] -= ceil((ZI[l] - zmax)/LZ[i-1]) * LZ[i-1];
}
for (kk=0; kk<NP; kk++){
if ((XP[kk]!=0. || YP[kk]!=0. || ZP[kk]!=0.) ){
distI[l] = sqrt((XI[l]-XP[kk])*(XI[l]-XP[kk]) + (YI[l]-YP[kk])*(YI[l]-YP[kk]) + (ZI[l]-ZP[kk])*(ZI[l]-ZP[kk]));
if (distI[l] < dimI[l]) {
dimI[l] = distI[l];
}
}
}
distI[l] = dimI[l];
rhos[qq][l] = dimI[l];
} 的#pragma OMP屏障 ...
你能告诉我什么是错与并行后,我的代码?为什么只在某些情况下给出了错误的答案,而不是所有的情况?我非常感谢您的意见和建议。我在linux上使用gcc。 非常感谢你,
干杯, 阿拉什
嗨安德斯,我会申请后你的建议,谢谢,阿拉什 – Arash