program main c*********************************************************************72 c cc MAIN is the main program for QUAD. c c Discussion: c c QUAD is a FORTRAN77 program to estimate the integral of c f = 50.0 / ( pi * ( 2500.0 * x(i) * x(i) + 1.0 ) ) c from 0 to 10. c c Licensing: c c This code is distributed under the GNU LGPL license. c c Modified: c c 03 September 2013 c c Author: c c John Burkardt c include 'omp_lib.h' double precision a double precision b double precision error double precision exact integer i integer n double precision pi double precision total double precision wtime double precision x(1000000) a = 0.0 b = 10.0 exact = 0.49936338107645674464D+00 n = 1000000 pi = 3.141592653589793D+00 write ( *, * ) ' ' write ( *, * ) 'QUAD:' write ( *, * ) ' FORTRAN77 version' write ( *, * ) ' ' write ( *, * ) ' Estimate the integral of f(x) from A to B.' write ( *, * ) ' f(x) = 50 / (pi * ( 2500 * x * x + 1 ) ).' write ( *, * ) ' A = ', a write ( *, * ) ' B = ', b write ( *, * ) ' Exact integral is 0.49936338107645674464...' c c Load the array X with evenly spaced values between A and B. c do i = 1, n x(i) = ( dble ( n - i ) * a & + dble ( i - 1 ) * b ) & / dble ( n - 1 ) end do c c Evaluate F at each node, sum and average. c wtime = omp_get_wtime ( ) total = 0.0D+00 c$omp parallel shared ( n, pi, x ) private ( i ) c$omp do reduction ( + : total ) do i = 1, n total = total + 50.0D+00 & / ( pi * ( 2500.0D+00 * x(i) * x(i) + 1.0D+00 ) ) end do c$omp end do c$omp end parallel total = ( b - a ) * total / dble ( n ) wtime = omp_get_wtime ( ) - wtime c c Print quadrature estimate, error, time c error = abs ( total - exact ) write ( *, * ) ' ' write ( *, * ) ' Estimate = ', total write ( *, * ) ' Error = ', error write ( *, * ) ' Wallclock time = ', wtime stop end