title: openmp gives different result from sequential
body: <p>I am a beginner with openmp. I am trying to parallize a simple loop. But its clearly wrong.
  Can anyone kindly help?</p>
  
  <pre><code>use omp_lib
  implicit none
  integer ::n=20,it,j
  real(8) :: a=0,b=5,s,func,del,sum1,tnm,x
  it=2**(n-2)
  tnm=it
  del=(b-a)/tnm
  x=a+.5*del
  sum1=0.0
  
  !$omp parallel do reduction(+:sum1)
  do j=1,it
    sum1=sum1+func(x)
  !  write(*,*)func(x)
    x=x+del
  end do
  !$omp end parallel do
  s=.5*(s+(b-a)*sum1/tnm)
  write(*,*)s,sum1,it,del
  end
  
  function func(x)
    real(8)::x
    func=x
  end function
  </code></pre>
  
  <p><strong>EDIT</strong>
  Results:</p>
  
  <p><em>Parallel run::</em></p>
  
  <pre><code>$ ifort -openmp trapzd.f90 
  $ ./a.out 
    0.976562500000000        102400.000000000           262144
    1.907348632812500E-005
  </code></pre>
  
  <p><em>Sequential Run</em></p>
  
  <pre><code>$ ifort  trapzd.f90 
  $ ./a.out 
     6.25000000000000        655360.000000000           262144
    1.907348632812500E-005
  </code></pre>
  
  <p><code>s,sum1</code> is different in this two run</p>