title: Summation error in openmp fortran
body: <p>I am trying to sum up of a variable with openmp with code given below.</p>
  
  <pre><code>    normr=0.0
   !$omp parallel default(private) shared(nelem,normr,cell_data,alphar,betar,k)
     !$omp do REDUCTION(+:normr)
       do ii=1,nelem
          nnodese=cell_data(ii)%num_vertex
          pe=cell_data(ii)%porder
          ndofe=cell_data(ii)%ndof             
          num_neighboure=cell_data(ii)%num_neighbour
  
          be=&gt;cell_data(ii)%Force
          Ke=&gt;cell_data(ii)%K
          Me=&gt;cell_data(ii)%M
          pressuree=&gt;cell_data(ii)%p
          Rese=&gt;cell_data(ii)%Res
          neighbour_indexe=&gt;cell_data(ii)%neighbour_index(:)
  
          Rese(:)=be(:)
          Rese(:)=Rese(:)-cmplx(-1.0,1.0*alphar/k)*matmul(Me(:,:),pressuree(:))
          Rese(:)=Rese(:)-cmplx(1.0,1.0*k*betar)*matmul(Ke(:,:),pressuree(:))
  
          do jj=1,num_neighboure  
             nbeindex=neighbour_indexe(jj)
             Knbe=&gt;cell_data(ii)%neighbour(jj)%Knb
             pressurenb=&gt;cell_data(nbeindex)%p
             ndofnb=cell_data(nbeindex)%ndof
  
  
  
             Rese(:)=Rese(:)-cmplx(1.0,1.0*k*betar)*matmul(Knbe(:,:),pressurenb(:))
  
  
             nullify(pressurenb)
             nullify(Knbe)
          end do   
  
  
          normr=normr+dot_product(Rese(:),Rese(:))
  
          nullify(pressuree)
          nullify(Ke)
          nullify(Me)
          nullify(Rese)
          nullify(neighbour_indexe)
          nullify(be)
  
       end do
    !$omp end do
  !$omp end parallel 
  </code></pre>
  
  <p>The result for summed variable, normr, is different for parallel and sequantial code. In one of the posts I have seen that inner loop variable should be defined inside the parallel construct(Why I don't know). I also changed the pointers to locall allocated variables but result did not changed. normr is a saved real variable.</p>
  
  <p>Any suggestions and helps will be appreciated.</p>
  
  <p>Best Regards,</p>
  
  <p>Gokmen  </p>