title: OpenMP parallel numerical integration (summation) performance
body: <p>I recently started studying parallel coding, I'm still at the beginning so I wanted to try some very simple coding. Since it is in my interest to perform parallel numerical integration I started with a simple summation Fortran code:</p>
  
  <pre><code>program par_hello_world
  
  use omp_lib
  
  implicit none
  
  integer, parameter:: bign = 1000000000
  integer:: i
  
  double precision:: start, finish, start1, finish1, a
  
  a = 0
  
  call cpu_time(start)
  
  !$OMP PARALLEL num_threads(8)
  
    !$OMP DO REDUCTION(+:a)
  
      do i = 1,bign
  
  
        a = a + sqrt(1.0**5)
  
      end do
  
    !$OMP END DO
  
  !$OMP END PARALLEL
  
  call cpu_time(finish)
  
  print*, 'parallel result:'
  
  print*, a
  
  print*, (finish-start)
  
  
  a=0
  
  call cpu_time(start1)
  
  do i = 1,bign
  
    a = a + sqrt(1.0**5)
  
  end do
  
  call cpu_time(finish1)
  
  print*, 'sequential result:'
  
  print*, a
  
  print*, (finish1-start1)
  
  end program
  </code></pre>
  
  <p>The code basically simulates a summation, I used the weird expression <code>sqrt(1.0**5)</code> to have a measurable computational time, if I used just <code>1</code> the computational time was so small that i could not compare the sequential code with the parallel.
  I tried to avoid the race condition by using the <code>REDUCTION</code> clause.</p>
  
  <p>However I'm getting very strange <code>time</code> results:</p>
  
  <ol>
  <li>If I raise the number of threads from 2 to 16 I don't get a reduction of computational time but   somehow I even get an increase.</li>
  <li>Incredibly it seems that also the sequential code is influenced by the choice of the threads number (I really don't understand why!) in particular it is raised if I raise the number of threads.</li>
  <li>I get the correct result for the variable <code>a</code></li>
  </ol>
  
  <p>I think I'm doing something very wrong somewhere, but I'm clueless about it...</p>