program compute_pi
  implicit none 
  include "omp_lib.h" 

  real*8 t0,t1,wt0,wt1   

  integer(kind=8) i
  integer(kind=8), parameter:: n=80000000000
  real*8 w,x,sum,pi,f,a

  ! function to integrate
  f(a)=4.0_8/(1.0_8+a*a)

  wt0=omp_get_wtime() 
  call cpu_time(t0)

  ! calculate pi = integral [0..1] 4/(1+x**2) dx
  w=1.d0/n
  sum=0.d0
  !$OMP PARALLEL DO PRIVATE(i,x),REDUCTION(+:sum),SCHEDULE(STATIC)
    do i=1,n
       x=w*(i-0.50)
       sum=sum+f(x)
    enddo
  !$OMP END PARALLEL DO
  pi=w*sum
  
  call cpu_time(t1)
  wt1=omp_get_wtime() 

  write (*,'(/,a,1pg24.16)') 'computed pi = ', pi
  write (*,'(/,a,1pg12.4)')  'cpu_time:     ', t1-t0
  write (*,'(/,a,1pg12.4)')  'omp_get_wtime:', wt1-wt0
  stop
end program compute_pi  
