Segmentation fault in C code using OpenMP and O0 in three nested parallel loops? -


i'm trying parallelize function following code

        double*** calchr(int snr, int snf ,int snz, double*** shr,double*** shr_temp, double*** sef, double*** sez,double*** ser,double*** shf, double*** a1r_h,double*** a2r_h,double dr,double df,double dz,double dt, int singularity,int pmlthick)     {         int i,j,k,l;         double temp,per_temp,sum1,sum2;         int fi_pi_2,fi_3pi_2;          for(i=0; i<=(snr-1); i++)         {             for(k=0; k<=(snz-1); k++)                 {                     k+=pmlthick;                     shr_temp[i][snf][k]=shr[i][snf][k];                     #ifdef parfor                     #pragma omp parallel schedule(static) private(i, j, k, temp, fi_3pi_2, fi_pi_2, per_temp, sum1, sum2) shared(shr_temp, shr, a2r_h, sef, sez, a1r_h)  num_threads(threads) ordered                     #endif                                         for(j=0; j<=(snf-1); j++)                         {                         temp=shr[i][j][k];                         shr_temp[i][j][k]=temp;                         if( i!=0)                             shr[i][j][k]=(a2r_h[i][j][k]/dz)*(sef[i][j][k+1]-sef[i][j][k])-( (a2r_h[i][j][k]/(double(i)*dr*df))*(sez[i][j+1][k]-sez[i][j][k]) )+ a1r_h[i][j][k]*temp;                         else                         {                               {                                fi_pi_2=j+snf/4;                             fi_3pi_2=j+(3*snf/4);                             if(fi_pi_2>=snf)                             fi_pi_2=fi_pi_2-snf;                             if(fi_3pi_2>=snf)                             fi_3pi_2=fi_3pi_2-snf;                             shr[0][j][k] = temp + (0.5*dt/mi_0)*( ((sez[1][fi_3pi_2][k]-sez[1][fi_pi_2][k])/dr) + ((-1.0*ser[0][fi_3pi_2][k+1] + ser[0][fi_pi_2][k+1] - ser[0][fi_pi_2][k] + ser[0][fi_3pi_2][k])/dz));                                                      }                         }                         shr[i][snf][k]=shr[i][0][k];                         k-=pmlthick;                         }                 }         }         return(shr,sef,sez);         } 

num_threads(threads) taking argument makefile appropiate flag -dthreads=4 (for example)

when compile code -o2 flags, segmentation fault not appear. when compile -o0 flag (no optimization) segmentation fault appears. serial version of code runs without problems both in -o2 , -o0 levels of optimization. operations additions , multiplications , matrices dynamically allocated outside of these functions. may cause problem? i've read around that, in parallel nested loops have declare private variables indexes of loops. made segmentation fault insists. in inner loop placed printf message , seems runs index number. wondering causes problem. ideas appreciated


Comments