Example 3 - valid Fortran SMP source file
!*****************************************************************
!* This example uses a PARALLEL construct and a DO construct *
!* to calculate the value of pi. *
!*****************************************************************
program compute_pi
integer n, i
real*8 w, x, pi, f, a
f(a) = 4.d0 /(1.d0 + a*a) !! function to integrate
pi = 0.0d0
!$OMP PARALLEL private(x, w, n), shared(pi)
n = 10000 !! number of intervals
w = 1.0d0/n !! calculate the interval size
!$OMP DO reduction(+: pi)
do i = 1, n
x = w * (i - 0.5d0)
pi = pi + f(x)
enddo
!$OMP END DO
!$OMP END PARALLEL
print *, "Computed pi = ", pi
end