OpenMp代码停止在Code :: Blocks中工作

时间:2015-07-01 18:07:22

标签: c++ parallel-processing openmp codeblocks reduction

我必须使用OpenMp在code :: blocks中对大块代码进行并行化。但由于某种原因,它在我运行它的那一刻就停止工作。但是代码正确编译。我在Microsoft Visual Studio 12调试器中运行它,它给出了堆栈溢出异常。请帮忙。这是代码..

#pragma omp parallel
{
int dxij_priv[] = {0,0,0,0};
int vt_priv[] = {0,0,0,0};
double sp_priv[Npartstot-Nboun][100][4],torquep_priv[Npartstot-Nboun][4],fmp_priv[Npartstot-Nboun][4];
for(i=Nboun+1;i<=Npartstot;++i){
    for(int n=1;n<=Nneb[i];++n){
        for(int p=1;p<=3;++p){
            sp_priv[i][n][p]=0;}}}
    for(i=Nboun+1;i<=Npartstot;++i){
        for(int p=1;p<=3;++p){
            torquep_priv[i][p]=0;
            fmp_priv[i][p]=0;
    }}
#pragma omp for nowait reduction(+:dal) reduction(+:st) reduction(+:vtang) reduction(+:sdotr)
for (i=Nboun+1;i<=Npartstot;++i){

    for (int n=1;n<=Nneb[i];++n){

        if(dxij_priv[1]>L-rng*(R[i]+R[j]))
          dxij_priv[1]=dxij_priv[1]-L;   //Same for other indices...

            else if (dxij_priv[1]<-L+rng*(R[i]+R[j])) //Same for other indices...
                  dxij_priv[1]=dxij_priv[1]+L;                

        for (int p=1;p<=3;++p){
          dal=dal+mij[p]*(vp[i][p]-vp[j][p]);
        }
        vt_priv[1]=vt_priv[1]-dxij_priv[i]; //Same for other indices
                sdotr=0;
        for (int p=1;p<=3;++p)
                    sp_priv[i][n][p] += vt_priv[p]*dt;
        for (int p=1;p<=3;++p)
                    sdotr += sp_priv[i][n][p]*dxij_priv[p];
        for (int p=1;p<=3;++p)
                    sp_priv[i][n][p] -= sdotr*dxij_priv[p]/d/d;
        for (int p=1;p<=3;++p)
                    st += sp_priv[i][n][p]*sp_priv[i][n][p];
        st=sqrt(st);
        for (int p=1;p<=3;++p)
                    vtang += vt_priv[p]*vt_priv[p];
                    vtang=sqrt(vtang);
        for (int p=1;p<3;++p) sp[i][n][p] *=st/st_prev;
        for (int p=1;p<=3;++p) tij[p]=vt_priv[p]/vtang;
        for (int p=1;p<=3;p++){
                  fmp_priv[i][p]=fmp_priv[i][p]+mij[p]*NForce+tij[p]*TForce;
                  torquep_priv[i][1]=torquep_priv[i][1]-R[i]/d*TForce*(dxij_priv[2]*tij[3]-dxij_priv[3]*tij[2]);  //Same for other indices...
                }
        } //end of n loop
        dxij[1] += dxij_priv[1];dxij[2] += dxij_priv[2];dxij[3] += dxij_priv[3];vt[1] += vt_priv[1];vt[2] += vt_priv[2];vt[3] += vt_priv[3];
    for(int z=Nboun+1;z<=Npartstot;++z)
        for(int n=1;n<=Nneb[i];++n)
            for(int p=1;p<=3;++p)
                sp[z][n][p] += sp_priv[z][n][p];
    for(int z=Nboun+1;z<=Npartstot;++z)
        for(int p=1;p<=3;++p){
            torquep[z][p] += torquep_priv[z][p];
            fmp[z][p] += fmp_priv[z][p];
    } //end of p
   }//end of i
  } //end of #pragma

我必须编辑代码的某些部分(实际代码比这大得多)并且我只显示那些涉及减少的行。当我在Code :: Blocks上运行程序时,出现错误提示:Parallized.exe已停止工作。

编译命令是:g ++ -fopenmp Parallized.cpp -lm。

我有一台两核四CPU电脑。

在我看来,我认为我正在搞乱某些地方减少数组变量。

0 个答案:

没有答案